Skip to content

Instantly share code, notes, and snippets.

class BasicObject
def class
classes = []
::ObjectSpace.each_object(::Class).each do |x|
case self
when x then classes << x
end rescue nil
end
classes.reject! { |k| classes.any? { |c| c < k } }.first
end
def self.normalize(name)
if name =~ /^#?<3/
# Special case for love, because the world needs more love.
'<3'
elsif name
name.gsub(/[^#{self.tag_text_regexp}]/, '').downcase
end
end
require 'muzang'
require 'muzang-plugins'
require 'muzang-plugins/muzang-soupirc'
require 'muzang-plugins/muzang-google'
EM.run do
@bot = Muzang::Bot.new(irc_host: "irc.freenode.net", channels: ["#drug.pl"])
@bot.register_plugin(PlusOne)
@bot.register_plugin(LiveReload)
@bot.register_plugin(Motd)
class Rake::Task
def overwrite(&block)
@actions.clear
enhance(&block)
end
end
Rake::Task['db:migrate'].overwrite do
puts "Without migration, srsly?"
end
DATA.rewind
puts DATA.read
__END__
# http://en.wikipedia.org/wiki/Quine_(computing)
@LTe
LTe / responder.rb
Created February 27, 2012 13:30 — forked from mati0090/gist:1923694
{ send_for_approval: "sent for approval",
deactivate: "deactivated",
reactivate: "reactivated",
}.each do |status, desc|
define_method status do
if @offer.send(status)
redirect_to @offer, :notice => "Offer was #{desc}."
else
render :action => "edit"
end
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
# waiting for mr Lte... :)
describe "Soup Agent" do
before do
@agent = Faraday.new(url: 'http://www.soup.io/') do |builder|
builder.use Faraday::Request::UrlEncoded
builder.use Faraday::Response::Logger
builder.use Faraday::Adapter::NetHttp
end
end
@LTe
LTe / me_gusta.rb
Created February 13, 2012 11:27 — forked from paneq/me_gusta.rb
Challenge
class TestUser
def is_ok?
true
end
def receive_message
yield("user", "message")
end
def &(other)
@cache = {}
@cache["test"] = "resource"
def my_method
return value=value if value = @cache["test"]
end
puts my_method # => resource
module RSpec
module Matchers
module Extensions
module InstanceEvalWithArgs
def instance_eval_with_args(*args, &block)
return instance_exec(*args, &block) if respond_to?(:instance_exec)
# If there are no args and the block doesn't expect any, there's no
# need to fake instance_exec with our hack below.
# Notes: