Skip to content

Instantly share code, notes, and snippets.

View oriolgual's full-sized avatar

Oriol Gual oriolgual

View GitHub Profile
@oriolgual
oriolgual / elastic_search_indexer.rb
Created March 22, 2013 11:01
Companion gist for my talk about using ElasticSearch with Ruby.
# Public: A module to be mixed in another class with common methods to index
# records in ElasticSearch.
#
# The host object needs to respond to 'indexed_attributes', which will return
# an array of the attributes names to be indexed.
#
# It's also recommended to override the 'save?' method to make sure only
# records that match some specifications are indexed.
#
# The type used for the ElasticSearch index will be extracted from the name of
@oriolgual
oriolgual / pusher_webhooks_spec.rb
Created January 10, 2013 10:31
Testing Pusher Webhooks with rspec_api_documentation
require 'spec_helper'
require 'rspec_api_documentation/dsl'
resource "Pusher Webhooks" do
let(:user) { Fabricate(:user) }
let(:channel) { YOUR_CHANNEL_NAME }
post '/api/pusher_webhook' do
let(:pusher_key) { YOUR_PUSHER_KEY }
let(:pusher_secret) { YOUR_PUSHER_SECRET }
@oriolgual
oriolgual / hypermodel.rb
Created August 9, 2012 19:28
Readme Driven Development for Hypermodel
module Hypermodel
module ClassMethods
# Public: Adds a new link to the _links section of the representation.
#
# relation - A String or Symbol with the name of the relation. It will
# also be used as a method name to call in the Hypermodel
# class or in the resource (as a second option) to get the href
# if no href provided.
# href - An optional String with the href of the link.
# options - An optional hash to add to the link (like tempalted: true).
@oriolgual
oriolgual / macvim.rb
Created August 9, 2012 13:00
MacVim homebrew formula with clipboard support (useful when use the console mode)
require 'formula'
class Macvim < Formula
homepage 'http://code.google.com/p/macvim/'
url 'https://github.com/b4winckler/macvim/tarball/snapshot-64'
version '7.3-64'
sha1 'c8bf2d758f52a1173112138fefbf4e5ab08015ff'
head 'https://github.com/b4winckler/macvim.git', :branch => 'master'
@oriolgual
oriolgual / hyperclient.rb
Created August 5, 2012 17:30
Hyperclient refactor
# Read last HAL draft first: http://tools.ietf.org/html/draft-kelly-json-hal-03
api = MyBlogAPI.new
# Entry point
api.links #=> {'self' => link_to_self, 'relation' => link1}
api.links.self.url #=> '/'
api.embedded #=> {}
# Links
@oriolgual
oriolgual / no_tap.rb
Created July 6, 2012 10:09
to tap or not to tap?
def do_it(ids)
contacts = contact_finder(ids)
contacts = contacts.my_nice_scope if should_apply_nice_scope?
contacts
end
One of the possible consequences of the welfare state is the lack of culture of the effort. Everything is easy and free.
A clear example is the university (at least in Spain), it's very easy to get to college (both financially and academically),
but since it is almost free it is not given enough importance: it's OK if I spend the day lying on the grass or don't
go to class or I just left college because the cost is zero.
Details of abandonment: http://www.consumer.es/web/es/educacion/universidad/2010/03/21/191878.php (Spanish)
Just see the last few years in Spain, the real estate boom is the best example of the lack of the culture of effort.
@oriolgual
oriolgual / backtrace.sh
Created January 30, 2012 12:05
Bug with Rails 3.2.1 and PG
Oriols-Mac-Pro:test_3_2_1 $ bundle exec rails console
Loading development environment (Rails 3.2.1)
~> Console extensions: wirble hirb ap rails2 rails3 pm interactive_editor blueprints
1.9.3-p0 :001 > Subject.first.student_ids
SCHEMA (0.3ms) SHOW client_min_messages
SCHEMA (0.1ms) SET client_min_messages TO 'panic'
SCHEMA (0.1ms) SET standard_conforming_strings = on
SCHEMA (0.0ms) SET client_min_messages TO 'notice'
SCHEMA (0.3ms) SET time zone 'UTC'
SCHEMA (0.1ms) SHOW TIME ZONE
@oriolgual
oriolgual / validate_spanish_vat.rb
Created January 18, 2012 14:10
Spanish VAT validator for Ruby
module ValidateSpanishVat
module ClassMethods
# Implements model level validator for Spanish's VAT number.
# Usage:
#
# Inside a model with a vat field, simply put
#
# validates_spanish_vat field_name
#
def validates_spanish_vat(*attr_names)
Rubinius Crash Report #rbxcrashreport
Error: signal SIGSEGV
[[Backtrace]]
0 rbx 0x00000001000225b1 _ZN8rubiniusL12segv_handlerEi + 241
1 libSystem.B.dylib 0x00007fff8666067a _sigtramp + 26
2 ??? 0x0000000102ecf080 0x0 + 4344049792
3 rbx 0x00000001002136b6 _ZN8rubinius16GarbageCollector11scan_objectEPNS_6ObjectE + 182
4 rbx 0x0000000100211d6b _ZN8rubinius7BakerGC14copy_unscannedEv + 283