Sample code:
anim = Magick::ImageList.new(*Dir["/some/path/*.jpg"]) anim.each {|img| img.resize!(200,200) } anim.delay = 10 anim.unshift Magick::Image.read("/some/image.jpg")[0].resize(200,200) anim << Magick::Image.read("/some/other/image.jpg")[0].resize(200,200) anim.write("animated.gif")
Example image:
DEC 03
After seeing Christian von Kleist’s solution, I couldn’t help but play with it a bit to come up with this:
#!/usr/bin/env ruby puts ARGV[0].split(/\s*/).inject([]) {|n,i| n << ((%w[+ - * /].include?(i)) ? (b,a=n.pop,n.pop; "(#{a} #{i} #{b})") : i) }[0]
My extremely lazy whack at the latest Ruby Quiz. Turns a postfix expression into an infix expression via regular expressions.
#!/usr/bin/env ruby str = ARGV[0].split(/\s+/).join('_') while str.include?('_') str.sub!(/([^_]+)_([^_]+)_([+\-*\/])/, '(\1 \3 \2)') end puts str
A few test cases I used in developing the solution before turning it into an actual script:
require 'test/unit' def postfix_to_infix(str) str = str.split(/[^.\d+\-*\/]/).join(' ') while str !~ /^\(.*\)$/ str.sub!(/([^ ]+) ([^ ]+) ([+\-*\/])/, '(\1\3\2)') end str.gsub(/([+\-*\/])/, ' \1 ').sub(/^\((.*)\)$/, '\1') end class PostfixToInfixTest < Test::Unit::TestCase def test_postfix_to_infix assert_equal '2 + 3', postfix_to_infix('2 3 +') assert_equal '12 + 34', postfix_to_infix('12 34 +') assert_equal '1.2 + 3.4', postfix_to_infix('1.2 3.4 +') assert_equal '(1 - 2) - (3 + 4)', postfix_to_infix('1 2 - 3 4 + -') assert_equal '(56 * (34 + 213.7)) - 678', postfix_to_infix('56 34 213.7 + * 678 -') end end
Throughout this post, I’ll use foobar as a fake domain. You should replace this with the appropriate domain(s) for your own use.
First, install AWStats.
$ sudo apt-get install awstats
/etc/lighttpd.conf will need to be modified; this will be slightly different if you want to use a directory instead of a subdomain to check your stats.
/etc/lighttpd/lighttpd.conf
server.modules += ( "mod_cgi" ) $HTTP["host"] =~ "stats.foobar" { alias.url = ( "/icon/" => "/usr/share/awstats/icon/", "/css/" => "/usr/share/doc/awstats/examples/css/", "/cgi-bin/" => "/usr/lib/cgi-bin/" ) cgi.assign = ( ".pl" => "/usr/bin/perl", ".cgi" => "/usr/bin/perl" ) }
Make sure this works by visiting http://stats.foobar/cgi-bin/awstats.pl. You should get an error message from the AWStats CGI file.
In /etc/awstats, make a awstats.foobar.conf file, replacing foobar with whatever is appropriate for your purposes.
/etc/awstats/awstats.foobar.conf
LogFile="/var/log/lighttpd/access.log" LogType=W LogFormat=1 SiteDomain="foobar" HostAliases="localhost 127.0.0.1 REGEX[foobar$]" DNSLookup=1 DirData="/var/lib/awstats" DirCgi="/cgi-bin" DirIcons="/icon" SkipHosts="127.0.0.1 localhost REGEX[^192\.168\.]"
Run awstats.pl to initialize the statistics database.
$ sudo -u www-data /usr/lib/cgi-bin/awstats.pl -config=foobar -update
Your stats should now be visible at http://stats.foobar/cgi-bin/awstats.pl?config=foobar.
Now all that’s left is editing the crontab and logrotate configuration files to automatically populate the stats.
/etc/cron.d/awstats
0,10,20,30,40,50 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.foobar.conf -a -r /var/log/lighttpd/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=foobar -update >/dev/null
/etc/logrotate.d/lighttpd
prerotate /usr/lib/cgi-bin/awstats.pl -config=foobar -update endscript
