Skip to content

Instantly share code, notes, and snippets.

View somebox's full-sized avatar
⌨️
coding nights

Jeremy Seitz somebox

⌨️
coding nights
View GitHub Profile
@somebox
somebox / music-dsl.rb
Last active August 29, 2015 14:22
music dsl in ruby idea
# song definition
tempo 120
# bassline
instrument :bass, channel: 2 do
preset 'bass/fender_jazz_clean'
end
=== 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 November 25, 2009 13:51
downsample attachment_fu images, rake task
# 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 November 25, 2009 13:44
Downsample attachment_fu images
class Image << ActiveRecord::Base
has_attachment :storage => :file_system,
:content_type => :image,
:processor => 'rmagick',
# ...
named_scope :large, :conditions => "size > #{1.megabytes}"
DEFAULT_QUALITY = 60
# 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)
# 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!
# 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')
// 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 July 13, 2010 09:47
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
<?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 August 17, 2010 14:23 — forked from anonymous/snippet.txt
Installing the mysql gem on OSX

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