Skip to content

Instantly share code, notes, and snippets.

@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 / Runfile
Created August 26, 2018 07:30
Ruby UDP Example
require 'socket'
title "UDP Test"
action :server do
s = UDPSocket.new
s.bind(nil, 1234)
5.times do
text, sender = s.recvfrom(16)
puts "received #{text} from #{sender}"
@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
# -*- 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 / 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).

@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:
@DannyBen
DannyBen / Readme
Last active August 29, 2015 14:21
Ruby Filewatcher Interrupt Bug
# See https://github.com/thomasfl/filewatcher/issues/24
$ gem install filewatcher -v0.4.0
$ gem uninstall filewatcher -v0.5.0
$ rvm list
$ ruby -v
$ gem list filewatcher
$ ./test.rb
$ gem install filewatcher
$ gem list filewatcher