Skip to content

Instantly share code, notes, and snippets.

@brenes
brenes / app_models_wiki_page.rb
Created September 13, 2011 00:10
Weird bug (or something I just don't get) on ActiveRecord relationships
# WikiPage(id: integer, title: string, fetched_at: date, created_at: datetime, updated_at: datetime, ancestry: string, url: string, is_root: boolean, wiki_tree_id: integer)
# The whole code is at https://github.com/brenes/Wiki-Roots
class WikiPage < ActiveRecord::Base
belongs_to :tree, :class_name => "WikiTree"
# ...
@brenes
brenes / Cucumber Plain Text Feature.tmLanguage
Created September 28, 2011 16:00 — forked from unixmonkey/Cucumber Plain Text Feature.tmLanguage
Cucumber Language definition file for TextMate; modified to work with Sublime Text 2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>feature</string>
</array>
<key>firstLineMatch</key>
<string>기능|機能|功能|フィーチャ|خاصية|תכונה|Функціонал|Функционалност|Функционал|Особина|Могућност|Özellik|Właściwość|Tính năng|Savybė|Požiadavka|Požadavek|Osobina|Ominaisuus|Omadus|OH HAI|Mogućnost|Mogucnost|Jellemző|Fīča|Funzionalità|Funktionalität|Funkcionalnost|Funkcionalitāte|Funcționalitate|Functionaliteit|Functionalitate|Funcionalitat|Funcionalidade|Fonctionnalité|Fitur|Feature|Egenskap|Egenskab|Crikey|Característica|Arwedd(.*)</string>
@brenes
brenes / twitter-stream-connection.rb
Created November 3, 2011 00:11
Change on the connect method on twitter-stream gem due to SSL requirements
# Starting on 2011/09/29 Twitter Streaming API requires SSL to access.
# Twitter stream gem is a gem built over EventMachine to get access to Twitter Streaming API
# Unfortunately Twitter Stream uses http by default, not https.
# We have to pass two extra options to the connect method
stream = Twitter::JSONStream.connect(
:path => "/1/statuses/filter.json?track=20N",
:auth => "USER:PASS",
# And the extra params!!
:port => 443,
@brenes
brenes / rack_utils_header_hash_extension.rb
Created January 13, 2012 13:27
Fix for problem between cucumber/Mundo Pepino/Webrat and Rack::Rewrite
# I had Cucumber / Mundo Pepino configured with Webrat and used jtrupiano's Rack::Rewrite (https://github.com/jtrupiano/rack-rewrite) to handle redirections between some old URLs and new ones
# When I tested if redirections were being handled correctly I encountered with a big issue: URL of the redirection appeared to be nil.
# I tested it manually and redirections were fine, so I though this could be a problem with the interaction between Rack::Rewrite and Webrat.
# After some dig and debug on the gems (cucumber, webrat and rack mostly) code I found the problem:
# Line 283 of lib/webrat/core/session.rb
#
# def response_location
# response.headers["Location"]
# end
@brenes
brenes / .gitignore
Created January 29, 2012 23:33 — forked from karmi/.gitignore
Simple ping:pong WebSockets server and client in Ruby (em-http and em-websocket
Gemfile.lock
@brenes
brenes / rawclone_bundler.rb
Created February 8, 2012 12:21 — forked from rsierra/rawclone_bundler.rb
Script para generar el Gemfile de bundler a partir de un 'gem list'
#!/usr/bin/env ruby
# So you want to start developing an already "woking" project. No
# bundle, config.gem's not present or messing up dependencies. Fear
# not!
# Do a "gem list" wherever the project is already working
# (production?, some colleage machine?). Make a file with this format:
#
# chronic (0.2.3)
# colored (1.1)
@brenes
brenes / index.html
Created February 8, 2012 19:16 — forked from enjalot/index.html
Simple Pie Chart example with D3.js
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Testing Pie Chart</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?2.1.3"></script>
<style type="text/css">
def set_locale
# Si estoy en NavItemsController, y el match se hace con *, el locale
# en realidad está en el primer item de nicetitles
if controller_name == "nav_items" &&
params[:nicetitles].present? &&
Settings.app.locales.keys.map(&:to_s).include?(params[:nicetitles].first)
I18n.locale = params[:nicetitles].shift
elsif params[:locale].present?
I18n.locale = params[:locale]
else
@brenes
brenes / rails-admin-ancestry-example
Created April 23, 2012 23:18
Create an enum for 'parent_id' ancestry column
field :parent_id, :enum do
enum do
(ProcessType.select("id, name")||[]).map{|c|[c.name, c.id]} || [] #this is just an example though
end
end
@brenes
brenes / delayed_job_patch.rb
Created April 24, 2012 10:57
Disabling delayed jobs
# DelayedJob in its latest version allows to disable job delaying by a simple Delayed::Worker.delay_jobs = false.
# If we're using a previous version (i.e. the branch compatible with Rails 2), we need to open Delayed proxy class and force it to perform the works
# This way, in testing we can test mail delivieries and others
module Delayed
module MessageSending
def send_later(method, *args)
Delayed::PerformableMethod.new(self, method.to_sym, args).perform
end
end
end