Skip to content

Instantly share code, notes, and snippets.

View jasonsperske's full-sized avatar

Jason Sperske jasonsperske

View GitHub Profile
@jasonsperske
jasonsperske / fan.st-logo.py
Created July 25, 2013 17:44
I got tired of resizing and fixing our logo for the myriad of sizes that iPhone, Android and Facebook require, so I wrote a Python script to generate it. There are a couple of hacks (like the gap between the top and bottom half), but it generates our logo with the correct colors and ratios :)
import Image, ImageDraw
box_height = 2
box_width = 6
box_gap_height = 3
box_gap_width = 2
background = (0,0,0)
level_background = (119,120,123)
peeks = (237,26,59)
@jasonsperske
jasonsperske / Russian.js
Last active December 30, 2015 04:29
A Google Interview question I was asked over a year ago (and didn't know the answer to). I've since learned how and here is a quick solution in JavaScript (qunit demo at http://jsfiddle.net/at4gU/). I wanted to make something Lisp-y so it takes multiple arguments, deals with negative numbers and passes JSLint (well except for the bitwise operato…
/*jslint bitwise: true */
var multiply = function () {
'use strict';
var fn = function (a, b, product) {
if (a > 0) {
return fn(a >> 1, b << 1, product + (a % 2 === 1 ? b : 0));
}
return product;
},
factors = Array.prototype.slice.call(arguments),
@jasonsperske
jasonsperske / Russian.clj
Created December 5, 2013 00:31
I wanted to try and apply what I have learned writing a JavaScript implementation of the Russian Peasant Algorithm to what I have been learning with Scheme. This works the same way as the JavaScript function :)
(ns Russian)
(defn multiply [& args]
(defn russian_multiply [a b p]
(cond
(> a 0) (russian_multiply (bit-shift-right a 1) (bit-shift-left b 1) (+ p (if (= (mod a 2) 1) b 0)))
:else p))
(defn flip [a] (inc (bit-not a)))
@jasonsperske
jasonsperske / FencePainter.js
Last active February 3, 2018 03:43
Another Google technical interview question that left me stumped. "Write an algorithm that counts the number of ways you can paint a fence with N posts using K colors such that no more than 2 adjacent fence posts are painted with the same color". Here is a recursive approach:
var paint = function (posts, colors, display) {
var painter = function (posts, colors, fence, count, display) {
var color, total = count;
if (posts === 0) {
//Would you like to see them? Pass a display function
if(display) {
display(fence);
}
return 1;
} else {
@jasonsperske
jasonsperske / deepestNode.js
Last active July 12, 2017 20:44
Find the deepest left most node in a binary tree (and it's depth). A working demo can be found at: http://jsfiddle.net/YfLx6/5/
var Node = function(name, left, right) {
this.name = name;
this.left = left;
this.right = right;
},
findDeepest = function(node, depth) {
var left, right, depth = depth || 0;
if(typeof node !== 'undefined') {
left = findDeepest(node.left, depth+1);
right = findDeepest(node.right, depth+1);
@jasonsperske
jasonsperske / Wave_Writer.cpp
Last active August 29, 2015 14:01
Small utility that generates a clean set of WAV files from any supported format of game-music-emu
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
#include "Wave_Writer.h"
#include <assert.h>
#include <stdlib.h>
/* Copyright (C) 2003-2006 by Shay Green. Permission is hereby granted, free
of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without
@jasonsperske
jasonsperske / highlight.html
Created May 15, 2014 00:29
Basic System to highlight keywords in a textarea (http://jsfiddle.net/KcP7m/)
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Textarea Highlighter</title>
<script src="//code.jquery.com/jquery-1.11.0.js" type="text/javascript"></script>
<style type="text/css">
#Status, #Highlighter {
width: 96%;
height: 250px;
font-family: Helvetica, Arial, 'lucida grande', tahoma, verdana, arial, sans-serif;
@jasonsperske
jasonsperske / MIT-LICENSE
Last active March 1, 2023 03:06
A simple Python program that can read DOOM.Hexen IWAD and PWAD files and render them as SVG see examples at http://jason.sperske.com/wad/
MIT License
Copyright (c) 2018 Jason Sperske
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@jasonsperske
jasonsperske / car_cdr.playground
Last active August 29, 2015 14:02
Getting aquainted with a new langauge. Really wish there was a splatter operator.
func car<T>(l: Array<T>?) -> T? {
if l == nil || l!.count <= 0 {
return nil
} else {
return l![0]
}
}
func cdr<T>(l: Array<T>?) -> Array<T>? {
if l == nil || l!.count <= 1 {
@jasonsperske
jasonsperske / GRPParser.py
Last active April 16, 2022 00:55
Like my WADParser.py but for Duke Nukem 3D MAP files
#!/usr/bin/env python3
import struct
import re
import io
from collections import namedtuple
GrpFileDefinition = namedtuple('GrpFileDefinition', 'name size')
Line = namedtuple('Line', 'a b is_one_sided')