Skip to content

Instantly share code, notes, and snippets.

@DannyBen
DannyBen / stub.bash
Created December 9, 2019 13:19 — forked from jimeh/stub.bash
Shell script helpers to stub and restore bash shell functions/commands in tests.
# Stub commands printing it's name and arguments to STDOUT or STDERR.
stub() {
local cmd="$1"
if [ "$2" == "STDERR" ]; then local redirect=" 1>&2"; fi
if [[ "$(type "$cmd" | head -1)" == *"is a function" ]]; then
local source="$(type "$cmd" | tail -n +2)"
source="${source/$cmd/original_${cmd}}"
eval "$source"
fi
@DannyBen
DannyBen / Ruby Benchmark Helper.md
Last active September 20, 2019 09:34
Ruby Benchmark Helper

Ruby Benchmark Helper

Usage

require './bm'

bm = BM.new

bm.add(:sleep_long) { sleep 0.1 }
@DannyBen
DannyBen / config.ru
Last active May 7, 2019 18:51
Minimal Server for Request Header Debugging
# Usage:
# $ rackup -p3000
# $ curl localhost:3000
require 'rack'
require 'yaml'
run proc { |env| [200, {'Content-Type' => 'text/html'}, [env.select { |key| key.include?('HTTP_') }.to_yaml ] ] }
@DannyBen
DannyBen / spec_helper.rb
Last active February 15, 2018 21:40 — forked from nu7hatch/spec_helper.rb
Testing standard input with RSpec
module Helpers
# Replace standard input with faked one StringIO.
def stdin_send(*args)
begin
$stdin = StringIO.new
$stdin.puts(args.shift) until args.empty?
$stdin.rewind
yield
ensure
$stdin = STDIN
@DannyBen
DannyBen / ChromeRefreshOnFocus
Created July 19, 2015 10:51
Refresh Chrome whenever it receives focus
; Chrome Refresh On Focus
; Refresh Chrome whenever it receives focus
#SingleInstance force
#Persistent
Gosub WaitForChrome
Return
WaitForChrome:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
forward_port = ->(guest, host = guest) do
config.vm.network :forwarded_port,
guest: guest,
host: host,
auto_correct: true
end
@DannyBen
DannyBen / ssx
Last active February 25, 2016 09:13
Run a ruby or shell script remotely
# Run a ruby or shell script remotely
#
# Install:
# - Put the file in your home directory
# - Source it from your .bashrc:
# if [ -f $HOME/ssx ]; then source $HOME/ssx; fi
ssx() {
show_usage() {
echo "Run a ruby or shell script remotely"
@DannyBen
DannyBen / UnityWebPlayer
Last active December 24, 2015 15:49
Dropbox compatible HTML for showing Unity Player
<doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity Web Player</title>
</head>
<body>
<embed type="application/vnd.unity" width="960" height="640" tabindex="0" firstframecallback="unityObject.firstFrameCallback();" src="WebBuild.unity3d" style="display: block; width: 100%; height: 100%;">
<div style="text-align:center">
@DannyBen
DannyBen / apache_bench.sh
Created October 10, 2015 17:49 — forked from seyhunak/apache_bench.sh
Rails - Apache Bench - Load Testing (if Devise Sign-in Required)
1.
LOGIN_PAGE=http://localhost/users/sign_in
curl --cookie-jar cookie_file $LOGIN_PAGE | grep csrf-token
2.
<meta content="csrf-token" name="csrf-token" />
@DannyBen
DannyBen / gh-pages-deploy.md
Last active August 29, 2015 14:25 — forked from cobyism/gh-pages-deploy.md
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).