Skip to content

Instantly share code, notes, and snippets.

View g2graman's full-sized avatar

Francesco Gramano g2graman

  • Toronto, Ontario, Canada
View GitHub Profile
@g2graman
g2graman / kd-bsearch.py
Created February 22, 2015 20:27
A k-dimensional generalization of binary search after first redefining what it means to be sorted in multiple dimensions (similar to the definition for ordering a kd-tree). There is room for improvement marked by the TODO on line 22 for improving performance. Made more accessible from https://github.com/g2graman/Miscellaneous/blob/master/Scripts…
def sort(L):
'''(list) -> list
Returns a sorted version of list L, where every element in L
must have the same number of dimensions.'''
m_len = len(max(L, key=len))
assert(all([len(x) == m_len for x in L])) #Make sure all elements have same length
return _sort(L, 0, m_len)
@g2graman
g2graman / Interpreter.py
Last active August 29, 2015 14:18
Simple Interpreter (in Python) for a modified subset of Python which was made for creating simple recursive functions (based on foldl) and simple statements
from string import ascii_letters
from math import log
from math import ceil
def product(alphabet, up_to, repeat=1):
''' (list of strs, int, int) -> (list of strs)
Return the bounded cartesian product of alphabet with (repeat - 1)
other copies of itself, containing at most up_to elements.'''
@g2graman
g2graman / Dockerfile
Last active June 4, 2017 22:50
Example Node.js Dockerfile
FROM node:boron
RUN mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
RUN npm install --production
CMD ["node", "app.js"]
@g2graman
g2graman / Dockerfile
Last active June 5, 2017 02:12
Example Node.js Dockerfile for a build stage
FROM node:boron
RUN mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
RUN npm install --production
@g2graman
g2graman / Dockerfile
Last active June 5, 2017 02:12
Example Node.js Dockerfile for a release stage
FROM node:boron-alpine
RUN mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
CMD ["node", "app.js"]
@g2graman
g2graman / Dockerfile
Last active June 6, 2017 08:23
A multi-stage Dockerfile with named build stages for a Node.js app
FROM node:boron as installer
RUN mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
RUN npm install --production
FROM node:boron-alpine as release
@g2graman
g2graman / Dockerfile
Created June 6, 2017 08:24
A multi-stage Dockerfile without named build stages for a Node.js app
FROM node:boron
RUN mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
RUN npm install --production
FROM node:boron-alpine
@g2graman
g2graman / Dockerfile
Created June 6, 2017 08:47
A multi-stage partial (of an installation phase) Dockerfile without named build stages for a Node.js app
FROM node:boron
RUN mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
RUN npm install --production
@g2graman
g2graman / Dockerfile
Last active June 6, 2017 08:51
A multi-stage partial (of a release phase) Dockerfile without named build stages for a Node.js app
FROM node:boron-alpine
RUN mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
COPY --from=$BUILD_FROM /home/app .
CMD ["node", "app.js"]
@g2graman
g2graman / combinators.js
Created October 27, 2019 13:50 — forked from Avaq/combinators.js
Common combinators in JavaScript
const I = x => x;
const K = x => y => x;
const A = f => x => f(x);
const T = x => f => f(x);
const W = f => x => f(x)(x);
const C = f => y => x => f(x)(y);
const B = f => g => x => f(g(x));
const S = f => g => x => f(x)(g(x));
const P = f => g => x => y => f(g(x))(g(y));
const Y = f => (g => g(g))(g => f(x => g(g)(x)));