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 / 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 / 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 / index.js
Created November 1, 2019 02:48
Read raw upload data as stream in express js
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()
@rmela
rmela / App.js
Last active December 1, 2019 17:05
Dynamic table creation from React
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 ) {
@rmela
rmela / pre-push
Last active December 9, 2019 17:19
Git hook to prevent pushing to master or release
!/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
#
@rmela
rmela / binary_tree_to_array.js
Last active January 6, 2020 04:23
Binary tree as array kata - shows up a lot in coding challenges
let tree = {
'0': {
'1': {
'3': null,
'4': null },
'2': {
'5': null,
'6': null }
}
}
@rmela
rmela / index.js
Last active January 23, 2020 04:11
Simple Game of Life module - ( add to package.json as "any-name-here": "gist:76fe92595473ac07c25cf3dd1d631a38" )
function toString( rows ) {
return rows
.map( row => row
.map( cell => cell.value ? '1' : '0' )
.join( ' ' )
).join("\n")
}
class Game {
@rmela
rmela / interview coding challenge - arithmetic expression evaluator
Last active January 23, 2020 04:29
Arithmetic expression parser coding challenge
#
# 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()
#
@rmela
rmela / coding challenge
Last active August 28, 2020 03:22
Interview coding challenge. Aced this one well under the time limit. I guess practical problems suit me better.
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
curl --header "Authorization: bearer <your-github-api-token-here>" https://api.github.com/graphql \
-d '{"query":"query { viewer { login } }"}'