Skip to content

Instantly share code, notes, and snippets.

View whitehat101's full-sized avatar

Jeremy whitehat101

View GitHub Profile
def time_to_angle h=0, m=0
puts "hours: #{h*30+m/2}"
puts "mins: #{m*6}"
end
@whitehat101
whitehat101 / factorial.rb
Created June 2, 2016 00:54
Adds :fact to Fixnum
module WhiteHat101
module Factorial
# returns 1 for input < 1
def fact
(1..self).inject 1, :*
end
alias_method :!, :fact
end
end
@whitehat101
whitehat101 / carsar.rb
Created August 22, 2016 22:07
Print all 26 iterations of Carsar's Chiper for a string
# some credit: https://gist.github.com/matugm/db363c7131e6af27716c
# Print all 26 iterations of Carsar's Chiper for a string
def caesar_cipher(string, shift = 1)
alphabet = Array('a'..'z')
non_caps = Hash[alphabet.zip(alphabet.rotate(-shift))]
alphabet = Array('A'..'Z')
caps = Hash[alphabet.zip(alphabet.rotate(-shift))]
@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
@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 / 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 / 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 / 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 / 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 / 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)}%`
})()