Live data from Hacker News

Poor man's IFTTT in 3 lines of code

blog.lagentz.com

21–30 of 36 posts

Re: Poor man's IFTTT in 3 lines of code

#21

I use this to compile my LESS scripts already. I was always getting really frustrated with the options with LESS... either compile in the browser, or compile manually. Both were actually a bit of a pain, (caching being the biggest annoyance for browser compilation). So I used inotifywait... It would check for any modifications to my "CSS" folders recursively, and it would then run my custom less compilation script [1…

I solved this problem using http://leafo.net/lessphp/. Obviously that only works if you are programming in PHP, but I would imagine there are similar solutions available for other languages?

Re: Poor man's IFTTT in 3 lines of code

#22
post #3
post #2

Great use-case for lnotify, haven't thought about that. Feels much cleaner than having cron jobs for conversions like these.

With the listen gem you can write crossplatform scripts ( http://rubygems.org/gems/listen ).

For those of Perl persuasion, there are:

    * File::ChangeNotify (https://www.metacpan.org/module/File::ChangeNotify)
    * Filesys::Notify::Simple (https://www.metacpan.org/module/Filesys::Notify::Simple)

Re: Poor man's IFTTT in 3 lines of code

#26
post #19

The inotify script likely has a race condition; if the directory is modified while an update is running, it won't pick up the second modification, and will wait in a dirty state until it is modified again. If anyone wants a race-free solution, you should check out my NCD scripting language [1] which has an integrated command to receive directory change notifications (last example in Blockers section is a race-free so…

After a very brief look, NCD looks very cool. I'm curious about the first complete example. Is it possible to implement a delay of a few seconds before the IP address is reset when the link is lost?

Re: Poor man's IFTTT in 3 lines of code

#27
post #12
post #11

Earlier quoted context omitted.

I'm sorry if I missed this, but why would you use make instead of bash?

make figures out which files need updating make allows to write pattern rules (.c.o:, or %.o: %.c) you don't need to move files out of the 'inbox' to ignore them regenerating a file is a touch(1) away make is descriptive, not imperative (invaluable readability when you're coming back on it years later) should you ever need a second transformative step or a new dependency, it's trivial to insert, and make will figure…

"make is crazy fast"

Make calls the shell in order to run programs, correct?

(IOW, does make call execve directly, as the shell does?)

Re: Poor man's IFTTT in 3 lines of code

#28
post #19

The inotify script likely has a race condition; if the directory is modified while an update is running, it won't pick up the second modification, and will wait in a dirty state until it is modified again. If anyone wants a race-free solution, you should check out my NCD scripting language [1] which has an integrated command to receive directory change notifications (last example in Blockers section is a race-free so…

After a very brief look, NCD looks very cool. I'm curious about the first complete example. Is it possible to implement a delay of a few seconds before the IP address is reset when the link is lost?

I've never seen why that would be useful. Switches and Ethernet cards aren't that unreliable in my experience, and I've plugged cables into a different switch in less than a few seconds :) I think if you really needed that, the nicest way would be to add it as a feature to net.backend.waitlink(). See source [1] of this command, and source of sleep() [2] to see how to use a timer. It may also be possible to hack it up without C-coding using blocker(), spawn(), sleep() and maybe other control commands.

[1] http://code.google.com/p/badvpn/source/browse/trunk/ncd/modu... [2] http://code.google.com/p/badvpn/source/browse/trunk/ncd/modu...

Re: Poor man's IFTTT in 3 lines of code

#29
post #28

Earlier quoted context omitted.

After a very brief look, NCD looks very cool. I'm curious about the first complete example. Is it possible to implement a delay of a few seconds before the IP address is reset when the link is lost?

I've never seen why that would be useful. Switches and Ethernet cards aren't that unreliable in my experience, and I've plugged cables into a different switch in less than a few seconds :) I think if you really needed that, the nicest way would be to add it as a feature to net.backend.waitlink(). See source [1] of this command, and source of sleep() [2] to see how to use a timer. It may also be possible to hack it up…

I've had a situation where an Ethernet connection would occasionally drop link for a very small fraction of a second, which unnecessarily shut down the interface and reset all TCP connections. Maybe a few second delay is too long, but 500ms seems reasonable. Also, maybe I wouldn't want to keep the old address blindly, but trigger a DCHP request if the link is dropped and restored before the timeout.

Also, thanks for the pointers into the source code. It looks like I would want to make the change around line 67 of net_backend_waitlink.c. I highly doubt I'll actually get around to doing it though :).

Re: Poor man's IFTTT in 3 lines of code

#30
post #28

Earlier quoted context omitted.

I've never seen why that would be useful. Switches and Ethernet cards aren't that unreliable in my experience, and I've plugged cables into a different switch in less than a few seconds :) I think if you really needed that, the nicest way would be to add it as a feature to net.backend.waitlink(). See source [1] of this command, and source of sleep() [2] to see how to use a timer. It may also be possible to hack it up…

I've had a situation where an Ethernet connection would occasionally drop link for a very small fraction of a second, which unnecessarily shut down the interface and reset all TCP connections. Maybe a few second delay is too long, but 500ms seems reasonable. Also, maybe I wouldn't want to keep the old address blindly, but trigger a DCHP request if the link is dropped and restored before the timeout. Also, thanks for…

So you really need this, would that mean you may be able to use my language for something? If so, just say, and I can add this little feature, but I wouldn't like spending time for nothing :)
Post reply on HN