Skip to content

Instantly share code, notes, and snippets.

View hernan's full-sized avatar

Hernan Fernandez hernan

  • Argentina
View GitHub Profile

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@hernan
hernan / round_down.rb
Last active December 18, 2015 09:28
round down a float
class Float
def round_down n=0
s = self.to_s
l = s.index('.') + 1 + n
s.length <= l ? self : s[0,l].to_f
end
end
# 2nd variant
class Float
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
@hernan
hernan / change_utf8_signature.rake
Created December 2, 2015 00:11
add utf8 signature to old ruby files
desc "Set the magic encoding comment everywhere to UTF-8"
task :source_encoding do
shebang = '\s*#!.*?(\n|\r\n)'
magic_regex = /\A(#{shebang})?\s*(#\W*(en)?coding:.*?$)/mi
magic_comment = '#-- encoding: UTF-8'
(Dir['script/**/**'] + Dir['**/**{.rb,.rake}']).each do |file_name|
next unless File.file?(file_name)
@hernan
hernan / isempty.js
Created November 14, 2015 15:14
Check for empty object
// http://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object
//ecma 5+
Object.keys({}).length; // 0
// pre ecma 5
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
@hernan
hernan / turbine.rb
Created November 21, 2012 18:55
middleware request observer
require 'active_support/core_ext/hash/conversions'
require 'action_dispatch/http/request'
require 'active_support/core_ext/hash/indifferent_access'
class Turbine
def initialize(app)
@app = app
end
@hernan
hernan / reqUrl.js
Created November 20, 2012 21:20 — forked from wilsonpage/reqUrl.js
A function I made that wraps the node http.request function to make it a little more friendly. In my case I am using it for API route testing.
// module dependencies
var http = require('http'),
url = require('url');
/**
* UrlReq - Wraps the http.request function making it nice for unit testing APIs.
*
* @param {string} reqUrl The required url in any form
* @param {object} options An options object (this is optional)
@hernan
hernan / app.rb
Created May 23, 2012 16:25 — forked from cpatni/app.rb
unique calculation using redis
require 'sinatra'
require 'redis'
require 'json'
require 'date'
class String
def &(str)
result = ''
result.force_encoding("BINARY")
@hernan
hernan / hack.sh
Created March 31, 2012 21:31 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#