Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔

Guilherme Campos guilherme

🤔
View GitHub Profile
View gist:96d1e41a1fcada6f006435672686e1b9
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 Nov 24, 2015
run the specs of differences between master and current branch
View diffspec.sh
#!/bin/bash
git log --name-only master..HEAD | grep 'spec/' | grep -v 'factories' | grep -v 'spec_helper' | paste -s -d " " - | xargs spring rspec
View 0-readme.md

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 Aug 5, 2022
Git pre-commit hook that detects if the developer forget to remove all the javascript console.log before commit.
View gist:9604324
#!/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
View es.sh
# 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
View interchangeable_view.js
// 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 Feb 1, 2013
load up the rails environment on a script
View gist:4690921
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __FILE__)
View update_subclass_type.rb
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)
View gist:4529531
# 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
View gist:4136536
echo "Ativando: IP FORWARDING"
echo
echo "1" > /proc/sys/net/ipv4/ip_forward
##################
### PREROUTING ###