Skip to content

Instantly share code, notes, and snippets.

Greg Skiano skiano

Block or report user

Report or block skiano

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@skiano
skiano / linked.js
Last active Sep 28, 2018
little doubly linked list
View linked.js
function createList() {
var next = 'prev'
, prev = 'next'
, length = 0
, head
, tail
, arr
, n;
return {
View binary-blob-challenge.js
// SOLUTION 1
const getBlobBoundingBox1 = (blobString) => {
blobString = blobString.trim()
const width = (/\s/.exec(blobString) || {}).index
const one = /1/g
blobString = blobString.replace(/\s+/g, '')
@skiano
skiano / interview-snippets.js
Last active Mar 8, 2018
Interesting code snippets to talk about
View interview-snippets.js
// -------------------------------------------------------------------------------------------------------
// Once (from source of async)
// @see https://github.com/caolan/async/blob/f5d86b80b986c8cad88a224a6f8b3ec154839490/lib/internal/once.js
// -------------------------------------------------------------------------------------------------------
function once(fn) {
return function () {
if (fn === null) return;
var callFn = fn;
fn = null;
View anagram-compressor.js
// A compressor for anagram puzzle data
// because we know all the solutions to anagram puzzles
// have a very small number of characters, we can compress
// the data more strategically
//
// given a list of letters, this creates an encode and decode function
//
// for example
// given the letters:
// 'NCEHITK'
View recursive pyramid
// logs this pattern
// *
// * *
// * *
// * * * *
// * *
// * * * *
// * * * *
// * * * * * * * *
@skiano
skiano / n-distance.js
Last active Dec 23, 2017
n-dimension distance
View n-distance.js
// not really about performance
// but fun to make it one line
// this discussion looked interesting re estimating
// https://stackoverflow.com/questions/3693514/very-fast-3d-distance-check
const distance = (a, b) => Math.sqrt(a.reduce((total, _, i) => total + Math.pow(b[i] - a[i], 2), 0))
const _2d_ = distance([1, 2], [0, 4])
const _3d_ = distance([1, 2, 3], [0, 4, 5])
@skiano
skiano / spiralGridWalk.js
Created Dec 22, 2017
walk the coordinates of a grid in a spiral to the center
View spiralGridWalk.js
// walk around the edges of a grid
// and work toward the center
// Begin going right.
// When you are at an edge or a filled square, turn right.
const spiral = (w, h, fn) => {
// a map where keys are visited indexes
const visited = {}
// translations represent increments for: right -> down -> left -> up
const translations = [1, w, -1, -w]
@skiano
skiano / fillOrder.js
Created Dec 22, 2017
establish an order for filling a grid
View fillOrder.js
// >>> is perf hack for flooring positive numbers
const rand = (min, max) => ((Math.random() * (max - min + 1)) >>> 0) + min
const randItem = (arr) => arr[rand(0, arr.length - 1)]
const isDef = v => typeof v !== 'undefined'
const isUndef = v => typeof v === 'undefined'
const directions = [
(w, h, x, y, i) => y > 0 ? i - w : undefined,
(w, h, x, y, i) => y < h - 1 ? i + w : undefined,
@skiano
skiano / gridf.js
Last active Dec 17, 2017
2D letter grid compression
View gridf.js
// TAKES A 2D ARRAY OF LETTERS AND COMPRESSES TO STRING
// for example ...
// compressGrid([
// ['A','A','A','B','B'],
// ['B','A','B','B','B'],
// ['B','A','B','B','B'],
// ['B','A','B','B','B'],
// ])
// becomes...
// 'A2B1,BAB2,2'
View cursor.js
const createCursor = (directions, onMove) => {
const dirKeys = Object.keys(directions);
const cursor = {};
let location = 0;
cursor.max = 1000;
cursor.get = () => location;
You can’t perform that action at this time.