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 / fix-grub-config-gone-bad-steps.sh
Created Oct 27, 2019
Fix grub config gone bad ubuntu
View fix-grub-config-gone-bad-steps.sh
# make the bios boot from a live usb stick
# mount the filesystem and change to it
sudo mkdir /mnt/root
sudo mount /dev/sd2 /mnt/root
sudo mount -t proc none /mnt/root/proc
sudo mount -o bind /dev /mnt/root/dev
sudo chroot /mnt/root /bin/bash
# fix the issues
@torgeir
torgeir / boot-physical-win-disk-from-linux.sh
Created Oct 20, 2019
Boot physical win disk from linux
View boot-physical-win-disk-from-linux.sh
# find e.g. Windows 8 (on /dev/sda2)
fgrep menuentry /boot/grub/grub.cfg
# MAKE SURE NOT TO BOOT FROM THE OS YOU ARE ALREADY IN!!
sudo vim /etc/default/grub
# modify it, like
# GRUB_DEFAULT=0
GRUB_DEFAULT="Windows 8 (on /dev/sda2)"
# then create an image for your disk
@torgeir
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
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) {
You can’t perform that action at this time.