Skip to content

Instantly share code, notes, and snippets.

Nick Larson ifightcrime

Block or report user

Report or block ifightcrime

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ifightcrime
ifightcrime / 0_reuse_code.js
Created Mar 21, 2014
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View unicorn.rb
worker_processes 4
timeout 20
preload_app true
listen ENV['PORT'].to_i, backlog: 10
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
View wercker-nodejs-default.yml
box: wercker/nodejs
# Build definition
build:
# The steps that will be executed on build
steps:
# A step that executes `npm install` command
- npm-install
# A step that executes `npm test` command
- npm-test
@ifightcrime
ifightcrime / hashquiz.rb
Last active Aug 29, 2015 — forked from potatosalad/hashquiz.rb
Ruby quiz for convert hash "dot paths" into actual hash hierarchy.
View hashquiz.rb
#require 'rubygems'
require 'pp'
#require 'ap' # Awesome Print
class Object
# expects [ [ symbol, *args ], ... ]
def recursive_send(*args)
args.inject(self) { |obj, m| obj.send(m.shift, *m) }
end
end
@ifightcrime
ifightcrime / hash_dig.rb
Created Jul 14, 2015
"Dig" through hash using dot notation
View hash_dig.rb
class Hash
def dig(dotted_path)
parts = dotted_path.split '.', 2
first_part = parts[0]
match = self[first_part] || self[first_part.to_sym]
if !parts[1] || match.nil?
return match
else
return match.dig(parts[1])
end
@ifightcrime
ifightcrime / random_password.rb
Created Sep 8, 2015
Safari like random passwords in ruby
View random_password.rb
BASE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
def random_string(length = 3)
length.times.map { BASE[rand(BASE.length)] }.join
end
puts 4.times.map { random_string }.join('-')
@ifightcrime
ifightcrime / routes.rb
Created Jul 13, 2011 — forked from pixeltrix/routes.rb
Examples of advanced Rails 3.0 routes
View routes.rb
Rails.application.routes.draw do
get '/(:locale)/products/(:category)/(page/:page).:extension',
:to => 'products#index',
:as => :products,
:constraints => {
:locale => /[a-z]{2}/,
:category => /.+?/,
:page => /\d+/
},
@ifightcrime
ifightcrime / gist:1126226
Created Aug 4, 2011
See if each object in an array is in another array of objects
View gist:1126226
my_objects.each do |my_object|
if my_other_objects.any?{|my_other_object| my_other_object.Name == my_object.name}
# do something if we found one
end
end
@ifightcrime
ifightcrime / gist:1189032
Created Sep 2, 2011
JavaScript verify text inputs as the user types
View gist:1189032
// used to verify characters and prevent incorrect input as the user is typing.
// TODO: detect special characters like period/comma/?/etc. in the first regexp
// USAGE: use the keydown event: "return dynamicVerify(e, '[0-9a-zA-Z]');"
// e = event, re = regexp for allowed characters, ce = regexp for allowed key codes
function dynamicVerify(e, re, ke) {
var key = e.keyCode || e.which;
var keychar = String.fromCharCode(key);
var rexp = new RegExp(re);
var kexp = new RegExp(ke);
@ifightcrime
ifightcrime / LICENSE.txt
Created Sep 29, 2011 — forked from p01/LICENSE.txt
Sudoku Solver in 140bytes
View LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mathieu 'p01' Henri <http://www.p01.org/releases/>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
You can’t perform that action at this time.