Skip to content

Instantly share code, notes, and snippets.

@nofxx
nofxx / project_default_scope_mongoid.rb
Created October 19, 2011 03:41
Mongoid bug default_scope test
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("foo_#{Time.now.to_i}")
end
class Project
include Mongoid::Document
field :name
field :state, :default => 'active'
@nofxx
nofxx / rspec_spec.rb
Created October 15, 2011 08:17
Spork on Rails 3/ActiveRecord/Fabrication
require 'spork'
Spork.prefork do
ENV['RAILS_ENV'] ||= 'test'
require 'rails/application'
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'database_cleaner'
@nofxx
nofxx / spec_helper.rb
Created October 15, 2011 08:01
Finally working spec_helper spork/mongoid/fabrication/capybara
require 'pry'
require 'spork'
# Loading more in this block will cause your tests to run faster.
# if you change any configuration or code from libraries loaded
# need to restart spork for it take effect.
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require 'rails/application'
@nofxx
nofxx / color-theme-fxx.el
Created March 5, 2011 18:55
Emacs color theme
;; Fxx Colour Theme for Emacs.
;;
;; Defines a colour scheme resembling that of the original TextMate Fxx colour theme.
;; To use add the following to your .emacs file (requires the color-theme package):
;;
;; http://wiki.nofxx.com/_detail/x:xxx2tmscreen.png
;;
;; (require 'color-theme)
;; (color-theme-initialize)
;; (load-file "~/.emacs.d/fxx-emacs/color-theme-fxx.el")
@nofxx
nofxx / Makefile
Created February 9, 2011 17:49
AVR Makefile
DEVICE = atmega32 #90s2313
AVRDUDE = avrdude -c usbasp -p $(DEVICE)
# Choose your favorite programmer and interface above.
COMPILE = avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=$(DEVICE) #-DDEBUG_LEVEL=2
# NEVER compile the final product with debugging! Any debug output will
# distort timing so that the specs can't be met.
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
psql -U postgres
create database template_postgis with template = template1;
UPDATE pg_database SET datistemplate = TRUE where datname = 'template_postgis';
\c template_postgis
CREATE LANGUAGE plpgsql;
# arch
\i /usr/share/postgresql/contrib/postgis-1.5/postgis.sql
\i /usr/share/postgresql/contrib/postgis-1.5/spatial_ref_sys.sql;
@nofxx
nofxx / serialize.rb
Created June 28, 2010 23:07
JSON vs BSON
#!/usr/bin/env ruby
require 'benchmark'
require 'json'
require 'bson'
T = 100_000
[{ :foo => 2 }, { :foo => 2, :bar => 3, :baz => "long very very long and big and uncut string" },
{ :foo => 2, :bar => 3, :baz => "long very very long and big and uncut string",
class DeliciousToken < ConsumerToken
DELICIOUS_SETTINGS = {
:site => 'https://api.login.yahoo.com',
:http_method => :get,
:scheme => :query_string,
:request_token_path => '/oauth/v2/get_request_token',
:access_token_path => '/oauth/v2/get_token',
:authorize_path => '/oauth/v2/request_auth',
}
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#
# Nanite Initializer
#
def load_mapper_opts
YAML.load(File.read(RAILS_ROOT + "/config/rabbitmq.yml"))#.result) #[ENV["RAILS_ENV"] || "development"]
end
if ENV["NO_NM"].nil? && RAILS_ENV != "test"
if defined?(PhusionPassenger)