Skip to content

Instantly share code, notes, and snippets.

View RP-3's full-sized avatar

Rohan Rogers RP-3

  • San Francisco Bay Area
View GitHub Profile
@RP-3
RP-3 / gcloud.d.ts
Created July 13, 2017 17:33 — forked from jasonswearingen/gcloud.d.ts
typescript definitions for gcloud datastore, v0.27.0 complete, but not yet tested/verified.
export interface IModuleImport {
(authOptions?: IAuthOptions): IGCloud;
}
export interface IAuthOptions {
projectId?: string;
keyFilename?: string;
}
@RP-3
RP-3 / index.js
Last active August 26, 2017 23:46
Slotted Aloha Efficiency Simulation
/*jshint esversion: 6 */
const ps = [0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4]; // these are the p vals that will be tested
const numHosts = 3; // change this to vary the number of hosts
// change this to vary the maximum number of messages a host might want to send
// unsigned 16-bit int
const maxMessageCount = 10;
// number of times to repeat the simulation for given p, numHosts and maxMessageCount
@RP-3
RP-3 / index.js
Created August 27, 2017 05:03
PCAP Image Parser for Bradfield CS
const fs = require('fs');
const fileName = '01-net.cap';
const targetIPAddress = '192.168.0.101';
const result = {};
let totalBytesRead = 0;
const readRawBytes = (numBytes, fd) =>{
const start = totalBytesRead;
@RP-3
RP-3 / this.js
Created October 3, 2017 23:49
Instantiation patterns and the keyword 'this'.
// functional instatiation
var FunctionalCat = function(name){
var result = {};
result.name = name;
result.sayHi = function(){
console.log(`Meow, my name is ${this.name}, the cat.`);
}
return result;
};
@RP-3
RP-3 / LoggingUIViewController.swift
Created December 7, 2018 04:04
Use this instead of UIViewController to print every lifecycle method of a UIViewController.
import UIKit
class LoggingViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad")
}
override func viewWillAppear(_ animated: Bool) {
@RP-3
RP-3 / Completely Reset XCode
Last active April 6, 2019 03:38
Completely reset Xcode, for when things get nasty
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
# On remote, install and start tinyProxy
# Note: By default, tinyproxy listens on port 8888 and only accepts local connections
sudo apt-get install tinyproxy
# On local,
ssh -L 3128:localhost:8888 -i ~/.ssh/some-private-key.pem ubuntu@your-remote-machine-ip -N
# Then configure your OS's proxy settings to use localhost:3128
# Notes
var minDominoRotations = function(A, B) {
const minRotationsToSetAllTo = (x) => {
let aSame = 0;
let bSame = 0;
for(let i=0; i<A.length; i++){
if(A[i] !== x){
if(B[i] === x) aSame++;
else aSame = Infinity;
}
var numDecodings = function(s) {
const memo = new Array(s.length).fill(null); // for performance
const inner = (i) => {
// base cases
if(i === s.length) return 1; // if we make it to the end, we've completed a valid decoding
if(s[i] === '0') return 0; // no decoding can have a leading 0
if(memo[i] !== null) return memo[i]; // for performance
// 'Pure' recursive
// Note that this is almost literally just writing out the question statement
var uniquePaths = function(m, n) {
// also note this is a pure function: No side effects. No enclosed local vars
// Using an inner function just to keep things tidy and not pass (m, n) everywhere
const traverse = (i, j) => { // i, j are position on board
if(i === m-1 && j === n-1) return 1; // Count the number of ways the robot gets here.
// I.e., every time the robot gets here, return 1.