Skip to content

Instantly share code, notes, and snippets.

View jasonsperske's full-sized avatar

Jason Sperske jasonsperske

View GitHub Profile
@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 / cookies.js
Last active May 20, 2022 17:49
A super tiny function that converts the document.cookie to an object
function cookieMap() {
return document.cookie
.split('; ')
.map((c) => Object.fromEntries([c.split(/=(.*)/s).slice(0, 2)]))
.reduce((a, v) => ({ ...a, ...v }), {});
}
@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')
@jasonsperske
jasonsperske / AUTOEXEC.BAT
Created March 14, 2021 22:16
P166 Boot files
@ECHO OFF
@REM SET SOUND=C:\SB16
@REM SET BLASTER=A220 I5 D1 H5 P330 T6
@REM SET MIDI=SYNTH:1 MAP:E
@REM SET CTCM=C:\SB16
@REM C:\SB16\DIAGNOSE /S /W=C:\WINDOWS
@REM C:\SB16\MIXERSET /P /Q
@REM C:\SB16\CTCU.EXE /S /W=C:\WINDOWS
PROMPT $p$g
PATH C:\NET;C:\WINDOWS;C:\DOS;C:\XTGOLD;C:\TC\BIN;C:\WP51;C:\SOFTMPU;C:\MIDIEMU
@jasonsperske
jasonsperske / deepSet.js
Last active November 9, 2021 17:46
Setting a deep JSON property with one call, a answer to a question on StackOverflow that was deleted before I could post it https://stackoverflow.com/questions/47064851/read-or-init-js-variable-to-avoid-cannot-read-property-of-undefined#47064851
function deepSet(keys, value) {
return keys.split('.')
.reverse()
.reduce((acc, current) => ({
[current]: acc
}), value);
}
//You can use it like this:
console.log(JSON.stringify(deepSet('foo.name.social.twitter.followers', 100)))
@jasonsperske
jasonsperske / q12944362-programmatic-binding-of-accelerators-in-wxpython.py
Created October 18, 2012 17:06
Solution to binding a lambda to an event in wxPython with arguments
import wx
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Programmatic binding of accelerators in wxPython", size=(450,150))
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
@jasonsperske
jasonsperske / Examples.java
Last active December 23, 2018 20:00
An Amazon Technical interview question I received this year. Write a function that when given a map (a 2-dimensional grid where 1 is a walk-able square, 0 is an impassable square and 9 is the destination) and starting at the top left (x:0, y:0) finds the shortest path to the destination
import java.util.Arrays;
public class Examples {
public static void main(String ... args) {
Solution s = new Solution();
System.out.print("Example problem: ");
System.out.println(s.shortest(3, 3,
Arrays.asList(
Arrays.asList(1, 0, 0),
@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 / hue.js
Created November 20, 2017 05:23
HueSegments
//An example of this can be seen at https://jsfiddle.net/uLzwv8mx/
function HueSegments(steps) {
var segments = []
var step
var increment = 200/steps
for(step = 0; step < steps; step++) {
segments.push("hsla("+(Math.floor(increment*step))+", 100%, "+(step % 2 == 0 ? "75" : "50")+"%, 1)")
}
return segments
}
@jasonsperske
jasonsperske / InstallCert.java
Created September 28, 2017 22:20
InstallCert.java Posted at 22:28 Oct 09, 2006 by Andreas Sterbenz
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*