Skip to content

Instantly share code, notes, and snippets.

View edgar's full-sized avatar

Edgar Gonzalez edgar

View GitHub Profile
@edgar
edgar / pre-commit
Last active November 24, 2022 13:42 — forked from FerPerales/pre-commit.sh
Git: Pre-commit git hook that prevents commits with undesired words, usually debugging statements #git #hook #pre-commit
# This script verifies if a list of "undesired" words are presented in the files you are intended to commit such console
# output, debugging information or keys/tokens/passwords
# Based on the git hook created by Mark Story
# http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes
# Instructions:
# Put this file into your .git/hooks folder and set as executable (chmod +x pre-commit)
@edgar
edgar / post-merge
Last active December 19, 2015 06:29
Git: Post-merge git hook that detects changes on Gemfile and migrations folder, to notify that you should run `bundle install` or `rake db:migrate` #git #hook #post-merge
# This script detects changes on Gemfile and migrations folder
# Instructions:
# Put this file into your .git/hooks folder and set as executable (chmod +x post-merge)
#---------------------------------------------
#!/bin/sh
diff=`git diff --name-only HEAD@{1} HEAD`
from ruby import Linter
CONFIG = {
'language': 'RubyMotion',
'executable': '/Library/RubyMotion/bin/ruby',
'lint_args': '-wc'
}
@edgar
edgar / gist:5630642
Last active December 17, 2015 15:19
Migrate from FasterCSV in ruby 1.8 to CSV in ruby 1.9+
require 'csv'
if CSV.const_defined? :Reader
# Ruby 1.8 compatible
require 'fastercsv'
Object.send(:remove_const, :CSV)
CSV = FasterCSV
else
# CSV is now FasterCSV in ruby 1.9
end
# lvalue slicing of Hashes
# hash = {foo: 1, bar: 2, baz: 3}
# hash[:foo, :bar] == [1, 2]
#
# hash[:foo, 3] = 6,7
# hash == {foo: 6, bar: 2, baz: 3, 3 => 7}
#
# strange enough, I haven't noticed any slowdown on rails startup.
class Hash
alias oldbracket []
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
@edgar
edgar / Sublime Text Shortcuts
Last active December 11, 2015 17:58 — forked from lucasfais/gist:1207002
Sublime Text Shortcuts #sublimetext #sublime
h1. Sublime Text 2 - Useful Shortcuts (Mac OS X)
h2. General
| *⌘T* | go to file |
| *⌘⌃P* | go to project |
| *⌘R* | go to methods |
| *⌃G* | go to line |
| *⌘KB* | toggle side bar |
| *⌘⇧P* | command prompt |
@edgar
edgar / nicerest
Last active December 11, 2015 13:59
nicerest -- pipe your REST API `curl` calls through this for nicer output. Based on http://code.activestate.com/recipes/577549-nicerest-pretty-print-json-output/
#!/usr/bin/env node
//
// nicerest -- pipe your REST API `curl` calls through this for nicer output
//
// $ curl -is http://search.twitter.com/search.json?q=node.js | nicerest
//
var stdin = process.openStdin();
var EventEmitter = require('events').EventEmitter;
@edgar
edgar / rb-magic-comment
Created April 10, 2012 18:48 — forked from kch/rb-magic-comment
Add the encoding magic comment to the ruby files passed as arguments
#!/usr/bin/env ruby
# encoding: UTF-8
ARGV.reject! { |path| !File.file?(path) }
(puts DATA.read.gsub("$0", File.basename($0)); exit 1) if ARGV.empty?
ARGV.each do |path|
ls = IO.readlines(path)
ix = ls[0] !~ /^#!/ ? 0 : 1
next if ls[ix] =~ /#.*?coding\s*[:=]\s*\S/
@edgar
edgar / Ruby.sublime-build
Created October 17, 2011 01:47
SublimeText2 - Check ruby syntax after save file
# Edit file: /path/to/SublimeText2/Packages/Ruby/Ruby.sublime-build
{
"cmd": ["/home/edgar/.rvm/rubies/ruby-1.9.2-p290/bin/ruby", "-cw", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}