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
const LOG_LEVELS = { | |
DEBUG: 1000, | |
INFO: 2000, | |
WARN: 3000, | |
ERROR: 4000, | |
NONE: 5000 | |
} | |
export function makeFakeLogger (log_level_override) { |
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
// 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. |
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
// Similar to Ruby array `last` method | |
Object.defineProperty(Array.prototype, "last", { | |
get: function(){ | |
return this.length && this[this.length-1]; | |
} | |
}); |
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
#!/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 |
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
import time | |
import threading | |
input_thread_values = [] | |
def input_thread(): | |
print('press s and enter to stop...') | |
global input_thread_values |
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
// 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 | |
} |
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
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 { |
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
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 |
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
interface Animal { | |
size: number; | |
} | |
interface Cat extends Animal { | |
furry: boolean; | |
} | |
interface Human extends Animal { | |
name: string; | |
} |
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
#!/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. |