Skip to content

Instantly share code, notes, and snippets.

View raimohanska's full-sized avatar

Juha Paananen raimohanska

View GitHub Profile
@raimohanska
raimohanska / fp.go
Created February 8, 2023 08:05
Golang FP basics: filter, map, flatMap
func Map[A any, B any](things []A, mapper func (x A) B) []B {
result := make([] B, len(things))
for i := range(things) {
result[i] = mapper(things[i])
}
return result
}
func Filter[A any](things []A, predicate func (x A) bool) []A {
result := make([] A, len(things))
import nextJs from "next"
async function createNextAppWithCustomLogging() {
const nextApp = nextJs({ dev: false })
const server = (await (nextApp as any).getServer()) as any
if (!(server.logError instanceof Function)) throw Error("Assertion fail")
server.logError = (err: Error) => {
logger.error(err)
}
return nextApp
@raimohanska
raimohanska / glitchprevention.md
Last active November 1, 2018 09:37
Bacon.js glitch prevention

The key to glitch prevention is the UpdateBarrier. This component takes care of starting and finishing event transactions. The inTransaction function is used to wrap all event handling, creating a transaction that lasts until the original event and all derived events (those created when passing the event through all the maps, combines etc) have been processed.

In the end of the transaction, a flush occurs. During flush, all pending actions are performed. And what are these action then? They are actions registered using the whenDoneWith function, and are basically requests like "please run this function when the dependencies certain observable have been fully flushed". To satisfy these request, the Up

#!/usr/bin/env node
if (process.argv.length != 3) {
console.error("Usage: psqlurl <url>")
console.error("Expected one argument, got " + (process.argv.length - 2))
process.exit(1)
}
var input = process.argv[2]
var URL = require("url")
var ps = require("child_process")
var url = URL.parse(input)
@raimohanska
raimohanska / enocean.ino
Created February 21, 2015 20:48
Arduino enocean dimmer
int SIGNAL_LED = 13;
int POWER_LED = 11;
byte buffer[100];
byte myAddress[] = {-1, -114, 70, -125};
void setup() {
Serial.begin(9600);
pinMode(SIGNAL_LED, OUTPUT);
pinMode(POWER_LED, OUTPUT);
@raimohanska
raimohanska / depth.js
Last active August 29, 2015 14:15
depth.js
#! /usr/bin/env node
var fs = require("fs")
var files = process.argv.slice(2)
if (!files.length) {
console.log("USAGE: depth.js file1 [file2 ...]")
}
files.forEach(function(filename) {
var object = JSON.parse(fs.readFileSync(filename))
console.log(filename, depth(object, ""))
function depth(object, path) {
@raimohanska
raimohanska / waitForAngular.js
Created July 18, 2014 12:26
Wait until angularjs is done with processing its stuff
waitForAngular = function(el, angular, callback) {
try {
angular.element(el).injector().get('$browser').notifyWhenNoOutstandingRequests(callback);
} catch (e) {
callback(e);
}
};
@raimohanska
raimohanska / .gitconfig
Created February 12, 2014 14:07
My .gitconfig
[user]
name = Juha Paananen
email = juha.paananen@gmail.com
[color]
ui = auto
diff = true
[alias]
st = status
stp = status --porcelain
br = branch
@raimohanska
raimohanska / rue.coffee
Created February 7, 2014 11:18
testing bacon.bus
Bacon=require("baconjs")
s = Bacon.later(1000, "hello")
b = new Bacon.Bus()
b.plug(s)
b.log()
@raimohanska
raimohanska / princess-vs-lion.elm
Created January 27, 2014 17:57
Princess vs Lion in Elm
module PrincessVsLion where
import Keyboard
data GameState = Ongoing Int Int | LionWon | PrincessWon
proceedGame keyPresses state = case state of
Ongoing princess lion ->
checkEnd (princess + (keyPresses `div` 2)) (lion + 1)
x -> checkRestart keyPresses x