Skip to content

Instantly share code, notes, and snippets.

View rafaelp's full-sized avatar

Rafael Lima rafaelp

View GitHub Profile
@rafaelp
rafaelp / snippets
Last active August 29, 2015 14:18
Chamada para snippets pro Graffiti da HE:labs
Vamos colocar alguns snippets de código no Graffiti da HE:labs
https://www.dropcam.com/p/helabs
Sugira o seu que ele pode entrar na parede, mas tem que ser até final do dia 31 de março (terça)!!
Pode ser qualquer linguagem.
Ex:
while working{
coffee++;
}
@rafaelp
rafaelp / gist:0fa400f8cefec64834c1
Created October 10, 2014 13:19
Exemplo de colorização
Exemplo de `tag` no github
```ruby
codigo = Ruby.new(:param1,:param2)
# comentario
```
```bash
$ export TOKEN=meutoken
$ ls -al
@rafaelp
rafaelp / take-iphone-simulator-screenshot.sh
Created December 1, 2013 21:15
Script to screenshot the iPhone Simulator to the correct size
#!/bin/sh
# script to screenshot the iPhone Simulator to the correct size
# to upload to iTunes Connect
# written by Jehiah Czebotar http://jehiah.cz/
OUTPUTDIR=~/Desktop
TEMPFILE=iPhoneSimulatorScreenshot_`date +%Y%m%d_%H%M%S`.png
echo "output filename:\c"
@rafaelp
rafaelp / swap-usage.sh
Created December 1, 2013 21:14
Show swap usage
#!/bin/sh
free -m | grep Swap | while read output;
do
swap=$(echo $output | awk '{print $2}' )
used=$(echo $output | awk '{ print $3 }' )
freed=$(echo $output | awk '{ print $4 }' )
echo "Swap : $swap"
echo "Used : $used"
echo "Free : $freed"
usep=`expr $used \* 100 / $swap`
@rafaelp
rafaelp / bank_billet.rb
Last active December 20, 2015 00:59
DRAFT WORK! Wrapper for BankBillet model on Cobre Gratis API: https://github.com/BielSystems/cobregratis-api/blob/master/resources/bank_billets.md
class BankBillet
include HTTParty
include Virtus
base_uri 'https://app.cobregratis.com.br'
attribute :id, Integer
attribute :name, String
attribute :amount, Float
attribute :expire_at, Date
attribute :external_link, String
@rafaelp
rafaelp / deferred_garbage_collection.rb
Created January 15, 2013 13:54
Speed up Rspec suite
# Joe Van Dyk discovered that running the Ruby garbage collector only every X seconds can speed up your tests.
# I found that deferring garbage collection would speed up my RSpec examples by about 15%,
# but it probably depends on the nature of your tests.
# https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection
class DeferredGarbageCollection
RESERVED_IVARS = %w(@loaded_fixtures)
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 10.0).to_f
@@last_gc_run = Time.now
def self.start
@rafaelp
rafaelp / find_unused_images.rake
Last active October 21, 2022 22:18
Rake task to find unused images on Rails project to deletion.
# It requires ACK - http://betterthangrep.com/
task :find_unused_images do
images = Dir.glob('app/assets/images/**/*')
images_to_delete = []
images.each do |image|
unless File.directory?(image)
# print "\nChecking #{image}..."
print "."
result = `ack -1 -G '(app|public)' --ruby --html --css --js #{File.basename(image)}`
# -*- encoding : utf-8 -*-
require "spec_helper"
describe Notification do
describe "new_question" do
let(:user) { Factory.create(:user, name: 'Dart Vader', email: 'dart@example.com') }
let(:category) { Factory.create(:category, name: 'Saúde') }
let(:owner) { Factory.create(:user, name: 'Jaspion') }
let(:question) { Factory.create(:question, user: owner, category: category) }
let(:mailer) { Notification.new_question(question.id, user.id) }
module AWS
module Core
class LogFormatter
# @param [Object] value
# @return [String]
def summarize_value value
case value
when String then summarize_string(value)
when Hash then '{' + summarize_hash(value) + '}'
when Array then summarize_array(value)
@rafaelp
rafaelp / gist:2884599
Created June 6, 2012 20:37
Rake stats do projeto websimulado feito no Startup DEV
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 130 | 117 | 13 | 20 | 1 | 3 |
| Helpers | 44 | 41 | 0 | 8 | 0 | 3 |
| Models | 241 | 218 | 9 | 31 | 3 | 5 |
| Libraries | 15 | 13 | 0 | 1 | 0 | 11 |
| Model specs | 696 | 676 | 0 | 0 | 0 | 0 |
| Controller specs | 455 | 430 | 0 | 6 | 0 | 69 |
| Helper specs | 126 | 121 | 1 | 0 | 0 | 0 |