Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremy Seitz somebox

View GitHub Profile
@somebox
somebox / music-dsl.rb
Last active Aug 29, 2015
music dsl in ruby idea
View music-dsl.rb
# song definition
tempo 120
# bassline
instrument :bass, channel: 2 do
preset 'bass/fender_jazz_clean'
end
View gist:184801
=== Snow Leopard, Ruby and MySQL
I was finally able to get the mysql 2.8.1 gem after a snow leopard upgrade. After trying many different builds, 64 vs. 32, etc, I ended up:
- removing the existing mysql bundle
$ sudo rm /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
- installing 64-bit mysql 5.0 from the .dmg download
- building the gem with this command:
@somebox
somebox / gist:242711
Created Nov 25, 2009
downsample attachment_fu images, rake task
View gist:242711
# downsample large attachment_fu images
namespace :images do
desc "Downsample Large Images"
task :downsample_large => :environment do
count = Image.large.count # named scope
chunk_size = 500
(0...(count/chunk_size)).each do |i|
images = Image.large.find(:all, :offset=>i*chunk_size, :limit=>chunk_size).each do |image|
image.downsample!(55)
end
@somebox
somebox / gist:242707
Created Nov 25, 2009
Downsample attachment_fu images
View gist:242707
class Image << ActiveRecord::Base
has_attachment :storage => :file_system,
:content_type => :image,
:processor => 'rmagick',
# ...
named_scope :large, :conditions => "size > #{1.megabytes}"
DEFAULT_QUALITY = 60
View gist:242716
# Use spawn to fork the resize.
# you'll want to have the following lines in environment.rb:
# Spawn::method :fork, 'production'
# Spawn::method :yield, 'test'
def downsample!(quality=DEFAULT_QUALITY)
id = spawn do
image = Magick::ImageList.new(self.absolute_filename)
image.write("jpeg:#{self.absolute_filename}") {self.quality = quality}
end
wait(id)
View geocode_mocks_examples.rb
# example tests
test "geocoder is used when new point is saved" do
geocoder_should_be_used
p = Point.new(:address => ..., :city => ... )
assert p.save
end
test "point will re-geocode if the address changes" do
gecoder_should_be_used # only once!
View geocoder_mocks.rb
# GeoKit geocoder mocks, place in test_helper.rb
# mocks
def geo_mock(options={})
defaults = {:lat=>1, :lng=>2,
:precision=>'address', :success => true,
:street_address=>'address', :zip=>'12345',
:city=>'city', :state=>'state',
:full_address => 'full address'}
res = mock('response')
View application.js
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(function() {
MIN_ANSWERS = 2
MAX_ANSWERS = 10
MIN_ANSWERS_MSG = "Minimum of two(2) answers required."
MAX_ANSWERS_MSG = "Maximum of ten(10) answers only."
TOP_ANSWER_MSG = "Can't go up answer is on the top list."
@somebox
somebox / network_tests.php
Created Jul 13, 2010
A simple PHP script to help test applications that access web pages. It provides a reliable way to simulate normal page load, 500 and 404 errors, redirects, PDF download, variable response delays, and a browser-killing huge te
View network_tests.php
<?php /* A simple PHP script to help test applications that access web pages.
It provides a reliable way to simulate normal page load, 500 and
404 errors, redirects, PDF download, variable response delays,
and a browser-killing huge text response.
To install, copy to your PHP-enabled web server. There are no other
dependencies. Access the script via your browser to see instructions.
http://gist.github.com/gists/473681
July 2010 - Jeremy Seitz
@somebox
somebox / mysql_install.md
Created Aug 17, 2010 — forked from anonymous/snippet.txt
Installing the mysql gem on OSX
View mysql_install.md

Mysql gem under OSX:

Install:

option 1:

Try to use existing mysql under OSX.

$ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
You can’t perform that action at this time.