Skip to content

Instantly share code, notes, and snippets.

View blackhole.rb
#! /usr/bin/ruby
require 'fileutils'
path = "/etc/hosts"
sites = %w(
news.ycombinator.com
reddit.com
www.reddit.com
@ScotterC
ScotterC / gist:b738721015de6c56573f
Created Nov 4, 2015
Basic vagrant error output
View gist:b738721015de6c56573f
~/vagrant-setup (master): vagrant plugin install vagrant-hostsupdater
Installing the 'vagrant-hostsupdater' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:
An error occurred while installing json (1.8.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
@ScotterC
ScotterC / pre-push.sh
Created Sep 2, 2015
Git Hook PrePush protection for force pushing
View pre-push.sh
#!/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
# 1. git config --global init.templatedir '~/.git-templates'
# 2. mkdir -p ~/.git-templates/hooks
View Clean remote branches
#!/usr/bin/env bash
for branch in `git checkout --quiet master && git branch -r --merged | grep origin/ | sed 's/origin\///' | sed '1d;$d' | grep --invert-match master`; do echo -e `git push origin --delete $branch` \\t$branch; done
View pre-push.sh
#!/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
# 1. git config --global init.templatedir '~/.git-templates'
# 2. mkdir -p ~/.git-templates/hooks
@ScotterC
ScotterC / bas
Created Jan 14, 2015
Git branch in command line
View bas
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="\[\033[0m\]\w\[\033[34m\] \$(parse_git_branch)\[\033[01;36m\]:\[\033[00m\] "
@ScotterC
ScotterC / gist:8826026
Created Feb 5, 2014
Find the largest prime factor of a number
View gist:8826026
def largest_prime_factor(number)
factors = factors_of(number)
factors.select do |f|
is_prime?(f)
end.max
end
def factors_of(number)
@ScotterC
ScotterC / gist:7604440
Last active Dec 29, 2015
Unicorn initialization script
View gist:7604440
#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/x/my_app/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
@ScotterC
ScotterC / gist:7234355
Last active Dec 26, 2015
StartupInstitude
View gist:7234355
class Me
def name
@name
end
def name=(name)
@name = name
end