Skip to content

Instantly share code, notes, and snippets.

View lorenzoplanas's full-sized avatar
💭
🏖️

Lorenzo Planas lorenzoplanas

💭
🏖️
View GitHub Profile
class Post
include Mongoid::Document
field :title, :type => String
has_many :comments do
def update(selector, params)
@target.each { |t| t.update_attributes(params) if t.matches?(selector) }
end
end
end
require 'eventmachine'
require 'net/pop'
class Popper
attr_accessor :pop, :read_messages
def initialize(hostname, port, user, password)
@pop = Net::POP3.start(hostname, port, user, password)
@read_messages = []
load_message_ids
class Asset
include Mongoid::Document
field :name
field :peer_ids, :type => Array, :default => []
def link_asset(asset_id)
unless self.peer_ids.include?(asset_id) || self.id == asset_id
self.peer_ids << asset_id
Asset.find(asset_id).link_peer(self.id)
end
@lorenzoplanas
lorenzoplanas / Nokogiri partials
Created June 11, 2011 11:49
Building templates and partials with Nokogiri
# encoding: utf-8
require "nokogiri"
@doc = Nokogiri::HTML::Document.new
def my_partial(parent)
Nokogiri::HTML::Builder.with parent do
p_ "foo"
p_ "bar"
end
@lorenzoplanas
lorenzoplanas / Bar.rb
Created September 12, 2011 05:05
jruby - develop & test using jruby interpreter. Compile the code to Java bytecodes and run it straight away
# encoding: utf-8
require "Foo"
class Bar
def self.say_hello
Foo.say_hello
end
@lorenzoplanas
lorenzoplanas / http_client_spec.rb
Created December 13, 2011 09:22 — forked from xaviershay/http_client_spec.rb
Running a rack app in a thread for integration tests.
require 'integration_helper'
require 'rack'
require 'rack/handler/webrick'
describe HttpClient do
before :all do
@server = WEBrick::HTTPServer.new(
:Port => 9293,
:Logger => Rails.logger,
:AccessLog => Rails.logger
@lorenzoplanas
lorenzoplanas / em_syslog2.rb
Created December 13, 2011 09:22 — forked from ngauthier/em_syslog2.rb
An EventMachine Syslog Protocol
# this is a configurable version of an EventMachine syslogger
# It was build to replace https://github.com/melito/em-syslog
#
# You can instantiate many of them (no global variables) as
# well as configure the facility. It also quacks like a ruby
# logger so it can be interchanged with a ruby logger.
#
# Example:
#
# # 11 is the facility code for an FTP daemon
@lorenzoplanas
lorenzoplanas / jruby-1.7.0-output.txt
Created November 20, 2012 14:43
Minitest::Mock broken in JRuby 1.7.0?
************************************
* minitest gem: minitest-4.3.1 *
************************************
Run options: --seed 65366
# Running tests:
.E
curl -XPUT http://localhost:9200/users/_mapping -d '{
"user" : {
"properties" : {
"author" : {
"type" : "string",
"analyzer" : "string_lowercase"
}
}
}
}'
@lorenzoplanas
lorenzoplanas / runner.rb
Created September 22, 2013 16:52
Testing EventMachine periodic timers
require 'eventmachine'
module Sample
class Runner
DEFAULT_INTERVAL_IN_SECS = 1
def initialize(command, interval=DEFAULT_INTERVAL_IN_SECS)
@command = command
@interval = interval
end