Skip to content

Instantly share code, notes, and snippets.

View brodock's full-sized avatar

Gabriel Mazetto brodock

View GitHub Profile
@brodock
brodock / queue_select.rb
Created October 14, 2015 19:59 — forked from djellemah/queue_multiplex.rb
blocking Queue.select in Ruby
require 'thwait'
# Synchronous hand-off between two threads.
# Both threads will block until a transfer is successful.
class Rendevous
def initialize
@mutex = Mutex.new
@send_flag = ConditionVariable.new
@recv_flag = ConditionVariable.new
@container = []
@brodock
brodock / deep_struct.rb
Last active January 26, 2017 02:01 — forked from anonymous/recursive hash to struct
json to struct
require 'ostruct'
class JsonStruct < OpenStruct
def initialize(hash = nil)
@table = {}
@hash_table = {}
return unless hash
hash.each do |k, v|
recursive_initializer(v) if v.is_a?(Array)
@brodock
brodock / money_attribute.rb
Last active October 15, 2015 12:33
Money Attributes
module Financeiro
# Inclui suporte para escrever em um campo com valor monetário
# utilizando BigDecimal, ou valor em string seguindo sintaxe
# do jQuery MoneyMask
#
# Para habilitar em um model é preciso primeiro fazer um include no model:
# include MoneyAttribute
#
# Defina cada um dos campos que você quer que tenham o comportamento:
@brodock
brodock / metaprogramming.rb
Created January 14, 2015 18:06
metaprogramming example
def x(&block)
"alguma coisa".tap &block
puts "outra coisa"
end
x { |obj| puts "METAPROGRAMMING: #{obj.inspect}" }
# METAPROGRAMMING: "alguma coisa"
# outra coisa
# => nil
@brodock
brodock / slides.md
Created October 10, 2014 06:19
Moodlemoot Brasil Keynote

Integração de aplicações externas usando LTI e Webservices.

Gabriel Mazetto

UFSC / UNASUS


Motivação


@brodock
brodock / logrotate_rails_application
Last active August 29, 2015 14:04
Silver Bullet Nginx Vhost Recipe for Rails application with HTTPS + Webp + Capistrano + Linux FHS
# This file should be placed at /etc/logrotate.d/
/srv/*/shared/log/*.log {
daily
missingok
dateext
rotate 30 # amount of days to keep compressed logs (you should backup it up externally)
compress
delaycompress
notifempty
@brodock
brodock / passenger4_ruby_production.sh
Last active August 29, 2015 13:57
Production setup with passenger 4 + Ruby (from brightbox, for ubuntu server)
echo "Acrescentando suporte para add-apt-repository"
sudo apt-get install -ym software-properties-common python-software-properties apt-transport-https
echo "Adicionando repositórios externos"
sudo add-apt-repository ppa:brightbox/ruby-ng-experimental
# chave pgp do repositório da phusion
gpg --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
gpg --armor --export 561F9B9CAC40B2F7 | sudo apt-key add -
@brodock
brodock / rails-essentials.sh
Last active August 29, 2015 13:57
ZSH + RVM + Ruby 2.0.0 installation script (This is all you need to develop Ruby on Ubuntu)
#!/bin/bash
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo update-ca-certificates
echo "Instalação de bibliotecas essenciais..."
sudo apt-get install -y git build-essential vim curl
echo "Instalação do MySQL (cliente e servidor) e bibliotecas para compilar gems..."
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
@brodock
brodock / zurb-chosen.css.scss
Last active August 29, 2015 13:57
This is Chosen stylesheet to use with ZURB Framework 5 (it expects to have @import "foundation" before this file is imported)
@import "chosen";
.chosen-container {
font-size: inherit;
margin-bottom: $form-spacing;
.chosen-single div {
background: none;
border-left: none;
position: absolute;
brew install htop -v
==> Downloading https://github.com/max-horvath/htop-osx/archive/0.8.2.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/htop-osx-0.8.2.2.tar.gz
==> Verifying htop-osx-0.8.2.2.tar.gz checksum
tar xf /Library/Caches/Homebrew/htop-osx-0.8.2.2.tar.gz
==> ./autogen.sh
glibtoolize: putting auxiliary files in `.'.
glibtoolize: copying file `./ltmain.sh'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
glibtoolize: copying file `m4/libtool.m4'