From 2fc835c0e36bbec3ce4888912e5e27ffecbe67a3 Mon Sep 17 00:00:00 2001 From: jarnaldich Date: Tue, 26 Apr 2011 14:38:56 +0200 Subject: [PATCH] modificat URL --- blog/Factor_file_system_monitor.lua | 226 ++++++++++++++++++------------------ sputnik/config.lua | 4 +- 2 files changed, 115 insertions(+), 115 deletions(-) diff --git a/blog/Factor_file_system_monitor.lua b/blog/Factor_file_system_monitor.lua index d12f365..59840d1 100644 --- a/blog/Factor_file_system_monitor.lua +++ b/blog/Factor_file_system_monitor.lua @@ -1,113 +1,113 @@ - -fields = "" -title = "blog/Factor file system monitor" -category = "" -actions = "" -config = "" -markup_module = "" -templates = "" -translations = "" -prototype = "@BlogEntry" -permissions = "" -html_main = "" -html_head = "" -html_menu = "" -html_logo = "" -html_search = "" -html_page = "" -html_content = "" -html_body = "" -html_footer = "" -html_header = "" -html_sidebar = "" -html_meta_keywords= "factor, factorcode, file, monitor," -html_meta_description= "Filesystem monitor implementation in the factor programming language" -redirect_destination= "" -xssfilter_allowed_tags= "" -http_cache_control= "" -http_expires = "" -content = [[ - -Sometimes I find myself editing config scripts that won't be reloaded until the program using them is restarted, and I find the editing/stopping/starting loop really annoying, so I thought it would be nice to hack a little tool that started an application and then monitors for changes in a directory tree root, stopping and restarting the app each time a change is detected... now, Factor is the only language, AFAIK, with a portable [file system monitoring library](http://docs.factorcode.org/content/vocab-io.monitors.html). It's important to note that it doesn't fall back to active polling, but use the underlying notifications API for each platform. - -In case you didn't know, Factor is a concatenative language, a sort of modern Forth on steroids with a lispy touch, created by [Slava Pestov](http://factorcode.org/slava/). Slava himself blogged about a [simple aplication](http://factor-language.blogspot.com/2008/02/simple-application-using-iomonitor-tail.html) of this library, and probably this blog post won't add much to the original article if you already know a bit of Factor, but in any case it will be yet another example of useful factor code. - -If you've never played with Factor, you can download the right version for your platform [here](http://www.factorcode.org). Then visit the [getting started](http://concatenative.org/wiki/view/Factor/Learning) page. It pays off spending some time browsing the docs, because the factor team has made an effort to make the introduction as gentle as possible... - - -

-! Vim: ts=4 :expandtab

-! Copyright (C) Joan Arnaldich Bernal

-! See http://factorcode.org/license.txt for BSD license.

-USING: accessors combinators fry io io.launcher io.monitors

- kernel namespaces prettyprint sequences ;

-IN: spinner

-

-: reset-image ( progname proc -- progname newproc )

-   kill-process dup run-detached ;

-

-: change-description ( change -- str )

-    changed>> first {

-        { +modify-file+ [ "FILE MODIFIED" ] }

-        { +add-file+ [ "FILE ADDED" ] }

-        { +remove-file+ [ "FILE REMOVED" ] }

-        { +rename-file+ [ "FILE RENAMED" ] }

-        { +rename-file-new+ [ "FILE RENAMED" ] }

-        { +rename-file-old+ [ "FILE RENAMED" ] }

-        [ unparse ] 

-    } case ;

-

-: describe-change ( change -- )

-    [ change-description ] [ path>> ] bi

-    " @ " swap append append print nl ;

-

-: print-path ( desc -- )

-    next-change describe-change flush ; ! 

-

-: watch-loop ( monitor progname proc  -- )

-   [ dup print-path ] 2dip

-   reset-image

-   watch-loop ;

-

-: watch-directory ( path progname proc -- )

-   [ watch-loop ] curry curry

-   '[ t _  with-monitor ] curry with-monitors ;

-

-: start-spinning ( path progname -- )

-   dup run-detached watch-directory ;

-

-: main ( -- )

-   "path" get-global

-   "exec" get-global

-   start-spinning ;

-

-MAIN: main

-
- -There's really not much to comment on this code. We start by reading -the two params from globals (MAIN is the only place where I allow -myself to use globals), and then push them onto the stack to call the -function `start-spinning`, that starts the process for the first time -and then calls `watch-directory`, which first builds a specialized -watch loop through currying... I guess this is the concatenative -equivalent of a HOF (ain't concatenative nice?) and then submits this -newly created function to `with-monitors`. The loop, as seen in this -function, just blocks for an event (`next-change` is a blocking call), -prints a readable message, and keeps looping. - -This will allow run it at the command-line like this: - -

-factor -exec=program-to-reset -path=path-to-monitor

-
- -VoilĂ ! That was it! - -]] -edit_ui = "" -admin_edit_ui = "" -breadcrumb = "" -save_hook = "" -author = "admin" -creation_time = "1296313923" -short_desc = "" \ No newline at end of file + +fields = "" +title = "blog/Factor file system monitor" +category = "" +actions = "" +config = "" +markup_module = "" +templates = "" +translations = "" +prototype = "@BlogEntry" +permissions = "" +html_main = "" +html_head = "" +html_menu = "" +html_logo = "" +html_search = "" +html_page = "" +html_content = "" +html_body = "" +html_footer = "" +html_header = "" +html_sidebar = "" +html_meta_keywords= "factor, factorcode, file, monitor," +html_meta_description= "Filesystem monitor implementation in the factor programming language" +redirect_destination= "" +xssfilter_allowed_tags= "" +http_cache_control= "" +http_expires = "" +content = [[ + +Sometimes I find myself editing config scripts that won't be reloaded until the program using them is restarted, and I find the editing/stopping/starting loop really annoying, so I thought it would be nice to hack a little tool that started an application and then monitors for changes in a directory tree root, stopping and restarting the app each time a change is detected... now, Factor is the only language, AFAIK, with a portable [file system monitoring library](http://docs.factorcode.org/content/vocab-io.monitors.html). It's important to note that it doesn't fall back to active polling, but use the underlying notifications API for each platform. + +In case you didn't know, Factor is a concatenative language, a sort of modern Forth on steroids with a lispy touch, created by [Slava Pestov](http://factorcode.org/slava/). Slava himself blogged about a [simple aplication](http://factor-language.blogspot.com/2008/02/simple-application-using-iomonitor-tail.html) of this library, and probably this blog post won't add much to the original article if you already know a bit of Factor, but in any case it will be yet another example of useful factor code. + +If you've never played with Factor, you can download the right version for your platform [here](http://www.factorcode.org). Then visit the [getting started](http://concatenative.org/wiki/view/Factor/Learning) page. It pays off spending some time browsing the docs, because the factor team has made an effort to make the introduction as gentle as possible... + + +
+! Vim: ts=4 :expandtab
+! Copyright (C) Joan Arnaldich Bernal
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors combinators fry io io.launcher io.monitors
+ kernel namespaces prettyprint sequences ;
+IN: spinner
+
+: reset-image ( progname proc -- progname newproc )
+   kill-process dup run-detached ;
+
+: change-description ( change -- str )
+    changed>> first {
+        { +modify-file+ [ "FILE MODIFIED" ] }
+        { +add-file+ [ "FILE ADDED" ] }
+        { +remove-file+ [ "FILE REMOVED" ] }
+        { +rename-file+ [ "FILE RENAMED" ] }
+        { +rename-file-new+ [ "FILE RENAMED" ] }
+        { +rename-file-old+ [ "FILE RENAMED" ] }
+        [ unparse ] 
+    } case ;
+
+: describe-change ( change -- )
+    [ change-description ] [ path>> ] bi
+    " @ " swap append append print nl ;
+
+: print-path ( desc -- )
+    next-change describe-change flush ; ! 
+
+: watch-loop ( monitor progname proc  -- )
+   [ dup print-path ] 2dip
+   reset-image
+   watch-loop ;
+
+: watch-directory ( path progname proc -- )
+   [ watch-loop ] curry curry
+   '[ t _  with-monitor ] curry with-monitors ;
+
+: start-spinning ( path progname -- )
+   dup run-detached watch-directory ;
+
+: main ( -- )
+   "path" get-global
+   "exec" get-global
+   start-spinning ;
+
+MAIN: main
+
+ +There's really not much to comment on this code. We start by reading +the two params from globals (MAIN is the only place where I allow +myself to use globals), and then push them onto the stack to call the +function `start-spinning`, that starts the process for the first time +and then calls `watch-directory`, which first builds a specialized +watch loop through currying... I guess this is the concatenative +equivalent of a HOF (ain't concatenative nice?) and then submits this +newly created function to `with-monitors`. The loop, as seen in this +function, just blocks for an event (`next-change` is a blocking call), +prints a readable message, and keeps looping. + +This will allow run it at the command-line like this: + +
+factor -exec=program-to-reset -path=path-to-monitor
+
+ +VoilĂ ! That was it! + +]] +edit_ui = "" +admin_edit_ui = "" +breadcrumb = "" +save_hook = "" +author = "admin" +creation_time = "1296313923" +short_desc = "" diff --git a/sputnik/config.lua b/sputnik/config.lua index 7e5090a..2ac05d5 100644 --- a/sputnik/config.lua +++ b/sputnik/config.lua @@ -27,7 +27,7 @@ xssfilter_allowed_tags= "" http_cache_control= "" http_expires = "" content = [[SITE_TITLE = "Rubber Bytes - Joan Arnaldich Home Page" -- change the title of the site -DOMAIN = "localhost:8080" -- set for RSS feeds to work properly +DOMAIN = "rubberbytes.nfshost.com" -- set for RSS feeds to work properly NICE_URL = BASE_URL.."?p=" -- set if you want "nicer" URLs MAIN_COLOR = 200 -- pick a number from 0 to 360 --BODY_BG_COLOR = "white" @@ -48,4 +48,4 @@ INTERFACE_LANGUAGE = "en" edit_ui = "" admin_edit_ui = "" breadcrumb = "" -save_hook = "" \ No newline at end of file +save_hook = "" -- 2.11.4.GIT