Skip to content

Instantly share code, notes, and snippets.

float dbToVolume(float dB)
{
return powf(10.0f, 0.05f * dB);
}
float volumeTodB(float volume)
{
return 20.0f * log10f(volume);
}
@rwrrll
rwrrll / case_sensitive_net_http_headers.rb
Created October 12, 2016 16:28
Monkey patch to prevent Net::HTTP from capitalising header keys on Ruby 2.3
# source: https://github.com/jnunemaker/httparty/issues/406#issuecomment-239542015
module Net::HTTPHeader
def capitalize(name)
name
end
private :capitalize
end
@rwrrll
rwrrll / gist:a37d0ec2858b78a334ac
Created January 25, 2016 15:16
Change Google Apps primary domain (Ruby google-api-client gem)
require 'google/apis/admin_directory_v1'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'fileutils'
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
APPLICATION_NAME = 'Directory API Ruby Quickstart'
CLIENT_SECRETS_PATH = 'client_secret.json'
CREDENTIALS_PATH = File.join(Dir.home, '.credentials', "admin-directory_v1-ruby-quickstart.yaml")
@rwrrll
rwrrll / gist:295cc72a9cb5bc184077
Last active August 29, 2015 14:15
Convert QuickTime screen recordings to lightweight animated GIFs.
#! /bin/bash
# you need ffmpeg and gifsicle installed. they're available via brew on a mac.
# sips will already be installed on your mac.
# you probably want an existence check here, but I'm lazy.
rm out.gif
mkdir pngs
# you can change 450 to your desired output width. the aspect ratio will be preserved.
@rwrrll
rwrrll / logmung.rb
Created October 8, 2014 17:03
Really quick and dirty hack to "parse" Rails log files looking for a request/response pair.
filename = ARGV.first
puts "Opening #{filename}"
file = File.open(filename)
puts "Reading contents"
contents = file.read.encode('UTF-8', invalid: :replace)
puts "Splitting into requests"
requests = contents.split("\n\n\n")
@rwrrll
rwrrll / Preferences.sublime-settings
Last active September 28, 2016 13:27
Preferences.sublime-settings
{
"bold_folder_labels": true,
"color_scheme": "Packages/Oceanic Next Color Scheme/Oceanic Next.tmTheme",
"create_window_at_startup": false,
"draw_white_space": "selection",
"ensure_newline_at_eof_on_save": true,
"fade_fold_buttons": false,
"font_face": "SF Mono Regular",
"font_size": 10.0,
"highlight_line": true,
@rwrrll
rwrrll / gist:9972308
Created April 4, 2014 11:00
Create swap on EBS Instance Storage
# Check for existing swaps:
swapon -s
# None listed? Then go for it!
# Create ~8GB empty file
sudo dd if=/dev/zero of=/mnt/swapfile bs=1M count=8192
# Lock it down
@rwrrll
rwrrll / strong_requirements.rb
Created February 18, 2014 16:36
Kinda hacky way of specifying that permitted parameters must be present in Rails' strong_parameters - use `insist` in place of `permit`.
module ActionController
class Parameters
def insist(*filters)
filters.each { |f| ensure_presence(f) }
permit(filters)
end
private
def ensure_presence(filter, params = self)
case filter
@rwrrll
rwrrll / append_routes.rb
Created October 9, 2013 10:58
Append Rails routes (without losing existing routes)
# spec/support/append_routes.rb
# Basically this: http://experiments.openhood.com/rails/rails%203/2010/07/20/add-routes-at-runtime-rails-3/
# but in a re-usable block format.
def append_routes(&block)
begin
_routes = Rails.application.routes
_routes.disable_clear_and_finalize = true
_routes.clear!
@rwrrll
rwrrll / gist:2421335
Created April 19, 2012 14:33
Patch Rack::Test::UploadedFile to be compatible with ActionDispatch::Http::UploadedFile (avoid "undefined method 'Tempfile'" error)
module Rack
module Test
class UploadedFile
def tempfile
self
end
end
end
end