Skip to content

Instantly share code, notes, and snippets.

@torgeir
torgeir / domains.js
Last active January 15, 2018 20:56
Naive available domain lookup
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 December 7, 2017 20:46
Script to diff two csv files and output the resulting diff to a csv file.
#!/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 October 23, 2017 11:56
Node server that streams dummy content for a number of seconds, useful for testing timeouts
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 October 12, 2017 12:55
Check for running tasks in ThreadPoolExecutor java
public class CalculationExecutor {
private final ThreadPoolExecutor executor;
public CalculationExecutor() {
executor = createThreadPool(1);
}
public void execute(Runnable runnable) {
executor.execute(runnable);
@torgeir
torgeir / index.js
Last active October 8, 2017 14:50
redux-observable example
const Rx = require('rxjs/Rx');
const { createStore, applyMiddleware } = require('redux');
const { createEpicMiddleware, combineEpics } = require('redux-observable');
const inc = n => n + 1;
const reducer = function ({ count } = { count: 0 }, { type } = {}) {
switch (type) {
case "add":
return { count: inc(count) };
@torgeir
torgeir / demo.org
Last active September 19, 2017 16:40
GIt-kurs for nyansatte: Demo
@torgeir
torgeir / connect-wireless-gopro-to-wireless-router-with-two-network-interfaces.md
Last active April 7, 2019 22:50
Connect wireless gopro to wireless router with two network interfaces

Connect wireless gopro to wireless router with two network interfaces

For a wireless router on 192.168.1.1 with two network interfaces, e.g. wlan0 and wlan1, you can expose your gopro's live stream on a port on the router using the following setup.

Connect your machine to wlan0, ssh to your router 192.168.1.1, and run these iptables rules.

iptables -t nat -I PREROUTING -d 192.168.1.1 -j DNAT --to-destination 10.5.5.9 -p tcp --destination-port 8080
@torgeir
torgeir / yarn-two-versions-of-jquery.txt
Created August 23, 2017 07:42
Yarn: Two versions of jquery?
~/Desktop/yarn-jquery-pickadate $ yarn add jquery@2.1.3
~/Desktop/yarn-jquery-pickadate $ yarn add pickadate
~/Desktop/yarn-jquery-pickadate $ cat yarn.lock
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
jquery@2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-2.1.3.tgz#6ec55204673d505d39432c5bf5cfad10e1dbad2e"
@torgeir
torgeir / minimal-redux-async-example.js
Last active March 21, 2018 09:25
Minimal redux example
const initialState = Immutable.Map({ count: 42 });
const actions = {
click: function () {
return { type: "click" };
},
asyncClick: function () {
return function (dispatch) {
setTimeout(() => dispatch(actions.click()), 1000);
@torgeir
torgeir / chrome-async-debug-example.js
Last active August 11, 2017 18:41
Chrome 60 async debugging, clever stepping
// async debugging in chrome 60
// https://developers.google.com/web/updates/2017/05/devtools-release-notes#step-into-async
// cmd/ctrl click result when in `debugger` breakpoint
const sleep = s =>
new Promise(resolve => setTimeout(_ => resolve(s), 1000 * s));
function delayedFetch(url) {
debugger;
return Promise.resolve()