Skip to content

Instantly share code, notes, and snippets.

View perguth's full-sized avatar

Per Guth perguth

View GitHub Profile
@perguth
perguth / computer
Last active July 23, 2019 14:01
Sleep host when Mosh is idle. Wake up on reconnect.
#!/bin/sh
wake-computer
echo 🚀 Connecting Mosh.
mosh user@computer.y
// https://github.com/cjdelisle/cjdns/blob/77259a49e5bc7ca7bc6dca5bd423e02be563bdc5/doc/proxying.md
function FindProxyForURL(url, host) {
// If we can't resolve this means that this host is IPv4 only. Trying cjdns won't hurt.
// It also make IPv4 only hosts connect ot clearnet IPv6 hosts if proxy is IPv6 capable.
// If we can resolve check if the host is insice cjdns network space.
if (shExpMatch(host, "fc*:*") || !dnsResolve(host) || shExpMatch(dnsResolve(host), "fc*:*")) {
return "SOCKS5 localhost:8080";
}
return "DIRECT";
#!/bin/bash
# Source: https://superuser.com/a/1030779
# standard sshd config path
SSHD_CONFIG=/etc/ssh/sshd_config
# helper functions
function tablize {
awk '{printf("| %-7s | %-7s | %-47s |\n", $1, $2, $3)}'
@perguth
perguth / choo-test.js
Last active August 2, 2016 18:02
Playing around with Yoshs Choo.
const choo = require('choo')
const app = choo()
app.model({
state: { title: 'Set the title' },
reducers: {
update: (action, state) => ({ title: action.value })
},
subscriptions: [
(send) => setInterval(() => {send('print', { payload: 'dog?' })}, 1000)
@perguth
perguth / hyperlog-test.js
Last active August 2, 2016 18:02
Playing around with Mafintoshs Hyperlog.
var hyperlog = require('hyperlog')
var levelup = require('levelup')
var steed = require('steed')
var db1 = levelup('./db1', { db: require('memdown') })
var db2 = levelup('./db2', { db: require('memdown') })
var db3 = levelup('./db3', { db: require('memdown') })
var log1 = hyperlog(db1)
var log2 = hyperlog(db2)
/*
A proper divisor of a positive integer n is any divisor
of n other than n itself.
A number n is called deficient if the sum of its proper
divisors is less than n and it is called abundant if
this sum exceeds n.
As 12 is the smallest abundant number,
1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be
@perguth
perguth / .htaccess
Last active January 28, 2024 19:01
Apache reverse proxy `.htaccess` file eg. for NodeJS. @Uberspace
SetEnvIf Request_URI "^(.*)" PORT=65300
RewriteEngine On
RewriteBase /
# CORS
Header add Access-Control-Allow-Origin "*"
# HTTPS
RewriteCond %{HTTPS} !=on
var inherits = require( 'inherits')
var EventEmitter = require( 'events').EventEmitter
var instance
inherits( Dispatcher, EventEmitter)
module.exports = instance ||
(instance = new Dispatcher())
function Dispatcher (opts){
@perguth
perguth / index.js
Last active September 11, 2015 15:09
signalhub_test
var signalhub = require( 'signalhub')
var argv = require( 'minimist')( process.argv.slice( 2))
var Peer = require('simple-peer')
var uid = require('cuid')()
var log = require('fancy-log')
// hub
var hub = signalhub( 'signalhubTest', [
'http://x:7000' ])
@perguth
perguth / iterate_array.sh
Last active September 8, 2015 15:00
Iterate over an array in Bash.
ARRAY=(
hello
world
)
i=0
while [ $i -lt ${#ARRAY[@]} ]; do
echo ${ARRAY[i]}
((i++))
done