This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The challenge here is to try and implement TypeScript that can handle a set of different operations | |
// defined in objects that are internally consistent in their type requirements. By this I mean that | |
// each object has a consistent interface except that the types are different object to object. The | |
// interface is of a consistent type, but has constraints, such as the return type of one function | |
// being the argument for another function. I then want to be able to have generic code that is | |
// able to "execute" each of these type specific objects while being type safe and not throwing | |
// type errors. | |
// | |
// The primary issue is that TypeScript infers the types to be a union type, for example String | Number, | |
// and consequently throws a type error. The structure doesn't allow it to understand that in each |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
DIRECTIONS = [:left, :forward, :right, :backward] | |
def play_turn(warrior) | |
@warrior = warrior | |
bind_enemies! || | |
attack_enemies! || | |
heal! || |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- HUMAN RESOURCE MACHINE PROGRAM -- | |
COMMENT 0 | |
a: | |
COPYFROM 24 | |
COPYTO 20 | |
b: | |
INBOX | |
JUMPZ c | |
COPYTO [20] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
NewerOlder