Stop OS X from spewing .DS_Store on network drives

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 , ,  | 1 comment | no trackbacks

Random OS X goodness

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  | no comments | no trackbacks

Using uShare for streaming video from Ubuntu to Xbox 360

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 , ,  | 1 comment | no trackbacks

How I generate passwords

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 , ,  | no comments | no trackbacks

Improved Twitter Stats in Ruby

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 , ,  | 1 comment | no trackbacks

Twitter stats using Ruby

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 , ,  | 3 comments | no trackbacks

Generating animated GIFs using RMagick

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:

Gloria making a funny face.

Posted in ,  | no comments | no trackbacks

Centering image links using CSS

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 ,  | no comments | no trackbacks

Postfix to Infix, Part 2

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:

#!/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]

Posted in ,  | no comments | no trackbacks

RubyQuiz #148: Postfix to Infix

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.

#!/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

Posted in ,  | no comments | no trackbacks

Older posts: 1 2