Skip to content

Instantly share code, notes, and snippets.

View AJamesPhillips's full-sized avatar

Alexander James Phillips AJamesPhillips

View GitHub Profile
@AJamesPhillips
AJamesPhillips / logger.js
Last active February 4, 2019 13:19
fake logger for tests
const LOG_LEVELS = {
DEBUG: 1000,
INFO: 2000,
WARN: 3000,
ERROR: 4000,
NONE: 5000
}
export function makeFakeLogger (log_level_override) {
// Adapted from: https://nodejs.org/docs/latest/api/cluster.html
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running on ${numCPUs} numCPUs`);
// Fork workers.
// Similar to Ruby array `last` method
Object.defineProperty(Array.prototype, "last", {
get: function(){
return this.length && this[this.length-1];
}
});
@AJamesPhillips
AJamesPhillips / git_helper.py
Last active March 30, 2017 13:15
Display the number of additions and deletions per commit for a file
#!/usr/bin/env python3
"""
Display the number of additions and deletions per commit for a file e.g.
$ ./git_helper.py index.d.ts
commit added deleted
bd1de57 4 4 index.d.ts Error object fix
c3a54db 25 120 index.d.ts Merge branch 'master' into types-2.0
e9a0e98 58 10 index.d.ts Merge commit 'upstream/master~300' into merge_7_25
import time
import threading
input_thread_values = []
def input_thread():
print('press s and enter to stop...')
global input_thread_values
// Code and tests adapted from Numpy library
func dot_product(in arr1: [Double], index1: Int, in arr2: [Double], index2: Int, n: Int, result_index: Int, inout result_arr: [Double]) {
var sum = 0.0;
for i in 0..<n {
sum += arr1[index1 + i] * arr2[index2 + i]
}
result_arr[result_index] = sum
}
import AIToolbox
import XCTest
@testable import ios_hub
class LogRegTests: XCTestCase {
func getSmallTestData() -> DataSet {
// Create test case
let data = DataSet(dataType: .Classification, inputDimension: 2, outputDimension: 1)
do {
@AJamesPhillips
AJamesPhillips / gist:04f3047ca8770f4a3a58
Created May 2, 2014 15:18
Integration testing Scrapy spiders
import subprocess
import unittest
from scrapy.crawler import Crawler
from scrapy.utils.project import get_project_settings
from twisted.internet import reactor, task
from my_project.spiders.spider1 import Spider1
from my_project.spiders.spider2 import Spider2
@AJamesPhillips
AJamesPhillips / gist:11308972
Last active August 29, 2015 14:00
Does not error
interface Animal {
size: number;
}
interface Cat extends Animal {
furry: boolean;
}
interface Human extends Animal {
name: string;
}
@AJamesPhillips
AJamesPhillips / rsa.py
Last active February 10, 2020 12:21
Reorder arguments in bruteForceV1 signature
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Simple example of encrypting, sending and decrypting a message using RSA.
Also included is how a third party without permission, would need
to use a very time consuming (brute force) approach to decrypt
the message. This is done by finding the two prime numbers that make up
part of the public key so that you can read the encrypted message.