Skip to content

Instantly share code, notes, and snippets.

View americodls's full-sized avatar
:shipit:

Américo Duarte americodls

:shipit:
  • Dublin, Ireland
View GitHub Profile
@courtenay
courtenay / gist:4498771
Last active December 10, 2015 21:59
MONKEY PATCH: no "xml type=yaml" in your .to_xml dump of activerecord objects
# RAILS 2.3.15
#
# Since <tag type="yaml"> was removed from rails' xml parsing,
# but not from its to_xml method, rails can't talk to an API
# generated by rails, if you have serialized attributes.
# This can be put in config/initializers and you should probably
# upgrade to rails 3 already. Ugh.
# Three parts:
# http://redis.io/commands/rpoplpush
module Resque
def self.move_queue(source, destination)
r = Resque.redis
r.llen("queue:#{source}").times do
r.rpoplpush("queue:#{source}", "queue:#{destination}")
end
end
end
@wacko
wacko / clock
Last active January 3, 2016 07:19
Emoji animations that fit in a tweet
ruby -e 'z=0x1F551;->(c,&b){loop{c.each(&b)}}.(11.times.map{|i|[z+i].pack("U")}){|m|print "#{"\b"*3}#{m} ";sleep 0.1}'
@spalenza
spalenza / pre-commit
Last active May 30, 2017 18:24
Git hook for commit. Add in .git/hooks/pre-commit
#!/usr/bin/env ruby
# .git/hooks/pre-commit
# Git pre-commit hook that catches errors that I commonly make.
#
# To intentionally ignore the hook (i.e., when adding an alert call), commit
# from the command line with "--no-verify"
#
# Loosely based on Henrik Nyh's <http://henrik.nyh.se> work (2011-10-08)
# under the MIT License.
@shadowmaru
shadowmaru / slides.md
Last active November 26, 2020 07:17
Palestras da RubyConf BR 2017
@jodosha
jodosha / Gemfile
Last active December 9, 2020 15:09
Full stack Lotus application example
source 'https://rubygems.org'
gem 'rake'
gem 'lotus-router'
gem 'lotus-controller'
gem 'lotus-view'
group :test do
gem 'rspec'
gem 'capybara'
@jswanner
jswanner / migrate.rake
Last active April 1, 2021 22:05
Rolls back migrations in current branch not present in specified branch.
desc 'rolls back migrations in current branch not present in other'
task :rollback_branch_migrations, [:other_branch] do |t, args|
load "#{Dir.pwd}/Rakefile"
branch_migrations = BranchMigrations.new(args.other_branch)
puts ['Rollback the following migrations', branch_migrations, 'y,n? ']
next if %w[no n NO N].include?(STDIN.gets.chomp)
Rake::Task['environment'].invoke
@masonforest
masonforest / gist:4048732
Created November 9, 2012 22:28
Installing a Gem on Heroku from a Private GitHub Repo

Installing a Gem on Heroku from a Private GitHub Repo

Sometimes you want to use a gem on Heroku that is in a private repository on GitHub.

Using git over http you can authenticate to GitHub using basic authentication. However, we don't want to embed usernames and passwords in Gemfiles. Instead, we can use authentication tokens.

  1. Get an OAuth Token from GitHub

First you will need to get an OAuth Token from GitHub using your own username and "note"

@tomstuart
tomstuart / gist:1466504
Created December 12, 2011 10:40
FizzBuzz in the lambda calculus in Ruby
>> IF = -> b { b }
=> #<Proc:0x007fb4e4049cc8 (lambda)>
>> LEFT = -> p { p[-> x { -> y { x } } ] }
=> #<Proc:0x007fb4e403d680 (lambda)>
>> RIGHT = -> p { p[-> x { -> y { y } } ] }
=> #<Proc:0x007fb4e4028ff0 (lambda)>
>> IS_EMPTY = LEFT
@serradura
serradura / mecha_basic.rb
Last active July 31, 2022 11:57
mecha.rb - a minimalist finite state machine implemented using Ruby 3.1 (basic = 34 LOC, enhanced = 53 LOC)
class Mecha
private attr_accessor(:states_map, :callbacks, :transitions, :current_state)
public :transitions, :current_state
def initialize(initial_state:, transitions:)
self.states_map = transitions.parameters.select { |(type, _)| type == :keyreq }.to_h { [_2, _2] }
self.callbacks = Hash.new { |hash, key| hash[key] = [] }
self.transitions = transitions.call(**states_map).transform_values(&:freeze).freeze