Voxeo VoiceXML Tools Suggestions
From the Rubyforge snippet library:
class Hash def to_struct(struct_name) Struct.new(struct_name,*keys).new(*values) end end
if $0 == __FILE__ h = {:name=>"Dan","age"=>33,"rank"=>"SrA","grade"=>"E4"}
s = h.to_struct("Foo")
puts "name: " + s.name puts "age: " + s.age.to_s puts "rank: " + s.rank puts "grade: " + s.grade end =begin Note: An empty string used as a key will cause 1.8 to choke =end
Using the SystemRescueCD, LVM partitions are visible but not active until you enter:
vgchange -ay
For details, see Ubuntu docs here.
default vmlinuz append initrd=initrd.gz ramdisk_size=12000 root=/dev/rd/0 rw
Note: syslinux.cfg as described in the docs does not work – removing the “init=/linuxrc” fixes the problem.
From PC-Week: check this out.
You’ve booted into Ubuntu and your expensive high-res display is running at a paltry 1024 by 768 resolution instead of the 1280 by 1024 or 1600 by 1200 you’re accustomed to. So you click System, Preferences, Screen Resolution, only to find that the higher resolutions you know your display can support are not offered in the drop-down list. What the heck?This is usually an indication that Ubuntu has failed to suss out the characteristics of your monitor. (Graphics card woes are also possible in this case, but in my experience monitor trouble is more common.) Luckily, a helpful Fix Video Resolution Howto in the Ubuntu wiki has solved this issue every time I’ve encountered it. The instructions there should be enough to get your display in gear.
Nasty little glitch in CentOS 4.4 kernel headers can be fixed with:
sed -i s/rw_lock/rwlock/ /usr/src/kernels/`uname -r`-`uname -m`/include/linux/spinlock.h
a = [1, 2, 3] Hash[*a.collect { |v| v, v*2].flatten]
or from something Ryan Carver was trying to do:
Array#to_h
I found myself writing something like this far too often:
def map_something(array) hash = {} array.each do |a| hash[a] = lookup_value a end hash end
It bugged me every time, but digging through the Pick Axe never yielded (ahem) a simpler solution. What I wanted to do is this:
def map_something(array) array.to_h do |a| lookup_value a end end
But of course you’d need Array#to_h. Here’s the cleverest implementation I could think of.
class Array def to_h(default=nil) Hash[ *inject([]) { |a, value| a.push value, default || yield(value) } ] end end
A pointless example:
a = [1, 2, 3] a.to_h do |v| [v * 2, v * 3] end > {1=>[2, 3], 2=>[4, 6], 3=>[6, 9]}
I love Array#inject!
Go to /var/cache/apt/archives and copy your debian packages to a folder of your choice, for example, /home/$username/repository
Cd into the directory and generate a Packages.gz file like this:
sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
Add the following line to your apt sources file (/etc/apt/sources.list)
deb file:/home/$username/repository/disk_1 /
Remember to replace $username with your username
Reload your package index like this:
sudo apt-get update
And you’re done.
Recent Comments