Skip to content

Instantly share code, notes, and snippets.

@rgo
rgo / block_constructor.rb
Created July 1, 2011 14:22
Using &block as constructor
# &block constructors
# From http://www.deploymentzone.com/2011/06/23/block-constructors
# If you need a behavior like this in your class:
Person.new do |p|
p.first_name = "John"
p.last_name = "Brown"
p.dob = Date.parse("5/9/1800")
end
@rgo
rgo / test.sh
Created July 6, 2011 14:51
Execute (remote) a ruby script
#!/usr/bin/env ruby
ruby -e "require 'open-uri'; system open('http:// or local file').read"
@rgo
rgo / gist:1173243
Created August 26, 2011 11:36 — forked from diecrf/gist:1170410
Delete unused images in a rails project
images = Dir.glob('public/images/*')
images.each do |image|
unless File.directory?(image)
puts "Checking #{image}..."
if IO.popen("ack-grep -1 -G '(app|public)' --ruby --html --css #{File.basename(image)}").eof?
IO.popen("svn delete #{image}")
puts " Deleted"
end
end
@rgo
rgo / block_unblock_package_updates.sh
Created September 21, 2011 10:54
Block/unblock package upgrades
# Block package version (don't upgrade it anymore)
echo "package-name hold" | sudo dpkg --set-selections
# Unblock package version (upgrade it again)
echo "package-name install" | sudo dpkg --set-selections
@rgo
rgo / flush_all_memcached.sh
Created October 25, 2011 10:29
Flush all memcached data
#!/bin/sh
echo $'flush_all\r\nquit\r\n' | nc localhost 11211
@rgo
rgo / change_idle_time_dims_screen.txt
Created October 26, 2011 21:39
Change idle time for dimming screen when run out of AC
1. Install dconf-tools package
2. Run dconf-editor
3. Browse to org.gnome.settings-daemon.plugins.power
4. Change idle-dim-time to your liked value in seconds.
You can run it in a termina:
$ gsettings set org.gnome.settings-daemon.plugins.power idle-dim-time <your_value>
@rgo
rgo / gist:1324325
Created October 29, 2011 10:36
Convert files to utf-8 with vim
## From http://stackoverflow.com/questions/2311750/change-file-encoding-to-utf-8-via-vim-in-a-script
#This is the simplest way I know of to do this easily from the command line:
vim +"argdo se bomb | se fileencoding=utf-8 | w" $(find . -type f -name *.rb)
#Or better yet if the number of files is expected to be pretty large:
find . -type f -name *.rb | xargs vim +"argdo se bomb | se fileencoding=utf-8 | w"
@rgo
rgo / gist:1333701
Created November 2, 2011 14:01
Generate timelapse video from jpg images
# Generate timelapse video from jpg images
mencoder -ovc copy -mf w=320:h=240:fps=6:type=jpg 'mf://*.jpg' -o time_lapse-test.avi
@rgo
rgo / bandwidth_summary.sh
Created December 23, 2011 18:42
Calculates bandwith with netstat
#!/bin/bash
#
## Calomel.org calomel_interface_stats.sh
#
IF=eth0
SECS=`uptime | awk '{ if ($3 ~ /:/) { split($3,a,":"); print (a[1]*60+a[2])*60} else { split($3,b,":"); split($5,a,":"); print b[1]*86400+(a[1]*60+a[2])*60} }'`
EXT_IN=`netstat -n -i $IF | grep $IF | tail -1 | awk '{print $4}'`
EXT_OUT=`netstat -n -i $IF | grep $IF | tail -1 | awk '{print $8}'`
echo " "
@rgo
rgo / unixodbc-configuration-example.sh
Created January 19, 2012 12:15
Unixodbc configuration example with cli
#
# COPIED FROM http://www.1stbyte.com/2011/06/28/unixodbc-example-setup-on-ubuntu-lucid-with-mysql-and-postgresql/
#
# Do the obvious, install mysql an postgresql first. :)
# install unixodbc
apt-get install unixodbc unixodbc-dev libmyodbc odbc-postgresql
cd to /etc/ODBCDataSources