Skip to content

Instantly share code, notes, and snippets.

View guiferrpereira's full-sized avatar
💻

Guilherme Pereira guiferrpereira

💻
View GitHub Profile
I'd start fresh with rvm:
sudo rvm implode
\curl -L https://get.rvm.io | bash -s stable
Make sure homebrew is installed:
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
Install libyaml, universally
@guiferrpereira
guiferrpereira / gist:5547088
Created May 9, 2013 12:09
em-synchrony vs typhoeus
require 'em-synchrony'
require 'em-synchrony/em-http'
require 'em-synchrony/iterator'
require 'typhoeus'
require 'benchmark'
(1..5000).each do urls << "http://example.com" end
puts "EM::Synchrony:\n\n"
@guiferrpereira
guiferrpereira / gist:5698918
Last active December 18, 2015 00:48
Capybara with phantomjs
require 'capybara'
require 'capybara/poltergeist'
# Capybara configuration
Capybara.run_server = false
Capybara.javascript_driver = :poltergeist
Capybara.default_wait_time = 10
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, { :phantomjs_options => ['--ignore-ssl-errors=yes'] })
@guiferrpereira
guiferrpereira / gist:5699259
Created June 3, 2013 16:12
RABL with cucumber
# step_definitions
filepath = File.dirname(__FILE__) + "/../../templates/"
Rabl.render(false, "test.json", :view_path => filepath, :format => :json)
# test.json.rabl
object false
node(:RequestId) { "<cool>" }
@guiferrpereira
guiferrpereira / gist:6634813
Last active December 23, 2015 12:19
Highcharts generate image from chart
# To use this you will need:
# lazy_high_charts gem (I used version 1.4.3) - https://github.com/michelson/lazy_high_charts
# phantomJS installed on your machine - http://phantomjs.org/
# Responsible for convertion LazyHighChart object into image
# Receives LazyHighChart Object
def render_chart(high_chart, image_format="png", options = {})
options = options.select {|key, value| RENDER_OPTIONS.include?(key.to_s) }
begin
# First we will create file that contains json properties from our chart
(function(global) {
var silpUrl = '//s3-eu-west-1.amazonaws.com/silp.shootitlive.com/js/silp.min.js';
// Globals
if(!global.Silp) { global.Silp = {}; };
var Silp = global.Silp;
// To keep track of which embeds we have already processed
if(!Silp.foundEls) Silp.foundEls = [];
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
@guiferrpereira
guiferrpereira / gist:a818ae6fbae4eb8c0563
Created January 8, 2015 18:26
PeixotosGo Redis Keys PFFFF
package main
import garyredis "github.com/garyburd/redigo/redis"
import "fmt"
var pool garyredis.Pool
func PooledGet(key string) (string, error) {
conn := pool.Get()
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@guiferrpereira
guiferrpereira / get_title_from_http_page.sh
Created April 15, 2016 18:02
Get all events from some page and return titles
#!/usr/bin/env bash
wget=/usr/bin/wget
for i in `seq 9000 12000`
do
echo "$i"
cool="https://results.chronotrack.com/event/results/event/event-$i"
wget -qO- $cool | perl -l -0777 -ne 'print $1 if /<title.*?>\s*(.*?)\s*<\/title/si'
done