Skip to content

Instantly share code, notes, and snippets.

View benzittlau's full-sized avatar

Ben Zittlau benzittlau

View GitHub Profile
@benzittlau
benzittlau / Remove From Git By Extension
Created May 4, 2011 21:59
Remove all *.swp files from a git repository
git ls-files | grep '\.swp$' | xargs git rm
/**
* @param {NS} ns
*/
export async function main(ns) {
ns.print("Running hacking script...");
var target; securityTreshold; moneyTreshold
// Identify the server to attempt to hack
var target = ns.args[0];
@benzittlau
benzittlau / merge_defaults.rb
Created February 10, 2017 20:16
Merging defaults with options hash in a ruby function
# Related area of style guide: https://github.com/GetJobber/ruby-style-guide#hash-fetch-defaults
# Pros: Is succinct and intuitive
# Cons: Doesn't work for false values
def default_one(options)
options[:foo] ||= 'foo'
options[:bar] ||= 'bar'
end
# Pros: Handles false without issue, is succient
@benzittlau
benzittlau / 4_by_4_tooling.js
Created February 12, 2019 22:31
4 By 4 Skyscrapers Tooling
function solvePuzzle (clues) {
// The hint says the value
// that must *at least* be in the adjacent cell.
// 1 -> 4
// 2 -> 3, etc.
// Calculate the possible permutations for each score in advance
// Rotate around in the order of hints, check if there is only
// one permutation that matches the hint and populated values, if
// so then populate it.
@benzittlau
benzittlau / player.rb
Created March 11, 2017 06:53
Ruby warrior intermediate player implementation (Level 4)
class Player
DIRECTIONS = [:left, :forward, :right, :backward]
def play_turn(warrior)
@warrior = warrior
bind_enemies! ||
attack_enemies! ||
heal! ||
@benzittlau
benzittlau / irbrc.rb
Created March 4, 2013 04:19
Default irbrc in rvm
# This is the common irbrc file used by all rvm ruby installations.
# This file will be overriden every time you update rvm.
# Turn on completion.
begin
require "readline"
require "irb/completion" rescue nil
# Turn on history saving.
@benzittlau
benzittlau / benchmarking.rb
Last active March 26, 2016 18:22
Simple benchmarking util
# Usage:
# $bm = Benchmarking.new
# VisitGeneratorWorker.new.perform(work_order.id)
# $bm.finish
# $bm.results
#
# Inside what you're benchmarking:
# $bm.mark("This is a data point")
#
@benzittlau
benzittlau / gist:6940664
Created October 11, 2013 19:30
Backtrace in PHP
foreach(debug_backtrace() as $trace) {
echo $trace['file'] . "::" . $trace['function'] . "::" . $trace['line'] . "\n";
}
@benzittlau
benzittlau / request.sh
Last active December 16, 2015 09:39 — forked from EricWarnke/request.sh
curl https://api.mover.io/connectors/lOVdV48pmWA7GDmmjkth/collections/DKLsd898sdKj/items \
-X POST \
-H "Authorization: MoverAPI app_id=2tsc0f9n9l4v209oara0mb2j5ur9my8v app_secret=65oow347p1q7d0loj45oje2u3sol99xd" \
-F item=@"my_pic.jpg"
@benzittlau
benzittlau / gist:ec60e41ca2197909b57e
Created August 18, 2014 16:20
Authing for shaw open using command line
curl -L -v --data "username=<username>@shaw.ca&password=<password>&acpt=on&language=en" https://wifisignon.shaw.ca/api/login