Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Sperske jasonsperske

View GitHub Profile
@jasonsperske
jasonsperske / cookies.js
Last active May 20, 2022
A super tiny function that converts the document.cookie to an object
View cookies.js
function cookieMap() {
return document.cookie
.split('; ')
.map((c) => Object.fromEntries([c.split(/=(.*)/s).slice(0, 2)]))
.reduce((a, v) => ({ ...a, ...v }), {});
}
View AUTOEXEC.BAT
@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 / Examples.java
Last active Dec 23, 2018
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
View Examples.java
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),
View hue.js
//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 / deepSet.js
Last active Nov 9, 2021
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
View deepSet.js
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 / InstallCert.java
Created Sep 28, 2017
InstallCert.java Posted at 22:28 Oct 09, 2006 by Andreas Sterbenz
View InstallCert.java
/*
* 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.
*
View keybase.md

Keybase proof

I hereby claim:

  • I am jasonsperske on github.
  • I am sperske (https://keybase.io/sperske) on keybase.
  • I have a public key ASDulU5JtSD8n6FbUOUc-Ew2aEepk77hUZO8-pUPKWGyJAo

To claim this, I am signing this object:

@jasonsperske
jasonsperske / index.html
Created Jun 21, 2017
Get Location Information
View index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=content-type content="text/html;charset=UTF-8">
<title>GeoLocation Diagnostics</title>
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1">
<meta name=format-detection content="telephone=no">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
@jasonsperske
jasonsperske / SendVictory.js
Created Mar 24, 2017
Fetches a RandomVictory and sends it to a IFTTT Maker WebHook (defiend in envrionment varibles)
View SendVictory.js
'use strict';
var https = require('https');
function fetchVictory(then, context, callback) {
var options = {
hostname: "randomvictory.com",
port: 443,
path: "/random.json",
method: "GET"
}
@jasonsperske
jasonsperske / index.js
Created Mar 20, 2017
Indexing to Algolia
View index.js
'use strict';
const algoliasearch = require('algoliasearch'),
path = require('path'),
striptags = require('striptags'),
settings = require('nconf').argv().env().file({file: '../settings.json'}).defaults(),
localizations = require('../content/localizations.json'),
base_path = path.join(__dirname, '..'),
utils = require('../fileCMS-utils')(base_path),
algolia_settings = settings.get('algolia'),
client = algoliasearch(algolia_settings.id, algolia_settings.key, function(err, message) {