Skip to content

Instantly share code, notes, and snippets.

View ErvalhouS's full-sized avatar
🔥
This is fine

Fernando H. E. Bellincanta ErvalhouS

🔥
This is fine
View GitHub Profile
@ErvalhouS
ErvalhouS / sinesp.py
Created January 27, 2017 06:50
Getting SINESP Python API to work with Ruby
from sinesp_client import SinespClient
import sys
sc = SinespClient()
result = sc.search(sys.argv[1])
print result
@ErvalhouS
ErvalhouS / throttle_test.rb
Created February 21, 2017 13:34
Throttling script for testing server capacity
require 'httpclient'
c = HTTPClient.new
a=0
loop do
c.get_async("http://target.com")
p a
a += 1
a = 0 if a == 10000
end
@ErvalhouS
ErvalhouS / latest.rake
Created March 14, 2017 09:50
Get latest Heroku database state, dump and apply on localhost Postgres
namespace :latest do
desc "rake 'latest:db' Get last state from the production database"
task db: :environment do
Rake::Task["db:drop"].execute
Rake::Task["db:create"].execute
system( "heroku pg:backups:capture --app <YOUR APP NAME>" )
system( "curl -o latest.dump `heroku pg:backups public-url`" )
system( "pg_restore --verbose --clean --no-acl --no-owner -d <YOUR DEVELOPMENT DATABSE NAME> latest.dump" )
Rake::Task["db:migrate"].execute
end
@ErvalhouS
ErvalhouS / script.sh
Last active August 28, 2017 22:50
Adding new script line to files contained in folder after regex match
#!/bin/bash
FILES=/path/to/folder/*
for file in $FILES
do
sed -i "/my-complex-regexp-finder/a content-to-add" $file
done
@ErvalhouS
ErvalhouS / consolis.rb
Created September 21, 2017 14:32
Initializer to add some helpers into ruby console
module Consolis
def parse_xls(opts={})
opts[:file] = "output" unless opts[:file].present?
opts[:headers] = ["Important", "Data"] unless opts[:headers].present?
opts[:data] = [["foo","bar"]] unless opts[:data].present?
File.open(opts[:file]+".xls", "w+") do |f|
f.write("<meta charset='utf-8'><table border=yes width=100%>")
opts[:size] = 1 unless opts[:size].present?
f.write("<tr>")
opts[:headers].map do |header|
while true; do
heroku logs --tail >> /tmp/<appname>.log
echo disconnect >> /tmp/<appname>.log
done
@ErvalhouS
ErvalhouS / comma_separator.rb
Last active February 15, 2018 23:38
This one line def will separate the string by commas, unless the commas are inside simple OR double quotes using only Ruby's `split` and regexp
module CommaSeparator
def separate params
params.split(/(?!\B\b('|")[^\"']*),(?![^\"']*('|")\B\b)/)
end
end
@ErvalhouS
ErvalhouS / download_file.js
Created February 17, 2018 03:01
A JS to download a file given only a link, which can be used to "proxy" requests using javascript response https://stackoverflow.com/a/48837289/3399504
//IMPLEMENT THIS PART BELOW
// Source: http://pixelscommander.com/en/javascript/javascript-file-download-ignore-content-type/
window.downloadFile = function (sUrl) {
//iOS devices do not support downloading. We have to inform user about this.
if (/(iP)/g.test(navigator.userAgent)) {
//alert('Your device does not support files downloading. Please try again in desktop browser.');
window.open(sUrl, '_blank');
return false;
@ErvalhouS
ErvalhouS / .hyper.js
Created March 1, 2018 21:07
My hyper config
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// Choose either "stable" for receiving highly polished,
// or "canary" for less polished but more frequent updates
updateChannel: 'stable',
@ErvalhouS
ErvalhouS / select2+turbolinks.js
Created March 30, 2018 17:33
A great way to handle Select2 page transitions within Turbolinks