Skip to content

Instantly share code, notes, and snippets.

View sentientmonkey's full-sized avatar

Scott Windsor sentientmonkey

View GitHub Profile
#include <math.h>
#include <stdio.h>
int main() {
double a = 16.99;
double b = 100.0;
printf("a is %f\n", a);
printf("b is %f\n", b);
Error: signal SIGSEGV
0 rbx 0x00000001000474af _ZN8rubiniusL12segv_handlerEi + 159
1 libSystem.B.dylib 0x00007fff8026480a _sigtramp + 26
2 ??? 0x0000000000000000 0x0 + 0
3 libMagickCore.2.dylib 0x00000001073189b5 AcquirePixelCache + 325
4 libMagickCore.2.dylib 0x00000001073c3406 AcquireImage + 358
5 libMagickCore.2.dylib 0x00000001073c3af2 SetImageInfo + 466
6 libMagickCore.2.dylib 0x000000010734056d ReadImage + 173
7 RMagick2.bundle 0x000000010719b712 rd_image + 318
@sentientmonkey
sentientmonkey / unicorn_production.rb
Created April 8, 2011 00:52
This is our unicorn config! It's magical!
worker_processes 6
preload_app true
timeout 180
listen 8100
working_directory "/opt/teachstreet/web-app/current"
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"
@sentientmonkey
sentientmonkey / unicorn_capistrano.rb
Created April 8, 2011 01:01
Our deploy for unicorn. It also has magical powers.
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :unicorn do
desc "start unicorn"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} bundle exec unicorn_rails -c #{current_path}/config/unicorn-#{rails_env}.rb -E #{rails_env} -D"
end
desc "stop unicorn"
task :stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill `cat #{unicorn_pid}`"
@sentientmonkey
sentientmonkey / to_xml.rb
Created April 8, 2011 22:38
lambda magic...
def to_xml(options = {})
options[:indent] ||= 2
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
xml.instruct! unless options[:skip_instruct]
xml.deal do
xmlify = lambda do |key,value|
case value
when Array
xml.tag!(key.to_sym) do
value.map{|v| [key.to_s.singularize, v]}.each(&xmlify)
@sentientmonkey
sentientmonkey / jquery.crossfade.js
Created August 19, 2011 21:55
javascript/jquery crossfader for tiled images
(function($) {
// crossfade takes an image list, which is an array of hashes with
// src: image url
// title: link title
// href: link url
//
// available options:
// fadeTime: time in msec of how long cross fade transition takes
// waitTime: time in msec of how long to wait between transitions
// imageHeight: height of each image
@sentientmonkey
sentientmonkey / pluralize.js
Created September 22, 2011 23:23
Pluralize for Javascript
Number.prototype.plural = function(){
if(this > 1 || this == 0){
return true;
} else {
return false;
}
}
String.prototype.pluralize_rules = function(){
return [[new RegExp('$', 'gi'), 's']];
@sentientmonkey
sentientmonkey / .vimrc
Last active December 13, 2015 22:19
interactive repl with vim
" map ,r to run contents in repl
map ,r :w\|:silent !cat % > repl-command<cr>:redraw!<cr>
" map ,r in visual mode to run contents in repl
vmap ,r :w !cat > repl-command<cr>:redraw!<cr>
" map ,l to map current line in repl
map ,l :silent.w !cat > repl-command<cr>:redraw!<cr>
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :log_params
private
def log_params
logger.debug "*********** Session Data ***********"
session.each do |k,v|
Foo::Application.routes.draw do
constraints(:host => /^example.com/) do
root :to => redirect("http://www.example.com")
match '/*path', :to => redirect {|params| "http://www.example.com/#{params[:path]}"}
end
end