Skip to content

Instantly share code, notes, and snippets.

View guilherme's full-sized avatar
🤔

Guilherme Campos guilherme

🤔
View GitHub Profile
@guilherme
guilherme / gist:4121922
Created November 20, 2012 23:14
thOOughtz #1
# "O que é mais interessante? Adicionar callbacks(ActiveRecord like) ou criar uma classe encapsulando o comportamento 'extra' desejado."
# "What is more interesting? Add callbacks(ActiveRecord like) or create a class that encapsulate the desired 'extra' behavior."
class B
before :method, :before_method
...
before :method, :before_methodN
after :method, :after_method
...
after :method, :after_methodN
@guilherme
guilherme / money.rb
Created October 1, 2012 23:13
money monkey patch
module ActiveRecord
class Base
def self.money_attributes(*attrs)
(attrs || []).each do |attr|
attr = attr.to_s
define_method attr do
read_attribute(attr).tap do |value|
value = value.to_money if value
end
end
@guilherme
guilherme / pthread_mutex.c
Created September 26, 2012 23:51
pthread_mutex
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
void funcao1(int *id);
void funcao2(int *id);
@guilherme
guilherme / gist:3131788
Created July 17, 2012 20:18
color terminal
# ~/.bash_profile
export CLICOLOR=1
export LSCOLORS=gxfxcxdxbxegedabagacad
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ →\ \1/'
}
export PS1='\[\e[1;37m\][\[\e[1;35m\]\u\[\e[1;37m\]@\[\e[1;32m\]\h\[\e[1;37m\]:\[\e[1;36m\]\w\[\e[1;31m\]$(parse_git_branch)\[\e[1;37m\]]$ \[\e[0m\]'
@guilherme
guilherme / arquivo.js
Created July 6, 2012 03:15
arquivo alvo do test do sed
before debug
// debug-start
var x = 'hello'
console.log(x);
// debug-end
after debug
@guilherme
guilherme / inheritance_complex.rb
Created July 3, 2012 15:00
ar: reflections inheritance more complex test case
require 'active_record'
class ReferencedModelA < ActiveRecord::Base; end
class ReferencedModelB < ActiveRecord::Base; end
class ReferencedModelC < ActiveRecord::Base; end
class ModelA < ActiveRecord::Base
has_many :referenced_model_a
end
@guilherme
guilherme / inheritance.rb
Created July 3, 2012 14:42
ar: reflections inheritance
require 'active_record'
class ModelA < ActiveRecord::Base
end
class SubModelA < ModelA
end
p SubModelA.reflections.keys
var events = 'click change focus'.split(' '), // add more as needed
eLen = events.length,
eI = 0,
els = document.getElementsByTagName('*'),
len = els.length,
i = 0,
el;
var debug_mode = 1;
g(x) h(x) f(x)
2 8 3 4 11 0
1 6 4 4 11 0
7 0 5 4 11 0
g(x) h(x) f(x)
2 8 3 5 8 13
1 0 4 5 8 13
7 6 5 5 8 13
g(x) h(x) f(x)
2 0 3 6 10 16
// Table.h
class Table {
private:
int h;
int g;
std::vector< std::vector<int> > pecas;
int _delta_l_c(int l_ini, int c_ini, int l_fim, int c_fim);
Table* parent;
public: