Skip to content

Instantly share code, notes, and snippets.

@diodoe
diodoe / gist:812637
Created February 5, 2011 17:58
gem mysql Rails Configuration for snow leopard and macport
sudo env ARCHFLAGS="-Os -arch x86_64 -fno-common" gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5
@diodoe
diodoe / mysql2csv.sh
Created February 5, 2011 11:20
Export mysql tables in csv with sed
#!/bin/bash
mysql -uexampleuser -pletmein exampledb -B -e "select * from \`person\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > filename.csv
@diodoe
diodoe / fixtures.rake
Created February 5, 2011 10:52
Fixture dump in yaml for models in a rails application
namespace :db do
namespace :fixtures do
desc 'Create YAML test fixtures from data in an existing database.
Defaults to development database. Set RAILS_ENV to override.'
task :dump => :environment do
sql = "SELECT * FROM %s"
skip_tables = ["schema_info"]
ActiveRecord::Base.establish_connection(:development)
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
before(:each) do
@fanout = mock("fanout")
@binding = mock("binding", :subscribe => true)
@queue = mock("queue", :bind => @binding, :publish => true)
@amq = mock("AMPQueue", :queue => @queue, :fanout => @fanout)
@serializer = mock("Serializer", :dump => "dumped_value")
@target = mock("Target of Request")
@reaper = mock("Reaper")
Nanite::Reaper.stub!(:new).and_return(@reaper)
@request_without_target = mock("Request", :target => nil, :token => "Token",
@diodoe
diodoe / xmas_tree.php
Created October 15, 2010 15:03
create a numeric pyramid with random numbers
<?php
//You'd find it useful to resolve the http://bit.ly/aySVgM problem ;)
//Number of total rows
$tot_row=100;
//Spacer between the numbers
$spacer=' ';
//file where the pyramid will be saved
$file='triangle.txt';
@diodoe
diodoe / resize_image_by_window.js
Created October 15, 2010 14:39
Resize image based on the window size (jQuery)
//Adjust image size
//needs jquery
//put a #grid and #resizeme on your html and call $('#resizeme').resizeimg()
$.fn.resizeimg = function() {
//Define starting width and height values for the original image
var startwidth = 1280;
var startheight = 960;
//Define image ratio
var ratio = startheight/startwidth;
//Gather browser dimensions