Skip to content

Instantly share code, notes, and snippets.

View unders's full-sized avatar

Anders Törnqvist unders

  • Functionbox
  • Göteborg, Sweden
View GitHub Profile
# Build an inverted index for a full-text search engine with Redis.
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License.
# USAGE:
#
# ruby invertedindex.rb add somedir/*.c
# ruby invertedindex.rb add somedir/*.txt
# ruby search your query string
require 'rubygems'
require 'redis'
require 'action_view'
require 'active_support'
require 'mustache'
class Mustache
# TODO - Think about allowing to overwrite layout methods in subclassing views
#
# http://github.com/defunkt/mustache/blob/master/lib/mustache/sinatra.rb#L79-82
# http://github.com/defunkt/mustache/blob/master/lib/mustache/sinatra.rb#L96-102
@unders
unders / default.rb
Created October 18, 2010 14:49 — forked from ezmobius/default.rb
#
# Cookbook Name:: delayed_job
# Recipe:: default
#
if ['solo', 'app', 'app_master'].include?(node[:instance_role])
# be sure to replace "app_name" with the name of your application.
run_for_app("maloca") do |app_name, data|
@unders
unders / god.rb
Created October 18, 2010 14:53 — forked from defunkt/god.rb
rails_root = "/data/github/current"
20.times do |num|
God.watch do |w|
w.name = "dj-#{num}"
w.group = 'dj'
w.interval = 30.seconds
w.start = "rake -f #{rails_root}/Rakefile production jobs:work"
w.uid = 'git'
@unders
unders / Presenter.rb
Created November 26, 2010 15:05
Presenter that works with Rails
#app/presenters/article_presenter
module ArticlePresenter
def fancy_name
end
end
#app/presenters/comment_presenter
module CommentPresenter
def fancy_name
end
@bryanl
bryanl / tmux.conf
Created November 30, 2010 05:17
I copied this from somewhere. It is a good start, though
# ~/.tmux.conf
#
# See the following files:
#
# /opt/local/share/doc/tmux/t-williams.conf
# /opt/local/share/doc/tmux/screen-keys.conf
# /opt/local/share/doc/tmux/vim-keys.conf
#
# URLs to read:
#
@vangberg
vangberg / curb.rb
Created December 14, 2010 20:10
persistent http w/ ruby
require "curb"
# Persistent.
c = Curl::Easy.new
c.url = "http://127.0.0.1"
2.times { c.perform }
# Not persistent.
2.times {
c = Curl::Easy.new
@milandobrota
milandobrota / monty_hall.rb
Created December 19, 2010 18:24
Monty Hall Problem simulation written in Ruby. Usage: ruby monty_hall.rb <number of games>
class Show
attr_reader :games
def initialize
@games = []
end
def first_pick(door)
@current_game = Game.new(door)
@current_game.first_pick(door)
body = MultipartBody.new(:field1 => 'test', :field2 => 'test2')
http = EventMachine::HttpRequest.new('http://example.com').post(
:head => {'content-type' => "multipart/form-data; boundary=#{body.boundary}"},
:body => body.to_s
)
# Or with a file part included
part1 = Part.new('name', 'content', 'file.txt')
@zefer
zefer / nginx_cors_s3_upload_proxy_full
Created February 18, 2011 13:29
My nginx config to allow CORS (cross-site) uploads to Amazon S3, with added config e.g. timeouts & security
# DO NOT RESPOND TO REQUESTS OTHER THAN yourdomain.com
server {
listen 80 default;
server_name _;
return 444;
}
# FILE UPLOADS
server {
listen 80;