Skip to content

Instantly share code, notes, and snippets.

Torgeir Thoresen torgeir

Block or report user

Report or block torgeir

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
torgeir / sketch_lines.cljs
Last active Sep 18, 2019
Generative art: Lines between two random lines inverted, repeat
View sketch_lines.cljs
(ns sketches.sketch-lines
(:require [quil.core :as q]
[quil.middleware :as m]
[lib.key-press-handlers :refer [save-image]]
[sketches.palette :refer [find-palette rand-palette]]))
(def body (.-body js/document))
torgeir / compile.cljs
Last active Mar 9, 2019
Using clojurescript to compile clojurescript
View compile.cljs
(ns example.core
(:require [cljs.js :as cjs]
[cljs.analyzer :as ana :include-macros true]
[cljs.reader :as r]
[cljs.pprint :as pprint]))
(let [src "(ns t.math)
(defn increase [n] (inc n))"
torgeir / torg.ds
Last active Feb 17, 2019
devilspie workspace layout
View torg.ds
Lookup geometry: /usr/bin/xwininfo
(and (is (application_name) "Firefox")
(set_workspace 1)
(geometry "1387x1138+0-32")))
(and (is (application_name) "emacs-snapshot")
torgeir / dependency-stats.js
Created Sep 26, 2018
Lookup various github stats from npm package name; stars, contributors, open issues/prs etc.
View dependency-stats.js
const r2 = require("r2");
const npm = require("npm");
const { spawn } = require("child_process");
const [_, __, accessToken, repo] = process.argv;
const shellCmdStdoutToObject = (cmd, args) =>
new Promise(function(resolve, reject) {
const child = spawn(cmd, args);
let result = "";
torgeir / myth-loader.js
Created May 3, 2018
webpack myth loader, a myth loader that supports @import declarations
View myth-loader.js
const path = require('path');
const myth = require('myth');
const globby = require('globby');
const loaderUtils = require('loader-utils');
const resolve = function () {
const p = [__dirname].concat(Array.from(arguments));
return path.resolve.apply(path, p);
torgeir / hyperappish.js
Last active Apr 21, 2018
A minimal, hyperapp-like, wired action, state handling thingy that works with plain react components
View hyperappish.js
import React from "react";
import ReactDOM from "react-dom";
import Rx from "rxjs/Rx";
// hyperappish
const identity = v => v;
const doto = (o, fn) => (fn(o), o);
const getIn = (obj, [k, ...ks]) => (ks.length == 0) ? obj[k] : getIn(obj[k], ks);
torgeir / lazy-fetch-with-getter.js
Last active Mar 14, 2018
Js lazy fetch with getter
View lazy-fetch-with-getter.js
const wait = s => new Promise((resolve) => setTimeout(resolve, s * 1000))
const state = {};
dataField(state, "ip", "");
.then(() => state.ip)
torgeir / domains.js
Last active Jan 15, 2018
Naive available domain lookup
View domains.js
const domains = [""];
const normalize = s => s.replace(/[^a-z]/g, "")
const status = d => new Promise(function (resolve, reject) {
const fn = `handle_result_${normalize(d)}`;
window[fn] = data => resolve(data);
const script = document.createElement("script");
script.src = `${encodeURIComponent(d)}?callback=${encodeURIComponent(fn)}`;
script.onload = () => delete window[fn];
script.onerror = function (err) {
torgeir / diff-csvs.clj
Last active Dec 7, 2017
Script to diff two csv files and output the resulting diff to a csv file.
View diff-csvs.clj
#!/usr/bin/env boot
:dependencies '[[org.clojure/clojure "1.9.0-RC2"]
[org.clojure/data.csv "0.1.4"]])
(require '[ :as csv]
torgeir / node-server-stream-5-minutes.js
Created Oct 23, 2017
Node server that streams dummy content for a number of seconds, useful for testing timeouts
View node-server-stream-5-minutes.js
const http = require('http');
const server = http.createServer(function (req, res) {
res.writeHead(200, {
"content-type": "text/plain",
"transfer-encoding": "chunked"
let i = 0;
You can’t perform that action at this time.