Skip to content

Instantly share code, notes, and snippets.

View edgar's full-sized avatar

Edgar Gonzalez edgar

View GitHub Profile
@edgar
edgar / array_indeof.js
Created January 21, 2014 18:20
In IE8 arrays don't have the method indexOf defined. Implementation taken from MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf Other source could be: http://ecma262-5.com/ELS5_HTML.htm#Section_15.4.4.14
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
}
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
fromIndex = +fromIndex || 0;
if (Math.abs(fromIndex) === Infinity) {
fromIndex = 0;
}
@edgar
edgar / pry_console
Created February 6, 2014 17:20
Rails 2.3.* console using Pry
#!/usr/bin/env ruby
console = File.expand_path(File.dirname(__FILE__), '.') + "/script/console"
exec console, *ARGV, '--irb=pry'
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@edgar
edgar / gist:9900527
Created March 31, 2014 19:41
keybase.md
### Keybase proof
I hereby claim:
* I am edgar on github.
* I am edgar (https://keybase.io/edgar) on keybase.
* I have a public key whose fingerprint is 45A6 D897 81CD ABBC A678 8C57 4599 5010 176C F6BF
To claim this, I am signing this object:
@edgar
edgar / .pryrc
Created June 17, 2014 17:54
.pryrc file to customize Pry
Pry.config.editor = 'subl3 -n -w'
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
def unbundled_require(gem)
loaded = false
if defined?(::Bundler)
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
@edgar
edgar / ruby_gc.sh
Last active August 29, 2015 14:23 — forked from mikhailov/ruby_gc.sh
- http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/
- http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration
article’s settings: ("spec spec" took 17-23!sec)
export RUBY_HEAP_MIN_SLOTS=1250000
export RUBY_HEAP_SLOTS_INCREMENT=100000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=30000000
export RUBY_HEAP_FREE_MIN=12500
@edgar
edgar / polycorn.md
Last active August 29, 2015 14:26 — forked from octplane/polycorn.md
Life and Death of Unicorns The introduction of our Unicorn management tool, Polycorn. This gists contains the original article about Polycorn plus the source code of Polycorn.

Life and death of Unicorns

The introduction of our Unicorn management tool, Polycorn.

jump into our train!

Photo by Protohiro from Flickr

At Fotopedia, we use Unicorn to serve our main Rails application. Every day, we restart our application several times, spawning and killing hundred of Unicorns. Managing graceful restarts is a complex task, and requires careful monitoring and command. This article introduces our tool Polycorn, a Unicorn management program.

[[MORE]]

@edgar
edgar / cpu.rb
Created October 23, 2015 19:47 — forked from jimweirich/cpu.rb
Can people run this script and see if it gives accurate count of CPUs on their system. Report results in the comments please. Thanks! Oh! And don't forget to report what kind of system you are running this on (linux, windows, mac, etc.). UPDATE: Revised version that uses the Java runtime if running under JRuby.
require 'rbconfig'
# Based on a script at:
# http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed
class CpuCounter
def self.count
new.count
end
def count
class HashSubclass < Hash
def foo
self.reject {|k,v| k[:foo]}
end
end
obj = HashSubclass.new
new_obj = obj.foo
new_obj.class