Skip to content

Instantly share code, notes, and snippets.

Avatar

Thiago Araújo Silva thiagoa

  • thoughtbot
  • Natal / RN - Brazil
View GitHub Profile
@thiagoa
thiagoa / gist:ec192babb1d2afc34d70
Last active Aug 29, 2015
Address decorator extracted from a project
View gist:ec192babb1d2afc34d70
require 'delegate'
module ConcatHelper
def concat(*elements, separator)
elements.reject(&:blank?).join(separator)
end
def format(format_string, string)
format_string % string unless string.blank?
end
View eql.rb
class Obj
attr_reader :a
def initialize(a)
@a = a
end
def ==(other)
a == other.a
end
@thiagoa
thiagoa / query_planner.markdown
Created Jan 3, 2016 — forked from hgmnz/query_planner.markdown
PostgreSQL query plan and SQL performance notes
View query_planner.markdown

Types of index scans

Indexes

Sequential Scan:

  • Read every row in the table
  • No reading of index. Reading from indexes is also expensive.
@thiagoa
thiagoa / context_manager.py
Created Feb 22, 2016
Python: My simple ContextManager implementation
View context_manager.py
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):
View fizzbuzz.exs
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
View vimscript_examples.vim
" 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'])
endfor
return join(map(values(buffer_numbers), 'fnameescape(v:val)'))
endfunction
@thiagoa
thiagoa / pipe.cr
Last active May 31, 2016
Crystal pipe working with module prefixes
View pipe.cr
# this was copied from https://carc.in/#/r/fg2
# thanks to @waterlink from this issue thread https://github.com/crystal-lang/crystal/issues/1388
module CrChainableMethods
module Pipe
macro pipe(ast)
{% uast = ast.stringify.gsub(/ >>/, ".pipe").id %}
{% pp uast %}
{% if uast.stringify != ast.stringify %}
pipe {{uast}}
View gist:7083d12385e51d8d8b16313667a6220c

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');

View index.html.erb
<!-- app/views/home/index.html.erb -->
<div data-twitter-app>
<div data-tweets>
</div>
</div>
@thiagoa
thiagoa / twitter_timeline_spec.rb
Created Sep 28, 2016
Twitter Widget - Pending feature spec
View twitter_timeline_spec.rb
# spec/features/twitter_timeline_spec.rb
require 'feature_helper'
RSpec.feature 'twitter timeline' do
scenario 'a user views a twitter timeline' do
pending
visit root_path
within '[data-twitter-app]' do