Skip to content

Instantly share code, notes, and snippets.

View longlostnick's full-sized avatar

Nick Larson longlostnick

View GitHub Profile
@longlostnick
longlostnick / 0_reuse_code.js
Created March 21, 2014 17:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
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
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
@longlostnick
longlostnick / hashquiz.rb
Last active August 29, 2015 14:24 — forked from potatosalad/hashquiz.rb
Ruby quiz for convert hash "dot paths" into actual hash hierarchy.
#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
@longlostnick
longlostnick / hash_dig.rb
Created July 14, 2015 20:36
"Dig" through hash using dot notation
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
@longlostnick
longlostnick / random_password.rb
Created September 8, 2015 17:22
Safari like random passwords in ruby
BASE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
def random_string(length = 3)
length.times.map { BASE[rand(BASE.length)] }.join
end
puts 4.times.map { random_string }.join('-')
@longlostnick
longlostnick / routes.rb
Created July 13, 2011 18:03 — forked from pixeltrix/routes.rb
Examples of advanced Rails 3.0 routes
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+/
},
@longlostnick
longlostnick / gist:1126226
Created August 4, 2011 20:46
See if each object in an array is in another array of objects
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
@longlostnick
longlostnick / gist:1189032
Created September 2, 2011 16:10
JavaScript verify text inputs as the user types
// 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);
@longlostnick
longlostnick / LICENSE.txt
Created September 29, 2011 22:38 — forked from p01/LICENSE.txt
Sudoku Solver in 140bytes
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