Skip to content

Instantly share code, notes, and snippets.

@nwjsmith
nwjsmith / gist:78305
Created March 12, 2009 21:44
Some macros for making system calls less verbose
#define TRY_ASSIGN(v, x) do { \
v = x; \
if (v == -1) { \
fprintf(stderr, # x ": %s\n", strerror(errno)); \
exit(EXIT_FAILURE); \
} \
} while (0)
#define TRY(x) do { int unused; TRY_ASSIGN(unused, x); } while (0)
alias ssh_gaul="export TERM=xterm && ssh USER_NAME@obelix.gaul.csd.uwo.ca"
Fib(0 * 10): 0
Fib(1 * 10): 55
Fib(2 * 10): 6765
Fib(3 * 10): 832040
Fib(4 * 10): 102334155
Fib(5 * 10): 12586269025
Fib(6 * 10): 1548008755920
Fib(7 * 10): 190392490709135
Fib(8 * 10): 23416728348467685
Fib(9 * 10): 2880067194370816120
byte * fib(byte *prev, byte *curr, int n)
{
byte *next;
// Fib(0) = 0
if (n == 0) { return prev; }
next = sum(prev, curr);
if (n > 2) {
return fib(curr, next, n - 1);
} else {
return next;
We couldn’t find that file to show.
Run the following commands
==========================
wget "http://kernel.org/pub/software/scm/git/git-1.7.0.1.tar.bz2"
tar xvf git-1.7.0.1.tar.bz2
mkdir $HOME/local/
cd git-1.7.0.1
./configure --prefix=$HOME/local/
make
make install
We couldn’t find that file to show.
# Credit to Brandon Keepers
# http://opensoul.org/2007/2/9/automatically-backing-up-your-remote-database-on-deploy
require 'yaml'
desc "Backup the remote production database"
task :backup, :roles => :db, :only => { :primary => true } do
filename = "#{application}.dump.#{Time.now.to_i}.sql.bz2"
file = "/tmp/#{filename}"
env = ENV['RAILS_ENV'] || 'development'
on_rollback { delete file }
" Use Vim settings, rather than Vi settings
set nocompatible
" Use The Pope's awesome pathogen.vim to load plugins
call pathogen#runtime_append_all_bundles()
" Automatically detect filetypes
filetype on
" Use syntax highlighting
ruby-1.9.2-rc1 > f = Father.new
=> #<Father id: nil, name: nil, created_at: nil, updated_at: nil>
ruby-1.9.2-rc1 > f.name = "Dave"
=> "Dave"
ruby-1.9.2-rc1 > s = Son.new :name => "Nate"
=> #<Son id: nil, name: "Nate", father_id: nil, created_at: nil, updated_at: nil>
ruby-1.9.2-rc1 > f.son
f.son_ids f.sons f.sons= f.son_ids=
ruby-1.9.2-rc1 > f.sons << s
=> [#<Son id: nil, name: "Nate", father_id: nil, created_at: nil, updated_at: nil>]