Skip to content

Instantly share code, notes, and snippets.

View jhollinger's full-sized avatar

Jordan Hollinger jhollinger

View GitHub Profile
@jhollinger
jhollinger / fax.rb
Last active August 29, 2015 14:17
Fun with Enumerator
require_relative 'libfax'
puts "Sending fax..."
attempts = mock_fax('555-555-5555', "Here's a fax!")
attempts.each_with_index do |status, i|
case status
when :sent
puts "Fax sent!"
break
when :busy
@jhollinger
jhollinger / config.ru
Created November 12, 2014 14:52
Sample Grape/Swagger Cat API
require './main'
run API::Root
@jhollinger
jhollinger / managed_web_socket.js
Last active April 6, 2017 17:01
ManagedWebSocket - WebSocket wrapper to handle auto reconnecting and event re-binding
/*
* ManagedWebSocket is a thin wrapper around WebSocket that handles automatic reconnecting and re-binding.
* If the server/network drops the connection, it will keep trying to reconnect. However, you may call
* "kill" to permanently disconnect on the client side. The native WebSocket object is available as "ws".
*
* Use "on" to bind to normal WebSocket events (open, message, error, close), and to the following custom events:
* - connecting: Fired when it is attempting to connect or reconnect.
* - drop: Fired when the connection has been dropped by the server or network. (fired before "close")
* - kill: Fired when you call "kill" on the MWS. (fired before "close")
*
@jhollinger
jhollinger / rspec_database_cleaner.rb
Created December 21, 2012 05:58
Optimal RSpec Database Cleaner config
Capybara.javascript_driver = :webkit # Selenium works, but not as well
RSpec.configure do |config|
config.use_transactional_fixtures = false
# Use transactions by default
config.before :each do
DatabaseCleaner.strategy = :transaction
end
@jhollinger
jhollinger / thin
Created November 4, 2012 14:51 — forked from sorah/thin
/etc/init.d/thin - thin init script with bundle exec
#!/bin/bash
DAEMON=/usr/local/bin/thin
BUNDLE=/usr/local/bin/bundle
CONFIG_PATH=/etc/thin
SCRIPT_NAME=/etc/init.d/thin
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
invoke()
@jhollinger
jhollinger / clipboard.rb
Created September 30, 2012 16:24
A simple clipboard in Sinatra
require 'sinatra'
CLIPBOARD = ENV['CLIPBOARD'] || '/tmp/www-clipboard'
get '/' do
@data = File.readlines(CLIPBOARD) rescue []
erb :form
end
post '/paste' do
unless params[:data].to_s.empty?
@jhollinger
jhollinger / README.md
Last active July 6, 2023 09:54
rbackup - time-stamped, hard-linked backups powered by rsync

rbackup

rbackup is a lightweight, rsync-powered backup utility that creates time-stamped backups.

Features

It can save backups to your local filesystem (probably an attached USB device) or to a remote host.

Backups are saved in time-stamped directories. Backups are cheap on storage, because hard-links are used for files that haven't changed between backups.

@jhollinger
jhollinger / dropbox.css
Created July 27, 2012 05:27
Dropbox - async, ajax uploads with HTML5 in Sinatra
#dropbox {
position: relative;
}
#dropbox > input {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;