Skip to content

Instantly share code, notes, and snippets.

View bhollis's full-sized avatar

Ben Hollis bhollis

View GitHub Profile
@bhollis
bhollis / GlowBack.pde
Created June 3, 2011 02:38
Arduino program for animating LEDs for the GlowBack ceramic sculpture
/*
Arduino program for animating LEDs for the GlowBack ceramic sculpture
http://benhollis.net/blog/2010/02/04/glowback-arduino-powered-glowing-ceramic-creature/
Copyright (C) 2010 by Benjamin Hollis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@bhollis
bhollis / simple_cache.rb
Created June 3, 2011 02:43
Simple Rails caching library
# 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,
@bhollis
bhollis / .htaccess
Created March 25, 2012 22:58
Serving pre-gzipped assets from Apache
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
bhollis / deepmv
Created August 31, 2013 03:43
Simple script for moving files to another directory while preserving their folder structure.
#!/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
bhollis / imovie-event
Created September 1, 2013 20:20
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.
#!/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
bhollis / checkerboard.js.coffee
Created November 28, 2013 02:31
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
bhollis / blog.js.coffee
Last active July 17, 2021 08:05
A simple, made-up example of the code for a simple AngularJS blog viewer as a more detailed exploration of http://benhollis.net/blog/2014/01/17/cleanly-declaring-angularjs-services-with-coffeescript/ . 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
bhollis / dedup-imovie-library
Last active February 25, 2021 21:07
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.
#!/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
bhollis / webaudio.js.coffee
Last active September 6, 2022 11:35
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
else
@bhollis
bhollis / README.md
Created May 9, 2015 17:08
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