Skip to content

Instantly share code, notes, and snippets.

@etrepat
etrepat / rails-install.sh
Created July 19, 2010 11:45
How to install ruby/rails dev. environment on Ubuntu 11.10
# Build-tools + Git
sudo apt-get install build-essential git-core
# Install required libraries & tools
sudo apt-get install bison openssl libreadline6 libreadline6-dev curl zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf
# -- SQLite3 support
sudo apt-get install libsqlite3-0 libsqlite3-dev sqlite3
# -- PostgreSQL support
@etrepat
etrepat / example_gist_create.rb
Created November 11, 2010 16:42 — forked from schacon/example_gist_create.rb
Old gits api calls
require 'net/http'
require 'uri'
# /api/v1/:format/new
# /api/v1/:format/gists/:user
# /api/v1/:format/:gist_id
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'),
{ 'files[file1.ab]' => 'CONTNETS',
'files[file2.ab]' => 'contents' })
@etrepat
etrepat / gist:1018500
Created June 10, 2011 08:51 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@etrepat
etrepat / criteria.rb
Created June 12, 2011 18:56 — forked from outoftime/criteria.rb
Instantiate the results of map-reduce operations as Mongoid documents
module Mongoid
class Criteria
include Criterion::MapReduce
end
end
@etrepat
etrepat / redis_pubsub_demo.rb
Created July 4, 2011 11:43 — forked from pietern/redis_pubsub_demo.rb
Simple demo to showcase Redis PubSub with EventMachine
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@etrepat
etrepat / dsl.rb
Created July 4, 2011 13:39
Very simple unit testing framework (in ~44 lines)
class Dsl
def initialize
@tests = {}
end
def parse(description, block)
self.instance_eval(&block)
Executor.new(description, @tests)
end
def it(description, &block)
@tests[description] = block
@etrepat
etrepat / triangle_check.rb
Created July 14, 2011 10:55
Check if a given point is inside a triangle
# encoding: utf-8
require 'pp'
class Point
attr_accessor :x, :y
def initialize(x=0.0, y=0.0)
@x = x
@y = y
end
@etrepat
etrepat / class_instance_vars.rb
Created July 26, 2011 10:56
Why I don't use class variables in Ruby (or try not to)
class Person
@name = nil
# class-level reader
# cattr_accessor is rails-specific not ruby, and uses class vbles so ...
# may be done like this too:
#
# class << self
# attr_reader :name
# end
@etrepat
etrepat / FIle.sublime-settings.json
Created October 15, 2011 18:44
Sublime Text 2 - My Settings
{
// Sets the colors used within the text area
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
// Note that the font_face and font_size are overriden in the platform
// specific settings file, for example, "Base File (Linux).sublime-settings".
// Because of this, setting them here will have no effect: you must set them
// in your User File Preferences.
"font_face": "Monaco",
"font_size": 12,
@etrepat
etrepat / dnsd.rb
Created December 7, 2011 22:12 — forked from peterc/dnsd.rb
Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL