Skip to content

Instantly share code, notes, and snippets.

View rmela's full-sized avatar

Robert Mela rmela

  • Lexington, MA, USA
View GitHub Profile
@rmela
rmela / game_of_life.py
Last active September 5, 2019 23:07
Game of life. Interview coding challenge. Didn't finish in the hour allotted. Solved it later anyway.
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 = [
@rmela
rmela / gs1-checksum.js
Last active August 9, 2019 20:57
GS1 checksum utilities
/*
*
* 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
@rmela
rmela / SQL query results as nodejs read stream
Last active March 24, 2025 13:12
SQLite query results as nodejs readable stream
/*
*
* 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 {