Skip to content

Instantly share code, notes, and snippets.

@jfoley
jfoley / cleanup.sh
Created December 16, 2020 21:13
clean up local branches
git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D
@jfoley
jfoley / gist:64e75b0dbac1f70c9434
Last active August 29, 2015 14:25
Tunnel to private webserver via SSH

Given a network where a webserver is behind a firewall but you have ssh access to a jumpbox, this command will tunnel traffic over ssh on the jumpbox.

-L will tunnel traffic from the local machine port 8080 to protected-web-server.com port 80. Add -N to only forward the ports and not send the terminal in to an ssh session on the jumpbox.

ssh jumpbox-user@jumpbox.com -L 8080:protected-web-server.com:80

Even better, setup the jumpbox to be a SOCKS proxy

@jfoley
jfoley / diff.js
Created June 25, 2015 02:19
show a diff in the console. Shows whitespace diffs with background colors.
let Diff = require('diff');
var diff = Diff.diffChars(actualString, expectedString);
diff.forEach(function(part){
// green for additions, red for deletions
// grey for common parts
var color = part.added ? 'bgGreen' :
part.removed ? 'bgRed' : 'grey';
process.stderr.write(part.value[color]);
@jfoley
jfoley / palindrome.rb
Created January 6, 2015 17:55
Recursive palindrome checker
class Palindrome
def self.check(str)
str.gsub!(' ', '')
if str == '' || str.length == 1
true
else
sub_string = str[1..-2]
str[0] == str[-1] && check(sub_string)
@jfoley
jfoley / loops.rb
Created November 11, 2014 21:43
loops!
class TodoApp < CommandLineApp
def initialize(input, output)
@input = input
@output = output
end
def run
running = true
while running
puts "entering first loop"
@jfoley
jfoley / banana_maker_spec.coffee
Created May 18, 2013 16:06
jasmine- javascript vs coffeescript
describe 'BananaMaker', ->
describe '#makeBanana', ->
it 'returns bananas!', ->
bananaMaker = new BananaMaker
expect(bananaMaker.makeBanana()).toEqual('Its bananas!')
describe '#bananaSmoothie', ->
it 'purees some bananas', ->
bananaMaker = new BananaMaker
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
4.1.0.beta
-- create_table(:companies, {:force=>true})
D, [2013-05-04T15:53:21.940407 #17627] DEBUG -- : (0.2ms) CREATE TABLE "companies" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
-> 0.0144s
-- create_table(:departments, {:force=>true})
D, [2013-05-04T15:53:21.941014 #17627] DEBUG -- : (0.1ms) CREATE TABLE "departments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "company_id" integer)
-> 0.0005s
-- create_table(:designers, {:force=>true})
D, [2013-05-04T15:53:21.941456 #17627] DEBUG -- : (0.1ms) CREATE TABLE "designers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
@jfoley
jfoley / game.hs
Created December 10, 2012 19:55
game of life
module GameOfLife where
import Data.List
type Cell = (Int, Int)
type Grid = [Cell]
gridSize = 15
showGrid :: Grid -> String
showGrid cells = unlines $ reverse $ showGrid' gridSize cells
@jfoley
jfoley / gist:3098757
Created July 12, 2012 15:14
Match full_name when you only have first_name and last_name
users_table = User.arel_table
concat_func = Arel::Nodes::NamedFunction.new 'CONCAT', [ users_table[:first_name], ' ', users_table[:last_name] ]
full_name = Arel::SqlLiteral.new('full_name')
query = query.select([users_table[Arel.star], concat_func.as('full_name')]).having(full_name.matches("%#{params[:name]}%"))
@jfoley
jfoley / gist:2639016
Created May 8, 2012 20:28
VIM: Add something to the end of selection of lines
1) V then select lines.
2) <ctrl-v>$A[type what you want to append]