Posted by Alpha
Wed, 06 Feb 2008 07:00:30 GMT
This is something that should be widely known by now, but is strangely not.
$ defaults write com.apple.desktopservices DSDontWriteNetworkStores true
This will come in useful later on when I post on how to use NFS and SMB to share files between Ubuntu and OS X.
Posted in default, tips, osx | 1 comment | no trackbacks
Posted by Alpha
Mon, 04 Feb 2008 06:36:00 GMT
Hitting Return activates the button with the solid highlight while hitting Space activates the one with the glow highlight. Very handy when there are multiple options in a form that are used often.
Posted in default | no comments | no trackbacks
Posted by Alpha
Sun, 27 Jan 2008 21:02:59 GMT
With much thanks to this blog post, which reveals how to fix /etc/ushare.conf and /etc/init.d/ushare.
Install the dependencies:
$ sudo apt-get install libupnp-dev pkg-config
$ sudo echo "deb http://www.geexbox.org/debian/ unstable main" >> /etc/apt/sources.list
$ sudo apt-get install libdlna-dev ushare
(uShare’s being installed here just to grab the conf files.)
Pick up the latest version of uShare (assuming Mercurial is installed):
$ hg clone http://hg.geexbox.org/ushare
In the uShare directory:
$ ./configure --prefix=/usr/local
$ make
$ make install
Now the configuration files need to be edited. Make the appropriate changes to /etc/ushare.conf, making sure to modify ENABLE_XBOX to USHARE_ENABLE_XBOX. The rest should be self-explanatory.
In /etc/init.d/ushare, add USHARE_OPTIONS="-f $CONFIGFILE" so that the correct command line is sent to uShare.
And now you should be able to stream videos from your Ubuntu fileserver to your Xbox 360.
Posted in default, server, ubuntu | 1 comment | no trackbacks
Posted by Alpha
Fri, 25 Jan 2008 05:51:58 GMT
I forgot where I saw this originally, but it’s a handy way to generate random passwords:
$ openssl rand -base64 6
Posted in default, tips, server | no comments | no trackbacks
Posted by Alpha
Thu, 03 Jan 2008 07:36:00 GMT
The previous method was a bit messy, so I’ve cleaned it up a bit.


Download twitter_stats.tar.gz
Read more...
Posted in default, ruby, programming | 1 comment | no trackbacks
Posted by Alpha
Wed, 02 Jan 2008 17:40:00 GMT
I saw Damon Cortesi’s Twitter Stats script last night, and decided to make a Ruby version. This was before he released his code, so it’s reverse-engineered rather than ported. I’ll take a look later tonight to see how much the logic differs.
Edit: This code is rather inelegant, and I’ve replaced the clunky CSV files with an Sqlite3 database. You can find the new and improved scripts here. The following should still work, and I’m leaving it here for posterity’s sake.
Read more...
Posted in default, ruby, programming | 3 comments | no trackbacks
Posted by Alpha
Sun, 30 Dec 2007 20:38:00 GMT
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:

Posted in default, ruby | no comments | no trackbacks
Posted by Alpha
Sun, 30 Dec 2007 18:05:58 GMT
It took me no small amount of time to figure out how to horizontally and vertically center image links, so here it is for posterity’s sake. Note that this doesn’t work in IE and is rather specific to my purposes in creating thumbnail links for a bunch of pictures.
HTML:
<div class="thumbnail">
<a href=/some/link>
<img src=/some/image>
</a>
</div>
CSS:
.thumbnail {
height:150px;
width:150px;
line-height:150px;
text-align:center;
}
.thumbnail img {
vertical-align:middle;
}
Posted in default, tips | no comments | no trackbacks
Posted by Alpha
Tue, 04 Dec 2007 03:55:00 GMT
After seeing Christian von Kleist’s solution, I couldn’t help but play with it a bit to come up with this:
puts ARGV[0].split(/\s*/).inject([]) {|n,i|
n << ((%w[+ - * /].include?(i)) ? (b,a=n.pop,n.pop; "(#{a} #{i} #{b})") : i)
}[0]
Posted in ruby, programming | no comments | no trackbacks
Posted by Alpha
Mon, 03 Dec 2007 21:49:00 GMT
My extremely lazy whack at the latest Ruby Quiz. Turns a postfix expression into an infix expression via regular expressions.
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
Posted in ruby, programming | no comments | no trackbacks