Skip to content

Instantly share code, notes, and snippets.

@timkuijsten
timkuijsten / tunnel.sh
Created September 9, 2011 11:53
os x ssh proxy
#!/bin/sh
#
# Copyright (c) 2011 Netsend
# Released under the MIT license.
#
###
# create a local ssh SOCKS proxy to RHOST and update OS X proxy settings.
# Tip: make your programs use the default OS X proxy.
#####
@timkuijsten
timkuijsten / .bash_profile
Last active September 27, 2015 04:08
tab complete ssh with known hosts
if [ -f ~/.ssh/known_hosts ]; then
HOSTLIST=$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | sed -e 's/^\[\(.*\)\].*/\1/g' | egrep -v '^[0-9]' | uniq`;)
complete -o bashdefault -o default -W "${HOSTLIST}" ssh
complete -o bashdefault -o default -o nospace -W "${HOSTLIST}" scp
complete -o bashdefault -o default -o nospace -W "${HOSTLIST}" ping
fi
@timkuijsten
timkuijsten / agent.sh
Created October 4, 2011 20:48
load a private key for 24 hours in the ssh-agent
# if we have private keys, load ssh-agent or connect to an already running agent
if [ -r $HOME/.ssh/id_rsa -o -r $HOME/.ssh/id_dsa -o -r $HOME/.ssh/identity ]; then
SSH_SOCKET=$HOME/.ssh/.ssh-socket
# ensure socket
ps -cx | grep -q '[s]sh-agent'
if [ 0 -ne $? ]; then
old_umask=$(umask)
umask 0077
@timkuijsten
timkuijsten / log_writes.patch
Created August 22, 2012 15:56
Emit write event on connection.write
diff --git a/node_modules/mongodb/lib/mongodb/connection/connection.js b/node_modules/mongodb/lib/mongodb/connection/connection.js
index 4b65528..b3f4686 100644
--- a/node_modules/mongodb/lib/mongodb/connection/connection.js
+++ b/node_modules/mongodb/lib/mongodb/connection/connection.js
@@ -115,18 +115,35 @@ Connection.prototype.isConnected = function() {
return this.connected && !this.connection.destroyed && this.connection.writable && this.connection.readable;
}
+var emitDocuments = function(command, connection) {
+ var documents = [];
@timkuijsten
timkuijsten / gist:3492572
Created August 27, 2012 21:46
mongo oplog replicate json over tcp
// default to $main, used in mongod master mode
var oplogCollection = '$main';
// if not master, assume a replicaset is used
if (config.db_mode !== 'master') {
oplogCollection = 'rs';
}
var mongoDb = require("mongodb"),
mongoServer = new mongoDb.Server(config.db_host, config.db_port),
@timkuijsten
timkuijsten / Bye Bye Ubuntu (Desktop)
Last active December 10, 2015 04:18
No Ubuntu for Christmas
Yesterday, after evangelizing Ubuntu for years and running Ubuntu on my
parents desktop since 2009, I finally "relieved" them by giving them
Windows 7 as a gift.
For years I had the hope that every Ubuntu release would get better
than the previous edition. That the vision of Canonical aligned with my
vision of openness and where user rights are put central. I took the
fact that some proprietary things didn't work for granted and thought
we could fight it best by adding weight to the open source movement and
use open source software while demanding open codecs, standards etc.
@timkuijsten
timkuijsten / genpass.sh
Last active February 22, 2017 16:06
Generate strong and easy to type passwords. Tested with OpenBSD 5.2, Ubuntu 10.04, Ubuntu 12.04 and Mac OS X 10.8.
#/bin/sh
# copy to /usr/local/bin
# usage: genpass [length]
LENGTH=12
if [ 0 -lt $(($1)) ]; then
LENGTH=$1
fi
<?php
/*
* Copyright (c) 2017 Tim Kuijsten
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
@timkuijsten
timkuijsten / sshsock
Last active April 10, 2018 20:43
Quick 'n dirty VPN for macOS
#!/bin/sh
# sshsock - Quick 'n dirty VPN for macOS
#
# Usage example:
# Let Apple Mail, Safari and Firefox route all traffic via your ssh server at
# foo.example.com by using a system-wide local SOCKS proxy:
#
# $ sshsock foo.example.com
# Password:
@timkuijsten
timkuijsten / udptun.c
Created July 12, 2018 19:42
unencrypted udp based vpn tunnel
/* A simple unencrypted UDP tunnel between two tunnel devices. */
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <net/if.h>
#include <net/if_tun.h>
#include <netinet6/in6_var.h>