Skip to content

Instantly share code, notes, and snippets.

View thiagoa's full-sized avatar

Thiago Araújo Silva thiagoa

  • thoughtbot
  • Natal / RN - Brazil
View GitHub Profile
thiagoa / gist:ec192babb1d2afc34d70
Last active August 29, 2015 14:11
Address decorator extracted from a project
require 'delegate'
module ConcatHelper
def concat(*elements, separator)
def format(format_string, string)
format_string % string unless string.blank?
defmodule FizzBuzz do
defmacro __using__(_) do
quote do
alias FizzBuzz.FunctionSignaturePatternMatching, as: FSPM
alias FizzBuzz.GuardClause
alias FizzBuzz.Case
alias FizzBuzz.Cond
alias FizzBuzz.If
import FizzBuzz.AnonymousFunction
thiagoa / eql.rb
Last active December 19, 2015 13:42
class Obj
attr_reader :a
def initialize(a)
@a = a
def ==(other)
a == other.a
thiagoa / query_planner.markdown
Created January 3, 2016 02:18 — forked from hgmnz/query_planner.markdown
PostgreSQL query plan and SQL performance notes

Types of index scans


Sequential Scan:

  • Read every row in the table
  • No reading of index. Reading from indexes is also expensive.
thiagoa /
Created February 22, 2016 14:53
Python: My simple ContextManager implementation
import time
class ContextManager():
def __init__(self, generator_method, args, kwargs):
self.generator_method = generator_method
self.args = args
self.kwargs = kwargs
def __enter__(self):
" How to process a set of files (includes escaping file name) and populate the arglist
" This example "copies" everything from quickfix to arglist
command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames()
function! QuickfixFilenames()
let buffer_numbers = {}
for quickfix_item in getqflist()
let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
return join(map(values(buffer_numbers), 'fnameescape(v:val)'))
thiagoa /
Last active May 31, 2016 04:08
Crystal pipe working with module prefixes
# this was copied from
# thanks to @waterlink from this issue thread
module CrChainableMethods
module Pipe
macro pipe(ast)
{% uast = ast.stringify.gsub(/ >>/, ".pipe").id %}
{% pp uast %}
{% if uast.stringify != ast.stringify %}
pipe {{uast}}

Adding Sinon to WebPack

  • Open your project (if you're using WebPack, obviously)

  • npm install sinon --save-dev

  • You should now have Sinon in your node modules and listed in your package.json file

  • In your tests, require Sinon: var sinon = require('sinon');

thiagoa / twitter_timeline_spec.rb
Last active October 10, 2016 15:26
Twitter Widget - First feature test.rb
# spec/features/twitter_timeline_spec.rb
require 'feature_helper'
RSpec.feature 'twitter timeline' do
scenario 'a user views a twitter timeline' do
visit root_path
within '[data-twitter-app]' do
within '[data-tweets]' do
expect(page).to have_css '.tweet', minimum: 2
thiagoa / home_route.rb
Last active October 5, 2016 13:52
Twitter Widget - Home Route
# config/routes.rb
Rails.application.routes.draw do
root to: 'home#index'