Skip to content

Instantly share code, notes, and snippets.

View whitehat101's full-sized avatar

Jeremy whitehat101

View GitHub Profile
@whitehat101
whitehat101 / main.php
Created March 25, 2015 05:54
SQL Benchmarks with PHP / Ruckusing Migrations
<?php
class MicroQuery
{
public static function configure($configuration)
{
// configure ruckusing db adapter
self::$adapter = null;
}
@whitehat101
whitehat101 / client.js.coffee
Last active August 29, 2015 14:20
Basic debugging callbacks for HTML Service Workers
console.log navigator.serviceWorker.controller
navigator.serviceWorker.register('/worker.js') #, scope: 'path'
.then (reg) ->
console.log '◕‿◕', reg
, (err) ->
console.log 'ಠ_ಠ', err
# credit: https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/post-message/index.html
@sendMessage = (message) ->
@whitehat101
whitehat101 / control.lua
Created September 17, 2015 07:50
Rewrite of factorio mod turrets-range 1.1.1
require "defines"
global.active_turret_range_entities = {}
global.nearby_turret_map = {}
local function draw_turret_range(turret_type, sx, sy, r)
-- what is this voodoo?
local function round(x)
return x + 0.5 - (x + 0.5) % 1
end
@whitehat101
whitehat101 / mean.rb
Last active May 2, 2016 18:31
Add :mean to Arrays
module WhiteHat101
module Mean
def mean
inject(0.0, :+) / length
end
alias avg mean
alias average mean
def mean_absolute_deviation
mean = self.mean
@whitehat101
whitehat101 / circle.rb
Created March 12, 2016 00:43
A Ruby Circle Class
module WhiteHat101
class Circle
attr_accessor :origin, :radius
def initialize origin = [0,0], radius = 0
@origin = origin
@radius = radius
end
def self.origin_point origin, point
radius = Math.sqrt origin.zip(point)
.map {|a,b| (a - b)**2 }
@whitehat101
whitehat101 / vector_2d.rb
Last active April 13, 2016 00:08
Vector2D
class Vector2D
include Math
attr_accessor :x, :y
def self.magnitude_angle magnitude, angle
x = magnitude * cos(angle*PI/180)
y = magnitude * sin(angle*PI/180)
new x, y
end
def initialize x, y
@x = x; @y = y
RealStdOut = $stdout
# Replace the main thread's $stdout and $stderr with IO.pipes
# Create a thread to watch for data on the pipes
# call given block with IO name, timestamp, and data read from IO
def redirect_stdout_and_stderr_to &callback
rout, $stdout = IO.pipe
rerr, $stderr = IO.pipe
map = { rout => 'stdout', rerr => 'stderr' }
include Process
# puts " ROOT: #{pid} of #{ppid}"
# at_exit { puts " EXIT: #{pid} of #{ppid}" }
$running = true
$workers = []
def start_worker
$workers << fork do
Signal.trap "INT", "DEFAULT"
@whitehat101
whitehat101 / ws_channels.rb
Created May 20, 2016 23:30
Simple WebSocket Channel Managment
require 'set'
class SingleChannel
def initialize id
@id = id
@sockets = Set.new
end
def push ws
@sockets << ws
end
@whitehat101
whitehat101 / wordlist.rb
Created May 31, 2016 00:59
Ubuntu Word list Iteration
# Wordlist on most Ubuntu Installs
open '/usr/share/dict/american-english' do |list|
until list.eof?
word = list.gets.chomp
next unless word.match /^[A-Za-z]+$/
value = word.upcase.split(//).inject(1) do |sum,v|
sum *= v.ord - 'A'.ord + 1
end
# puts "#{word} = #{value}"