Skip to content

Instantly share code, notes, and snippets.

View jrunning's full-sized avatar

Jordan Running jrunning

View GitHub Profile
@jrunning
jrunning / server.rb
Created June 30, 2014 18:10
Instant Ruby CGI server
#!/usr/bin/env ruby
require "webrick"
server = WEBrick::HTTPServer.new(Port: 8080, DocumentRoot: Dir::pwd)
trap("INT") { server.shutdown }
server.start
@jrunning
jrunning / fun_with_to_proc.rb
Last active August 29, 2015 14:07
Fun with to_proc
class Regexp
def to_proc
proc {|str| match(str) && $~.to_s }
end
end
arr = [ "foo", "bar 123", "baz", "456", "789 qux" ]
p arr.find(&/bar/) # => "bar 123"
@jrunning
jrunning / get-your-shit-together-protip-2014.md
Last active January 2, 2016 12:29
My Very Best Get-Your-Shit-Together Protip For 2014

My Very Best Get-Your-Shit-Together Protip For 2014

TL;DR

Take pictures of your important documents (driver's license, passport, birth certificate, etc.) and store them securely with an app that will sync to your computers and mobile devices.

Do this now

# https://minhajuddin.com/2016/03/03/put-this-in-your-code-to-debug-anything
require 'rouge'
require 'method_source'
require 'pp'
class Dbg
def initialize(object, to:)
@object, @stream = object, to
end
@bterlson
bterlson / mod.js
Last active January 26, 2017 15:25
Module export forms have subtle differences
// exporter1.js
let foo = 1;
export { foo as default }; // exports the foo binding
foo = 2;
// exporter2.js
let foo = 1;
export default foo; // creates a new binding named *default* and initializes it to 1.
foo = 2; // assigns to the foo binding which is not exported
@fredrick
fredrick / App-example-test.js
Last active April 6, 2018 12:39
React Router Test Context Helper
var React = require('react/addons'),
TestUtils = React.addons.TestUtils,
TestContext = require('./TestContext'),
App = require('./App.jsx'),
app = TestContext.getRouterComponent(App);
describe('App', function() {
it('has something', function() {
expect(app.getDOMNode().textContent).toContain('something');
});
@nukemberg
nukemberg / knife.sh
Created June 28, 2011 07:51 — forked from ches/knife
bash completion for Chef's knife command (updated for 0.10)
# vim: ft=sh:ts=4:sw=4:autoindent:expandtab:
# Author: Avishai Ish-Shalom <avishai@fewbytes.com>
# We need to specify GNU sed for OS X, BSDs, etc.
if [[ "$(uname -s)" == "Darwin" ]]; then
SED=gsed
else
SED=sed
fi
@itspriddle
itspriddle / setup-git-bundler-merge-driver
Last active August 13, 2018 08:41
This script makes git automatically run `bundle install` when a merge conflict with Gemfile.lock occurs. Run it once per project to setup `.gitattributes` and `.gitconfig`
#!/usr/bin/env bash
# Usage: setup-git-bundler-merge-driver
# Help: Configures git to use a custom merge driver to resolve Gemfile.lock
# merge conflicts.
if [ ! -f Gemfile ]; then
echo 'No `Gemfile` found! Aborting'
exit 1
fi
-- Apple Script to connect VPN Client with Password and Safenet MobilePass OTP.
set vpn_name to "'VPN Connection 01'"
set user_name to "username"
set passwd to "Password"
tell application "MobilePASS"
activate
end tell
tell application "System Events"
@sporkd
sporkd / question.rb
Created February 15, 2012 23:33
Using arel matches_any
class Question < ActiveRecord::Base
# UGLY
def self.starts_with(*strings)
# Big loop to build something like this...
where("wording LIKE ? OR wording LIKE ? OR wording LIKE ?", 'blah%', 'blaah%', 'blaaah%')
end
# PURDY
def self.starts_with(*strings)
strings = strings.map { |s| s+'%' }