Skip to content

Instantly share code, notes, and snippets.

View benzittlau's full-sized avatar

Ben Zittlau benzittlau

View GitHub Profile
/**
* @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 / 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 / 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 / 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 / Add_line_at_matching_line.rb
Created November 27, 2015 19:10
Searches for a certain set of files, and injects the same line into each line at a matching place
def inject_model_fixtures(filepath)
content = File.read(filepath).split("\n")
block_start = content.find_index{|l| l =~ /^RSpec.describe/}
return false if block_start.nil?
content.insert(block_start + 1, " include_context 'model_fixtures'")
File.open(filepath, 'wb') { |file| file.write(content.join("\n")) }
module Net
class HTTP
def request_with_monitor(request, body = nil, &block)
# Continue with the original request
response = request_without_monitor(request, body, &block)
begin
::NetNanny::HttpNetMonitor.output_request_debug_info(self, request)
if ::NetNanny::Registry.instance.registered_address?(self.address)
-- HUMAN RESOURCE MACHINE PROGRAM --
COMMENT 0
a:
COPYFROM 24
COPYTO 20
b:
INBOX
JUMPZ c
COPYTO [20]
@benzittlau
benzittlau / hard_click.js
Created May 29, 2015 21:33
Programatically Accept Suggestions in Google Docs
function hardClick(node) {
triggerMouseEvent (node, "mouseover");
triggerMouseEvent (node, "mousedown");
triggerMouseEvent (node, "mouseup");
triggerMouseEvent (node, "click");
}
function triggerMouseEvent (node, eventType) {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent (eventType, true, true);
@benzittlau
benzittlau / .vimrc.talk
Created November 16, 2014 21:59
Basic .vimrc example
" Highlight searches
set hlsearch
" Case sensitivity
set ignorecase
set smartcase
" Automatic Indenting
set autoindent