Skip to content

Instantly share code, notes, and snippets.

bhollis / upgrade-v4.diff
Created Dec 29, 2015
Upgrade to Middleman v4
View upgrade-v4.diff
commit d6b0db2c98cfbee1b3738fa042c89cb0b81fb661
Author: Ben Hollis <>
Date: Mon Dec 28 17:50:43 2015 -0800
Upgrade to Middleman v4
diff --git a/Gemfile b/Gemfile
index 88f7592..990881c 100644
--- a/Gemfile
+++ b/Gemfile
bhollis /
Created May 9, 2015
Simple script for copying iCloud Photos / Photostream photos out of the Photos library into a separate folder for import into Lightroom

Copy photos out of Photos App into Lightroom

This is a simple way to get your iCloud Photos / photostream photos out of the Photos app and into Lightroom. Photos get synced from your phone into your Photos library automatically, and this script periodically copies them out into an "import" folder where Lightroom's auto import feature can take over.

To install, copy copy-out-photos into ~/bin and net.benhollis.CopyPhotos.plist into ~/Library/LaunchAgents. Customize copy-out-photos to point to where your Photos library is and where your Lightroom import folder is. Then run these commands:

chmod a+x ~/bin/copy-out-photos
launchctl load ~/Library/LaunchAgents/net.benhollis.CopyPhotos.plist
bhollis /
Last active Jul 29, 2020
A simple interface for playing raw audio samples via the Web Audio API. Meant to mimic the API from dynamicaudio.js.
# The WebAudio object can be used to write raw stereo sound samples.
# It has one property, "supported" which returns whether the Web Audio API
# is supported, and one method, "writeStereo" which will play sound samples.
class WebAudio
constructor: ->
if window.AudioContext? || window.webKitAudioContext?
@context = new (window.AudioContext ? window.webKitAudioContext)
@supported = true
bhollis / dedup-imovie-library
Last active Feb 25, 2021
When you import movies into iMovie 10 libraries, the file is always copied, wasting space and hindering editability. This script replaces the copy with a hardlink, reclaiming disk space.
View dedup-imovie-library
#!/usr/bin/env ruby
# Usage: dedup-imovie-library LIBRARY ORIGINALS
# Goes through an iMovie 10 library and replaces all the "Original Media" with
# hardlinks to the actual original media, in order to conserve disk space. Note
# that because they're hardlinks, if you copy the originals and the iMovie event
# to a new disk, you'll end up with two copies again and will have to re-run this
# tool.
bhollis /
Last active Jun 4, 2020
A simple, made-up example of the code for a simple AngularJS blog viewer as a more detailed exploration of . Yes, I know about `$resource`, but I prefer not to use it.
app = angular.module 'BlogExample', []
# Simple controller that loads all blog posts
app.controller 'BlogCtrl', ['$scope', 'Blog', ($scope, Blog) ->
# Get all the blog posts
Blog.all().then (posts) ->
$scope.posts = posts
# Extend the $scope with our own properties, all in one big block
# I like this because it looks like declaring a class.
bhollis /
Created Nov 28, 2013
Three.js snippet for creating a checkerboard plane. Good for use as a floor in demos.
# Build a checkerboard colored square plane with "segments" number of tiles per side.
# Using three.js v62
checkerboard = (segments=8) ->
geometry = new THREE.PlaneGeometry(100, 100, segments, segments)
materialEven = new THREE.MeshBasicMaterial(color: 0xccccfc)
materialOdd = new THREE.MeshBasicMaterial(color: 0x444464)
materials = [materialEven, materialOdd]
for x in [0...segments]
for y in [0...segments]
bhollis / imovie-event
Created Sep 1, 2013
I hate how iMovie wants to move your files into its own directory structure, which is slow and wasteful. This script creates iMovie events as hardlinks to my own directory structure. Hardlinks are requires so that iMovie will let you mark favorites/rejected.
View imovie-event
#!/usr/bin/env ruby
# Usage: imovie-event SRC [EVENT NAME]
# Creates an iMovie event for all the .MOV files at "SRC".
# For me, the iMovie Events folder and some other rules are hardcoded.
require 'fileutils'
bhollis / deepmv
Created Aug 31, 2013
Simple script for moving files to another directory while preserving their folder structure.
View deepmv
#!/usr/bin/env ruby
# Usage: deepmv '**/*.rb' ../other
# Moves files under the current directory matching a glob
# to another directory, preserving directory structure.
require 'fileutils'
glob = ARGV.shift
bhollis / .htaccess
Created Mar 25, 2012
Serving pre-gzipped assets from Apache
View .htaccess
AddEncoding gzip .gz
RewriteEngine on
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Konqueror
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)\.css$ $1.css.gz [QSA,L]
RewriteRule ^(.*)\.js$ $1.js.gz [QSA,L]
RewriteRule ^(.*)\.html$ $1.html.gz [QSA,L]
bhollis / simple_cache.rb
Created Jun 3, 2011
Simple Rails caching library
View simple_cache.rb
# A simple expiring cache suitable for use with the :file_store cache store.
# Not particularly threadsafe, and can duplicate work if there are multiple
# requests for stale data at the same time.
# Usage:
# SimpleCache.fetch('my_data', 15.minutes) do
# MyModel.expensive_query
# end
# Make sure to set up the cache to use :file store in your environment.rb,