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
@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
@shadowmaru
shadowmaru / slides.md
Last active November 26, 2020 07:17
Palestras da RubyConf BR 2017
@notozeki
notozeki / Makefile
Last active March 22, 2023 16:27
An example Ruby extension written in Crystal
CRYSTAL = crystal
UNAME = "$(shell uname -ms)"
LIBRARY_PATH = $(shell brew --prefix crystal-lang)/embedded/lib
LIBS = -levent -lpcl -lpcre -lgc -lpthread
LDFLAGS = -Wl,-undefined,dynamic_lookup
TARGET = crystal_example_ext.bundle
$(TARGET): crystal_example_ext.o
$(CC) -bundle -L$(LIBRARY_PATH) -o $@ $^ $(LIBS) $(LDFLAGS)
@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.
@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'
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active November 11, 2024 22:46
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@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}'
# 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
@schickling
schickling / Rakefile
Last active November 5, 2024 09:14
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@drogus
drogus / Rakefile.rb
Created July 26, 2013 10:49
This is the example contents of the Rakefile, which you would use to run active record tasks without using Rails. It assumes using the same directories as rails uses: `db/migrate`, `config/database.yml`.
require 'bundler/setup'
require 'active_record'
include ActiveRecord::Tasks
db_dir = File.expand_path('../db', __FILE__)
config_dir = File.expand_path('../config', __FILE__)
DatabaseTasks.env = ENV['ENV'] || 'development'