Skip to content

Instantly share code, notes, and snippets.

View guilherme's full-sized avatar
🤔

Guilherme Campos guilherme

🤔
View GitHub Profile
require 'cityhash'
keywords = (0..4).to_a.inject(('a'..'z').to_a) do |perms, t|
perms = ('a'..'z').to_a.product(perms)
end.collect(&:join)
mod2_zero = 0
mod2_one = 0
keywords.each { |k| (CityHash.hash32(k) % 2) == 0 ? (mod2_zero += 1) : (mod2_one += 1) }
puts mod2_zero
puts mod2_one
@guilherme
guilherme / diffspec.sh
Last active November 24, 2015 19:14
run the specs of differences between master and current branch
#!/bin/bash
git log --name-only master..HEAD | grep 'spec/' | grep -v 'factories' | grep -v 'spec_helper' | paste -s -d " " - | xargs spring rspec

Ruby 1.9.3-p194 with DTrace probes, Perf Patches, and backported COW-friendly GC

Overview

This script installs a patched version of ruby 1.9.3-p194 with DTrace probes, boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Many thanks to funny-falcon for the performance patches and to Aaron Patterson for the DTrace instrumentation.

@guilherme
guilherme / gist:9604324
Last active February 24, 2024 20:39
Git pre-commit hook that detects if the developer forget to remove all the javascript console.log before commit.
#!/bin/sh
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
consoleregexp='console.log'
# CHECK
if test $(git diff --cached | grep $consoleregexp | wc -l) != 0
then
# INSTALACAO DO ELASTIC SEARCH MAIS NOVO
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
wget hhttps://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.3.deb
sudo dpkg -i elasticsearch-0.90.3.deb
sudo service elasticsearch start
// Example usage:
// MyCompositeView = Backbone.Marionette.CompositeView.extend({
// template: '#template',
// itemView: Namespace.InterchangeableView,
// itemViewOptions: function(model, index) {
// return { showView: myShowView,
// editView: myEditView,
// model: model
// };
// },
@guilherme
guilherme / gist:4690921
Created February 1, 2013 12:01
load up the rails environment on a script
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __FILE__)
class A < ActiveRecord::Base
def update_attributes_changing_type(attrs)
object = if attrs.keys.include?('type') || attrs.keys.include?(:type)
self.becomes((attrs['type'] || attrs[:type]).constantize)
else
self
end
object.class.instance_variable_set('@finder_needs_type_condition', :false)
object.update_attributes(attrs)
object.class.instance_variable_set('@finder_needs_type_condition', nil)
# vamos supor:
def convert_to_f(argument = nil)
argument.tap do |attribute|
attribute = attribute.to_f if attribute
end
end
convert_to_f
# esperado: nil
# obtido: nil
@guilherme
guilherme / gist:4136536
Created November 23, 2012 17:19
Exemplo de NAT
echo "Ativando: IP FORWARDING"
echo
echo "1" > /proc/sys/net/ipv4/ip_forward
##################
### PREROUTING ###