Skip to content

Instantly share code, notes, and snippets.

@cwise
cwise / gist:1353943
Created November 10, 2011 02:37
Ubuntu MySQL
The socket is in a weird spot on Ubuntu - add this symbolic link to put it where everyone expects:
ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
@cwise
cwise / gist:1353890
Created November 10, 2011 02:06
Ubuntu installation of RVM with openssl
rvm pkg install openssl
rvm remove 1.9.2
rvm install 1.9.2 --with-openssl-dir=$HOME/.rvm/usr
@cwise
cwise / calc.js
Created October 20, 2011 19:18
Calculate for recommendation
var calculate = function ($) {
var revenue=$('#revenue').val();
var margin = 0.3;
var profit1=(revenue * margin) - (revenue * 0.15);
var profit2=(revenue * margin) - (revenue * 0.05 + 100);
var profit3=(revenue * margin) - (revenue * 0.01 + 250);
$('#profit1').text(profit1);
$('#fee1').text(revenue * 0.15);
@cwise
cwise / streak.rb
Created November 8, 2010 20:19
I want to refactor this method
def streak
return "-" if @played_games.empty?
games=@played_games
streak=0
game=games.pop
last_result=game.result_type(@team.id)
until game.nil? || game.result_type(@team.id)!=last_result do
game=games.pop
streak+=1
@cwise
cwise / seeds_gen.rb
Created November 5, 2010 10:59
Generate a seeds.rb from existing data
# given a model (SomeModel), generate seeds.rb file from existing data in the database
elements=SomeModel.all.collect do |m|
"#{m.class.to_s}.create(#{m.attributes.select{|k, v| !["id", "created_at", "updated_at"].include?(k)}.collect{ |k, v| ":#{k} => '#{v.to_s.gsub("'", "\\\\'")}'" }.join(', ')})"
end
File.open('seeds.rb', 'w') {|f| elements.each{|element| f.puts(element)} }