Skip to content

Instantly share code, notes, and snippets.

View ilpoldo's full-sized avatar

Leandro Pedroni ilpoldo

  • Double Negative
  • London, UK
View GitHub Profile

Keybase proof

I hereby claim:

  • I am ilpoldo on github.
  • I am ilpoldo (https://keybase.io/ilpoldo) on keybase.
  • I have a public key ASCI3ULXK4PMzdY_mc7EJQmansDe2kfKSujs-tEczBaArgo

To claim this, I am signing this object:

@ilpoldo
ilpoldo / config.ru
Created November 24, 2014 17:09
geminabox + pow
require "rubygems"
require "geminabox"
Geminabox.data = File.expand_path('data', File.dirname(__FILE__))
run Geminabox
@ilpoldo
ilpoldo / mobile_detect.rb
Created July 22, 2013 07:49
Rails3 mobile subdomain redirection example
module MobileDetect
class Constraint
def matches?(request)
return false if request.cookies[:full_site_form_mobile] || request.host.match(/^m./)
request.user_agent.to_s.match(/Mobile/)
end
end
@ilpoldo
ilpoldo / config.ru
Created September 1, 2012 17:31 — forked from granth/config.ru
# Rack file for local Rubygems server, using YARD
require "rubygems"
require "yard"
libraries = {}
Gem.source_index.find_name('').each do |spec|
libraries[spec.name] ||= []
libraries[spec.name] << YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)
end
@ilpoldo
ilpoldo / testObjects.py
Created July 10, 2011 23:46
Python Useful Test Objects
import sys,types
class MockCallable():
""" Mocks a function, can be enquired on how many calls it received """
def __init__(self, result):
self.result = result
self._calls = []
def __call__(self, *arguments):
"""Mock callable"""
self._calls.append(arguments)
// Here is where you can define your constants for your application and to configure the blueprint framework.
// Feel free to delete these if you want keep the defaults:
$blueprint-grid-columns: 24;
$blueprint-container-size: 950px;
$blueprint-grid-margin: 10px;
// Use this to calculate the width based on the total width.
// Or you can set !blueprint_grid_width to a fixed value and unset !blueprint_container_size -- it will be calculated for you.
$blueprint-grid-width: ($blueprint-container-size + $blueprint-grid-margin) / $blueprint-grid-columns - $blueprint-grid-margin;
class Sentence < ActiveRecord::Base
has_many :translations
accepts_nested_attributes_for :translations, :allow_destroy => true, :reject_if => proc { |obj| obj[:text].blank? }
end
@ilpoldo
ilpoldo / mongoid_references_spec.rb
Created February 2, 2011 22:49
Trying to make sense of Mongoid's associations
require 'spec_helper'
class Instructor
include Mongoid::Document
embeds_many :courses
references_many :cool_rides
# references_many :trusted_collegues, :class_name => 'Instructor' #- raises NoMethodError 'entries' for #<Instructor:0x1062f1e10>
references_and_referenced_in_many :trusted_collegues, :class_name => 'Instructor'
# Create an italian word and add a definition to it
>> w = Word.create(:word => 'cestino', :language => :it)
#<Word _id: 4d41abc38b8e6b3001000002, word: "cestino", language: :it, origin: nil, pronunciation: nil>
>> w.definitions.create :kind => :noun, :text => 'un posto dove buttare le cose'
#<Definition _id: 4d42a9238b8e6b5fa2000003, kind: :noun, text: "un posto dove buttare le cose">
# Add a translation (a word in another language) to the definition
>> w.definitions.first.translations.create(:word => 'recycling bin', :language => :en)
NoMethodError: undefined method `first' for #<Definition:0x10668c020>
@invalid_user = Factory.create(:user)
@invalid_user.stub(:valid?).and_return(false)
User.stub(:new).and_return(@invaild_user)
post :create, :user_name => "some user name that won't even be used"