Skip to content

Instantly share code, notes, and snippets.

@goncalossilva
goncalossilva / .githookspre-commit
Created May 1, 2012 16:08
Don't commit conflicts
#!/usr/bin/env ruby
`git diff-index --name-status HEAD`.split("\n").each do
|status_with_filename|
status, filename = status_with_filename.split(/\s+/)
next if status == 'D'
File.open(filename) do |file|
while line = file.gets
if line.include?("<<<<<<<") || line.include?(">>>>>>>")
puts "ERROR: #{filename} has unresolved conflicts"
class Ability
include CanCan::Ability
def initialize(user)
can :create, Comment, :post => { :published => true }
end
end
@goncalossilva
goncalossilva / pre-commit
Created August 25, 2011 15:34
Default pre-commit hook in git
#!/bin/sh
echo "Peter Van Rooijen, explaining the Law of Demeter:
• You can play with yourself
• You can play with your own toys (but you can’t take them apart)
• You can play with toys that were given to you
• And you can play with toys you’ve made yourself\n"
[user]
name = Gonçalo Silva
email = goncalossilva@gmail.com
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
@goncalossilva
goncalossilva / gist:1115856
Created July 30, 2011 18:58
Codebits talk proposals rank
require 'rubygems'
require 'json'
require 'net/http'
require 'statistics2'
# from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
def ci_lower_bound(pos, n, power)
return 0 if n == 0
z = Statistics2.pnormaldist(1-power/2)
phat = 1.0*pos/n
From 5e048a2952661a975814b3f89c679c22f5b702ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gon=C3=A7alo=20Silva?= <goncalossilva@gmail.com>
Date: Thu, 24 Mar 2011 21:29:02 +0000
Subject: [PATCH] measure object allocations when rb_gc_malloc_allocations is available
---
ext/ruby_prof/measure_allocations.h | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/ext/ruby_prof/measure_allocations.h b/ext/ruby_prof/measure_allocations.h
rbx-head :037 > lb = Rubinius::Agent.loopback
=> #<Rubinius::Agent:0x1884 @decoder=#<BERT::Decode:0x1888 @in=#<IO:0x188c> @peeked=""> @io=#<IO:0x188c> @encoder=#<BERT::Encode:0x1894 @out=#<IO:0x188c>>>
rbx-head :038 > lb.get("system.memory.counter.bytes").last # this is memory
=> 45022024
rbx-head :040 > lb.get("system.memory.counter.objects").last # this is the amount of object allocations
=> 1367753
rbx-head :041 > lb.get("system.gc.full.count").last + lb.get("system.gc.young.count").last # this is the amount of gc runs
=> 13
rbx-head :042 > lb.get("system.gc.full.wallclock").last + lb.get("system.gc.young.wallclock").last # and the amount of time spent gcing
=> 217
# wtf
Psych::ScalarScanner.new.tokenize("2011-02-24 11:17:06 -0800")
=> 2011-03-29 20:17:06 +0100
# this date format is important because of git
(19:43) goncalossilva ~/Desktop/rails[master] $ git show -s --pretty=format:"%ci" 13547c16d97b5f52db11d9f48704bbea20b54a4c
2011-02-24 11:17:06 -0800
class Array
def trollface
puts <<-EOTF
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
From 53f2f7aef15c89f60a6a75b2b55cd124600d0c23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gon=C3=A7alo=20Silva?= <goncalossilva@gmail.com>
Date: Mon, 3 Jan 2011 18:51:57 +0000
Subject: [PATCH] use clock_gettime() instead of clock() when measuring process time under Linux
clock() limits it to centisecond precision on Linux
---
ext/ruby_prof/measure_process_time.h | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)