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
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]))
(enable-console-print!)
(let [src "(ns t.math)
(defn increase [n] (inc n))"
@torgeir
torgeir / torg.ds
Last active Feb 17, 2019
devilspie workspace layout
View torg.ds
/*
Lookup geometry: /usr/bin/xwininfo
Backup: https://gist.github.com/torgeir/401084929e678640b0cd36b3c92b5f03
*/
(and (is (application_name) "Firefox")
(begin
(set_workspace 1)
(geometry "1387x1138+0-32")))
(and (is (application_name) "emacs-snapshot")
@torgeir
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
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
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
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", "http://ip.jsontest.com/");
console.log(state.ip);
wait(2)
.then(() => state.ip)
.then(console.log);
@torgeir
torgeir / domains.js
Last active Jan 15, 2018
Naive available domain lookup
View domains.js
const domains = ["domain.no"];
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 = `https://das2.hostpartner.no/das/${encodeURIComponent(d)}?callback=${encodeURIComponent(fn)}`;
script.onload = () => delete window[fn];
script.onerror = function (err) {
@torgeir
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
;; https://github.com/boot-clj/boot#install
(set-env!
:dependencies '[[org.clojure/clojure "1.9.0-RC2"]
[org.clojure/data.csv "0.1.4"]])
(require '[clojure.data.csv :as csv]
@torgeir
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;
@torgeir
torgeir / check-for-running-tasks-in-thread-pool-executor.java
Last active Oct 12, 2017
Check for running tasks in ThreadPoolExecutor java
View check-for-running-tasks-in-thread-pool-executor.java
public class CalculationExecutor {
private final ThreadPoolExecutor executor;
public CalculationExecutor() {
executor = createThreadPool(1);
}
public void execute(Runnable runnable) {
executor.execute(runnable);
You can’t perform that action at this time.