Live data from Hacker News

Poor man's IFTTT in 3 lines of code

blog.lagentz.com

1–10 of 36 posts

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

#5
post #4

I found this a very intrusive site - I really dislike these animated slide in fade in distractions.

Not only the slide-in nonsense, but also the wiggling "Try Me!" arrow on the right. "You may also like" panels are becoming the Clippy of blogs and news sites.

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

#7
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 ).

Hadn't come across listen, that's perfect for what I need. I've used notify on Linux but I wanted something a bit more portable for OS X.

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

#8
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] ...

     #!/bin/bash
     while inotifywait -e modify -r /var/www/site/public/static/css/base; do
       cd /var/www/site/public/static/css; node compile;
     done
(I also hooked this up to Fab [2], and used a "start"/"stop" script [3] to pause the watch, so that I could manually control when inotify wait would be watching.

[1] https://gist.github.com/3497304 (My Custom LESS compile Script)

[2] http://docs.fabfile.org/en/1.4.3/index.html ( Fabric Command Line Tool )

[3] https://gist.github.com/3497308 (Sample Fab Command )

If it would benefit anyone to know in greater details, I'd be happy to write a blog post about automating compilation using these tools.

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

#9
post #4

I found this a very intrusive site - I really dislike these animated slide in fade in distractions.

Agreed; this was one I hit the Readability bookmarklet for straight away.

(Having said that, I went back afterwards and filled out the feedback form pointing out the annoying bits. It was a good article, and I wanted to repay the favour; I recommend you do the same if you agree.)

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

#10
Regarding the watermark generation process, although the bash script works, I immediately reach for my old friend (GNU) make(1) for that kind of task. Here's the Makefile:

    all: watermark
    
    done:=$(wildcard *-BD.pdf)
    src:=$(filter-out $(done),$(wildcard *.pdf))
    marked:=$(patsubst %.pdf,%-BD.pdf,$(src))
    
    watermark: $(marked)
    
    %-BD.pdf: %.pdf
    	./watermark_script.sh $
The done+filter-out mumbo jumbo is there just because without it, -BD.pdf would be matched by .pdf, and therefore would generate -BD-BD.pdf... and so on (this is a loophole that the original bash script has, if parallel runs are timed correctly). Putting the output files in another directory is left ans an exercise for the reader.

The inotify script becomes:

    inotifywait -e create /home/user/pdfs && make -C /home/user/pdfs
There is another loophole here, in that the -BD.pdf are created in that directory, so the script gets run again. It doesn't matter for our makefile, which will do nothing on the second run, but there is the 'parallel runs if timed correctly' issue of the original bash script.

Generally, GNU make has a bunch of very interesting facilities, making it much, much more powerful than its ancestors (BTW, people interested may want to take a look at an implementation of non-recursive make[0], which — while being awesome — also shows up some useful make tricks).

Now, regarding the filesystem events and userland tools (which are awesome), I wish there was a unified front-end for this kind of things (inotify on Linux, fsevents on OSX...)

PS: I wish the comment form supported something like markdown, so that I could escape those wildcards, and more.

[0] http://stackoverflow.com/questions/559216/what-is-your-exper...

Post reply on HN