Skip to content

Instantly share code, notes, and snippets.

@Gikkman
Gikkman / Map_RW_Performance_Test.java
Last active December 1, 2016 09:14
A test I wrote to compare read and write speeds of HashMap and ConcurrentHashMap.
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
public class ReadWriteTimeTest
{
@Gikkman
Gikkman / app.html
Created September 3, 2018 16:24 — forked from derekchiang/app.html
[electron]Use electron as a Web Server
<!doctype html>
<html><head><script src="app.js"></script></head><body></body></html>
@Gikkman
Gikkman / intersect.lua
Last active October 22, 2018 19:24
BizHawk input lua
-- Pre-made array for resetting the P1 joypad
local reset = joypad.get(1)
for k,v in pairs(reset) do
reset[k] = ''
end
event.onframestart( function()
local p1 = joypad.get(1)
local p2 = joypad.get(2)
local consolidated = intersection(p1, p2)
-- Array of controller modes. We will switch
-- between the three of these randomly
local mode = {"P1", "P2", "ZEN"}
local current = mode[1]
-- Pre-made array for resetting the P1 joypad
local reset = joypad.get(1)
for k,v in pairs(reset) do
reset[k] = ''
end
@Gikkman
Gikkman / currey.js
Created December 13, 2019 12:54
Short curry function for Javascript
// Tiny, recursive autocurry
const curry = (
f, arr = []
) => (...args) => (
a => a.length === f.length ?
f(...a) :
curry(f, a)
)([...arr, ...args]);
@Gikkman
Gikkman / compose.js
Created December 17, 2019 09:31
Short right-hand compose example
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x);
const trace = label => value => {
console.log(`${ label }: ${ value }`);
return value;
};
const g = n => n + 1;
const f = n => n * 2;
@Gikkman
Gikkman / chain-callbacks.js
Last active January 10, 2020 10:00
Small convenience function for chaining functions that utilizes error-first callbacks
// **************************************************
// Lib code
// **************************************************
function chainer(errHandler, functions) {
// Copy functions array so rChainer doesn't modify the referenced array
return (...input) => rChainer(errHandler, [...functions], ...input);
}
function rChainer(errHandler, functions, ...input) {
let func = functions.shift();;
@Gikkman
Gikkman / Mapped type example
Created February 11, 2020 09:29
example.ts
interface example {
"a": number,
"b": string,
"c": {x: number, y: string, z: any },
"d": {val: keyof example}
}
function test<T extends keyof example> (p1: T, p2: example[T]): void {
console.log(p1, p2);
}
@Gikkman
Gikkman / TypesLesson.ts
Created May 10, 2021 19:48
A handy collection of examples of how to work with typescript types
type SimpleExample = 1 | 2 | 'a';
type ConditionalExample<T> = T extends number ? T : never;
type T = ConditionalExample<SimpleExample> // '1' | '2'
/////////////////////////////////////////////////////////////////////////////
// Filter out keys from TRecord which's value matches type of TMatch
type MatchingKeys<
TRecord,
TMatch,
K extends keyof TRecord = keyof TRecord
@Gikkman
Gikkman / gist:0346639e451c2742a763912a12de2882
Created September 27, 2021 09:03
Git checkout tracking branch
git fetch;
git pull;
TRACKING=$(git remote show origin | grep 'HEAD branch' | cut -d ':' -f 2 | sed 's# ##');
echo Checking out $REPO:$TRACKING;
git checkout -q $TRACKING;
git pull;