Skip to content

Instantly share code, notes, and snippets.

Niklas Lindgren nikcorg

Block or report user

Report or block nikcorg

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
View summed-area-table.ts
// https://en.wikipedia.org/wiki/Summed-area_table
type Point = { x: number; y: number };
type DefaultingGetter<T> = (x: number) => T;
type DefaultingGetterFactory = <T>(xs: T[], def: T) => DefaultingGetter<T>;
interface Mapper {
toxy: (n: number) => Point;
toi: (x: number, y: number) => number;
}
@nikcorg
nikcorg / gsm7bit-decoder.js
Last active Dec 11, 2018
GSM 7 Bit Decoder
View gsm7bit-decoder.js
// This decoder is based on this answer https://stackoverflow.com/a/21115816
// It's not perfect, e.g. it does not accommodate the extended alphabet.
//
// Solution from SO answer paraphrased below:
//
// For input: C7F7FBCC2E03
// 1) Form tuples for hex numbers and reverse
// -> 03-2E-CC-FB-F7-C7
// 2) Convert hex to 8-bit binary octets
// -> 00000011-00101110-11001100-11111011-11110111-11000111
@nikcorg
nikcorg / main.go
Created Sep 24, 2018
Playing with Maybe in Go
View main.go
package main
import (
"fmt"
"strings"
)
type Any interface{} // The lack of generics in Go is the pitfall
type Morphism func(Any) Any
@nikcorg
nikcorg / inspirobot-bg.sh
Created Mar 27, 2018
Inspirobot background images
View inspirobot-bg.sh
#!/usr/bin/env bash
DUMP=/path_to_downloaded_images_storage_here
GENERATED_IMG_SRC=$(curl -s "http://inspirobot.me/api?generate=true")
if [ $? -eq 0 ]; then
BASENAME=$(basename $GENERATED_IMG_SRC)
OUT="$DUMP/$BASENAME"
TMP="/tmp/$BASENAME"
View dump.lua
function dump(o, p)
p = p or ''
if type(o) == 'table' then
local s = '{\n'
local pp = p .. ' '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"' .. k .. '"' end
s = s .. pp .. '[' .. k .. '] = ' .. dump(v, pp)
@nikcorg
nikcorg / document-meta-proxy.js
Last active Apr 16, 2016
Proxy pattern for transforming props passed to react-document-meta
View document-meta-proxy.js
import React from "react";
import DocumentMeta from "react-document-meta";
const applyTransforms = ({ title, ...props }) => ({ ...props, title: `${title} - suffix` });
export default const ProxyComponent = (props) => <DocumentMeta {...applyTransforms(props)} extend />;
View index.html
<!doctype html>
<html>
<head>
<title>TableSort Demo</title>
<body>
<table>
<thead>
<tr>
<th class="default-sort">Weekday</th>
<th>Date</th>
@nikcorg
nikcorg / package.json
Created Nov 24, 2015
StackOverflow answer
View package.json
{
"scripts": {
"build": "browserify index.js > bundle.js"
},
"browserify-shim": {
"./sorts/tablesort.date.js": {
"depends": "tablesort:Tablesort"
}
},
"browserify": {
@nikcorg
nikcorg / active-javascript.md
Last active May 18, 2016
Finnish GitHub users stats
View active-javascript.md

Most active GitHub users (git.io/top)

The count of contributions (summary of Pull Requests, opened issues and commits) to public repos at GitHub.com from Sun, 19 Apr 2015 17:59:08 GMT till Tue, 19 Apr 2016 17:59:08 GMT.

Only first 1000 GitHub users according to the count of followers are taken. This is because of limitations of GitHub search. Sorting algo in pseudocode:

githubUsers
  .filter(user => user.followers > 11)
@nikcorg
nikcorg / flatmaplatest.js
Last active Nov 11, 2015
Flat Map Latest (through events)
View flatmaplatest.js
export const VALUE = Symbol("VALUE");
const attempt = (fn, ...args) => {
try {
return fn(...args)
} catch (e) {}
}
const listen = function (event, cb) {
const eProp = Symbol.for(event);
You can’t perform that action at this time.