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
/* | |
* | |
* Return SQLite3 query results as a Nodejs stream, sensitive to backpressure. | |
* | |
* Assumes a foo.db file with a lot of rows - I used 1000 with a number & a string | |
*/ | |
const stream = require('stream'); | |
const sqlite = require('sqlite3'); | |
class DBStream extends stream.Readable { |
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
/* | |
* | |
* Wikipedia: | |
* | |
* The final digit of a Universal Product Code is a check digit computed as follows: | |
* | |
* 1) Take digits up to but not including the check digit. | |
* 2) Sum the digits in the odd-numbered positions (first, third, fifth, etc.) together and multiply by three. | |
* 3) Add the sum of digits in the even-numbered positions (0th, 2nd, 4th, 6th, etc.) to the result. | |
* 4) Take result modulo 10 |
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 inrange( maxx, maxy ): | |
def func( point ): | |
x,y = point | |
return x >= 0 and x <= maxx and y >= 0 and y <= maxy | |
return func | |
class Game: | |
def __init__(self): | |
self.board = [ |
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
# | |
# Coding challenge that took me well over an hour for a one-hour limi. | |
# I started by overbuilding. Lesson learned is - do minimum viable | |
# for interview coding challenges! | |
# | |
# Sigh. | |
# | |
# Challenge is to parse a string representing an arithmetic expression | |
# and evaluate it without using eval() | |
# |
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
Coding challenge. | |
Create a DataCapture class that queries statistics about an input stream of numbers. | |
Assume that the input stream consists of positive integers in the range 0 to 1000. | |
Class must implement the following methods: | |
add(n) - add an input element to collection in O(1) time | |
build() - create summary information on the collection in O(log(n)) time |
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
# | |
# I was given about 10 minutes to figure out an exercise that | |
# boiled down to merging named tuples | |
# | |
# Weird thing to expect someone to know. Certainly anyone who knows this | |
# off the top of their head knows a lot about Python. But not everyone | |
# good developer will know this little corner of Python. | |
# | |
# It took me some time inspecting tuples to come up with this approach, slowed | |
# by my discomfort with relying on single-underscore members of library objects |
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 express = require('express') | |
const app = express() | |
const HOST = 'localhost' | |
const PORT = 8000 | |
function hello( req, res ) { | |
const msg = `Use curl http://${HOST}:${PORT}/upload --upload-file <somefile>` | |
res.send(msg) | |
res.end() |
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 React, { useState } from 'react' | |
import './App.css' | |
function Cell( props ) { | |
const [ state, setState ] = useState( props.alive ) | |
return <td class={ props.alive ? 'alive' : 'dead' }>r{props.row}c{props.col}</td> | |
} | |
function Table( props ) { |
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
!/bin/bash | |
# | |
# Put this script into ~/.githooks/pre-push and make it executable. | |
# Then run git config -add core.githooks ~/.gitconfig | |
# | |
# You could also put it into .git/hooks for a particular repo | |
# and skip the git config step | |
# | |
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
let tree = { | |
'0': { | |
'1': { | |
'3': null, | |
'4': null }, | |
'2': { | |
'5': null, | |
'6': null } | |
} | |
} |
OlderNewer