Skip to content

Instantly share code, notes, and snippets.

View whitehat101's full-sized avatar

Jeremy whitehat101

View GitHub Profile
@whitehat101
whitehat101 / addEventListeners.coffee
Created April 19, 2017 21:16
jQuery-ish multiple-event addEventListener in CoffeeScript
addEventListeners = (elem, events, callback) ->
events.split(' ').forEach (event) ->
elem.addEventListener event, callback, false
@whitehat101
whitehat101 / norm_time.rb
Last active April 10, 2017 01:39
Normalize a flow of timestamps into ones suitable for charting
# HH:17:30 ... HH:27:30 => HH:20:00
def norm_time t
i = t.to_i
i /= 300.0
i = i.round # round to nearest 5 minutes
i /= 2 # floor to nearest 10 minutes
Time.at i*600
end
s = Time.now
@whitehat101
whitehat101 / ruby 2.3.4 configure --help
Created April 7, 2017 15:48
ruby 2.3.4 configure --help
$ ./configure --help
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
@whitehat101
whitehat101 / localStorage-usage.js
Last active March 28, 2017 16:19
Measure HTML5 localStorage (in MB)
(function(chars, index) {
for (chars = index = 0; index < localStorage.length; index++ )
chars += localStorage.getItem(localStorage.key(index)).length
return `${(chars/1024/1024).toPrecision(5)} MB ≈${(chars/5/1024/1024*100).toPrecision(3)}%`
})()
@whitehat101
whitehat101 / 1.8.7-p352-on-sierra.md
Created December 8, 2016 02:19
Installing 1.8.7-p352 on macOS Sierra 10.11 with openssl

Installing 1.8.7-p352 on macOS Sierra 10.11 with openssl

See https://github.com/rbenv/ruby-build/wiki

Assuming rbenv and ruby-build already setup

brew install openssl libyaml libffi readline
# required for building Ruby <= 1.9.3-p0:
brew tap homebrew/dupes &amp;&amp; brew install apple-gcc42
@whitehat101
whitehat101 / collect_host_keys.bash
Last active December 3, 2016 06:16
Collect all of a SSH server's host keys
#!/bin/bash
#
# !!! This function will attempt DOZENS of ssh connections !!!
# try not to scare your sysadmins
#
function collect_host_keys {
ukhf=$(mktemp)
keys=""
@whitehat101
whitehat101 / apache_vhost.conf
Last active December 2, 2016 01:00
Acme-http01 with Apache
# mod_rewrite method
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule /\.well-known/acme-challenge/(.+) http://example.com/cert-central/$1 [R=301,L]
</IfModule>
# mod_alias method
<IfModule mod_alias.c>
Alias "/.well-known/acme-challenge" "/var/acme-challenge"
<Directory "/var/acme-challenge">
@whitehat101
whitehat101 / puma.god
Created November 22, 2016 06:18
God configuration with CPU & memory monitoring and email notifications
# Thanks: https://github.com/dotgee/geoauth/blob/78e859b2d4ca5cd5788aeb3c3a64f2ccc92202dc/config/puma.god
ROOT = "/var/www/app/rails/development/geoauth"
God.pid_file_directory = "#{ROOT}/tmp/pids"
# rails_env = ENV['RAILS_ENV'] || 'production'
rails_env = ENV['RAILS_ENV'] || 'development'
rails_root = ENV['RAILS_ROOT'] || ROOT
@whitehat101
whitehat101 / set_ModifierMapping.sh
Last active September 3, 2017 10:24
Attempt to update ModifierMapping via Command Line
#!/bin/bash
#
# WARNING
#
# This script does not "work". It does correctly upate the preferences (good syntax).
# However, those settings are not reloaded until the user logs in again.
# They do NOT apply to the current session, and I haven't been able to find anything that
# can reload these values, other than AppleScript (with Accessability) simulating user input
# to the System Preferences application.
#
@whitehat101
whitehat101 / base.py
Last active August 31, 2016 01:29
Base N to Base M conversions (using Numeric arrays, not an extended alphabet)
"""
Port the to_base/from_base functions from Ruby to Python
"""
from __future__ import division
def __to_base_notation(value, base):
result = []
while value > 0 or not len(result):
part = value % base
value = (value - part) / base