Skip to content

Instantly share code, notes, and snippets.

@slant
slant / bluetooth.sh
Created September 20, 2016 22:42
Improving bluetooth audio quality on OS X (both incoming and outgoing)
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Max (editable)" 80;
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" 43;
defaults write com.apple.BluetoothAudioAgent "Apple Initial Bitpool (editable)" 80;
defaults write com.apple.BluetoothAudioAgent "Apple Initial Bitpool Min (editable)" 43;
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool" 80;
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Max" 80;
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Min" 43;
@slant
slant / redate.sh
Last active August 26, 2016 06:49
Redate image files with original exif data
# Set the date of picture files to the EXIF date
function redate () {
# Replace spaces in filenames with underscores
echo "Removing spaces..."
for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done
# Get orginal date from EXIF data and update file's metadata dates
# Required: http://www.sno.phy.queensu.ca/~phil/exiftool/
echo "Redating..."
find -E . -type f -iregex '.*\.(jpg|nef)' | while read PIC; do
@slant
slant / db.rake
Created September 11, 2015 22:58
Single-line rake task to rebuild a database from migrations (instead of schema.db)
namespace :db do
desc "Drop and recreate the database with migrations and seeds"
task :rebuild => [:drop, :create, :migrate, :seed]
end
@slant
slant / something.rb
Created May 22, 2015 21:08
Chaining methods in Ruby
class Something
attr_accessor :thing
def initialize
self.thing = []
end
def one
# by returning self on the last line of a method, that method will then
# allow another method to be called immediately after it since the next

Keybase proof

I hereby claim:

  • I am slant on github.
  • I am slant (https://keybase.io/slant) on keybase.
  • I have a public key whose fingerprint is 69D7 0FF6 1943 1F56 3842 5F40 EDFB 7859 68B5 B015

To claim this, I am signing this object:

@slant
slant / thing.rb
Created January 6, 2014 19:46
Experimenting with metaprogramming in Ruby.
class Thing
def self.format_answer_for(question_title, &block)
define_method("__format_answer_for_#{question_title}", &block)
end
end
#################
## Test Case 1 ##
#################
<!doctype html>
<html>
<head>
<style type="text/css">
body, html {
font-family: helvetica;
}
p:before {
@slant
slant / hue.rb
Last active December 28, 2015 20:29
Do random things to a set of Philips Hue bulbs.
require 'rubygems'
require 'hue'
class Data
class << self
def random_state
{ bri: self.random_bri, hue: self.random_hue, sat: self.random_sat }
end
def random_bri
@slant
slant / fb.js
Last active December 19, 2015 02:08
Bookmarklet to auto-accept Facebook group requests.
javascript:var buttons=document.getElementsByClassName('uiButtonText');var add_buttons=new Array;for(var b=0;b<buttons.length;b++){if(buttons[b].innerText=='Add'){add_buttons.push(buttons[b])}};for(var b=0;b<add_buttons.length;b++){add_buttons[b].click()};
@slant
slant / helper.rb
Last active December 17, 2015 08:29
Dynamic route generation in Rails
# Without the extra stuff
# Helper
class Helper
def edit_resource_link(text, resource, &block)
#if CanCan blah blah
content_tag(:a, text, send(:"edit_#{resource.class.name.downcase}_path", resource), &block)
#end
end
end