Skip to content

Instantly share code, notes, and snippets.

@headquarters
headquarters / .htaccess
Created October 6, 2017 20:21
Webfaction http->https and www redirect rules
# webapps/michaelehead_redirect/.htaccess
# michaelehead_redirect
# | - http://michaelehead.com
# | - http://www.michaelehead.com
# This simply redirects all traffic to https://www (with or without www) to the app itself at “michaelehead”.
# That app’s redirect rules then take care of the www portion.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ https://www.michaelehead.com/$1 [R=301,L]
@headquarters
headquarters / css-to-js.js
Created September 21, 2017 21:37
Convert CSS files to JS with postcss and postcss-js
const fs = require('fs');
const postcss = require('postcss');
const postcssJs = require('postcss-js');
// e.g. body { font-size: 14px } h1 { font-size: 21px; }
const cssFile = fs.readFileSync('./path/to/file.css');
const css = postcss.parse(cssFile.toString());
const cssJsObject = postcssJs.objectify(css);
// e.g. module.exports = { body: { fontSize: "14px" }, h1: { fontSize: "21px" };
@headquarters
headquarters / count-prs.js
Created July 27, 2017 19:06
Count pull requests by contributor in BitBucket
/**
* Run in the console on a MERGED PR page: https://bitbucket.org/<org>/<project>/pull-requests/?state=MERGED
*/
var names = {};
for(var node of document.querySelectorAll('.pr-number-and-timestamp')){
var text = node.innerHTML
var info = text.split(' - ');
var name = info[0];
if(names[name]) {
@headquarters
headquarters / commands.sh
Last active May 25, 2025 18:39
Linux/macOS Commands and Tips
# Find things listening on ports on Mac
lsof -n -i4TCP:$PORT | grep LISTEN
# Find a process PID
ps ax | grep ruby
# ...and kill it
kill -9 <PID>
# Alternatively, kill all of them with a name
pkill node
@headquarters
headquarters / ruby-snippets.rb
Created January 16, 2017 15:12
Ruby code snippets
#!/usr/bin/ruby
# shebang (#!) must on the first line of the script in order to run this
# with `./script.rb` rather than `ruby script.rb`
# use `whereis ruby` to find the path
# single line comments
=begin
Multi-line comments.
Begin and End must be on the first
@headquarters
headquarters / dynamic-regular-expression.js
Created January 11, 2017 00:33
Dynamic regular expression example
var item = 'abcdefghijkl';
var term = 'bfg';
var termArray = term.split('');
// start regex with 0 or more character match
var regex = '.*';
for(var i = 0; i < termArray.length; i++) {
// add character term to regex string
regex += termArray[i];
@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"
/**
* 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 / 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);
@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>