Skip to content

Instantly share code, notes, and snippets.

@headquarters
headquarters / calculate_bmi.rb
Last active August 29, 2015 14:04
Calculate BMI in Ruby. Weight and height are both coerced to floats to prevent integer division.
def calculate_bmi(weight_in_pounds, height_in_inches)
return ((weight_in_pounds.to_f/height_in_inches.to_f**2) * 703)
end
@headquarters
headquarters / delete-caches
Created October 15, 2014 05:21
Free up "miscellaneous used space" on Mac OS X
Boot file system in single user mode: hold down Command-S immediately after the startup tone.
Make the file system read-write: /sbin/mount -uw /
Delete the contents of three directories:
rm -rf /Library/Caches/*
rm -rf /System/Library/Caches/*
rm -rf /Users/<username>/Library/Caches/*
Be very careful about the rm -rf command!
@headquarters
headquarters / masonry.js
Last active August 29, 2015 14:11
Reflow items on different screen sizes.
var REFLOW = (function(window, $){
var self = {};
var nth;
var itemsAfterFirstRow;
var allItems = $('#items .col');
self.init = function(){
self.adjustHeights();
@headquarters
headquarters / fetch-plos.org-article-data.rb
Last active August 29, 2015 14:20
Collect article data from the Plos.org API
# This script uses the Plos.org API to collect article data.
# Necessary libraries
require 'csv'
require 'work_queue'
require 'rest-client'
# The file name for the CSV file that will be READ
CSV_FILENAME = "9_10_2014-Cumulative-Report-With-Subject-Area-and-Article-Type.csv"
# The file name for the CSV file that will be WRITTEN
CSV_OUTPUT_FILENAME = "9_10_2014-Cumulative-Report-With-ALM-Data.csv"
@headquarters
headquarters / scrape-plos.org-article-data.rb
Created May 6, 2015 16:02
Scrape data from Plos.org articles.
# This script scrapes the PlosOne.org website to extract data for articles. At the time, this data was not available in the API.
# Necessary libraries
require 'CSV'
require 'nokogiri'
require 'open-uri'
require 'work_queue'
require 'benchmark'
CSV_FILENAME = "9_10_2014-Cumulative-Report.csv"
@headquarters
headquarters / tab-click-profiling
Created May 27, 2015 16:16
Profile tab click times
jQuery(document.body).on("mouseup", function(){ console.time("Tab showing") });
jQuery(".nav-tabs li:nth-child(1)").on("mouseup", function(){ console.timeEnd("Tab showing"); })
var target = document.querySelector(".nav-tabs li:nth-child(2)");
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.timeEnd("Tab showing");
});
});
@headquarters
headquarters / SassMeister-input-HTML.html
Last active August 29, 2015 14:27
Generated by SassMeister.com.
<a href="#nogo" class="button--PRIMARY">Primary Button</a>
<br />
<a href="#nogo" class="button--SECONDARY">Secondary button</a>
@headquarters
headquarters / amazon-wishlist-total.js
Last active April 9, 2016 02:08
Get the total of all the items in an Amazon Wishlist. May not work for non-Prime items.
var prices = document.querySelectorAll('[class*="color-price a-text-bold"]');
prices = Array.prototype.slice.call(prices);
var total = 0;
prices.forEach(function (price) {
total += parseFloat(price.textContent.replace('$', ''));
});
alert(total);
/**
* Diff Java resource bundles to find missing keys.
*/
var fs = require('fs');
var englishFile = 'path/to/ResourceBundleMessage.properties';
var germanFile = 'path/to/ResourceBundleMessage_de.properties';
var japaneseFile = 'path/to/ResourceBundleMessage_ja.properties';
var chineseFile = 'path/to/ResourceBundleMessage_zh_CN.properties';
@headquarters
headquarters / .bash_profile
Last active July 25, 2019 01:59
Sample .bash_profile for macOS
# Aliases
alias editprofile="nano ~/.bash_profile"
alias loadprofile="source ~/.bash_profile"
alias flushdns="sudo discovery udnsflushcaches"
alias pythonserver="python -m SimpleHTTPServer 8000"
alias mochatest="mocha test/setup.js --compilers js:babel-core/register --require ignore-styles "
alias setprod="export NODE_ENV=production"
alias setdev="unset NODE_ENV"
alias checkenv="echo \$NODE_ENV"
alias disableipv6="networksetup -setv6off Wi-Fi"