Skip to content

Instantly share code, notes, and snippets.

View kvannotten's full-sized avatar

kvn kvannotten

View GitHub Profile
@kvannotten
kvannotten / str.go
Created May 8, 2018 09:30
Test golang string concat
package main
import (
"bytes"
"fmt"
"strings"
)
func main() {
049ab8414d2b32c3f5f18dd710dcab4bf1d7d4e123128b4f7d99bf4588fdc5aed2c468518fbfca32969dcbfa690c057fa886a536bce2f521cf72350fef0cd61ed0;Masterlyn
@kvannotten
kvannotten / keybase.md
Last active August 29, 2015 14:13
keybase.md

Keybase proof

I hereby claim:

  • I am kvannotten on github.
  • I am kristofv (https://keybase.io/kristofv) on keybase.
  • I have a public key whose fingerprint is 98E4 229A 1522 1BBE 6B4D 6BAB D893 5439 2922 A5ED

To claim this, I am signing this object:

@kvannotten
kvannotten / connect_socket.swift
Created June 23, 2014 02:58
connecting to sockets in swift
var inputStream : NSInputStream?
var outputStream : NSOutputStream?
func connect() {
var readStream : Unmanaged<CFReadStream>?
var writeStream : Unmanaged<CFWriteStream>?
let host : CFString = NSString(string: self.host)
let port : UInt32 = UInt32(self.port)
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, host, port, &readStream, &writeStream)
@kvannotten
kvannotten / dock_mut.rb
Created May 4, 2014 12:37
Toggle OSx dock's mutability
#!/usr/bin/env ruby
# get current state
immutable = `defaults read com.apple.dock contents-immutable`.to_i == 1
# toggle the state
immutable = !immutable
# write the state
`defaults write com.apple.dock contents-immutable -bool #{immutable ? "YES" : "NO"}`
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
mQINBFJc5fUBEADOZFIatFXbkoeYrbPFf5Ix1UHMcsmmWcNQ2jLoa/aQo9pFgm8p
OQy7+B45XfFYl5QDgqK0dZjtaHLQKbIjqrZU1ZiwjOsXiGmd0man0tnZPC+Ac/b9
dh0Vg6brDhi4ss2WKCABH9NZTmsTQSf85zCn/sKTDWtefa4hEG02GfBpgsHTkAjE
P05I3CFRdXdpH5G0ykTj0YBOXkFpkD9Mzv6uho3QnjIiUqXIVo2em6YVecKEeFFx
CmWplaMlBxhubpnUddTPXGPTogC+GrHlmoUMOSiA2Cj1W+SZYhOj8ThV1Qwv7x/g
Z+O3ZaNKPl3Yijr7gv8gs6nSNS5UjHpXVEMvyVUHnTQsREqQgihHE4pIL0fz6CZ6
tlEmv1i9kclhzt7UzNIu/SAbNwJ2Y6OfvW9839567aVDvnl46JzOqntJ5c8aCfwW
@kvannotten
kvannotten / convert_images.rb
Created October 31, 2013 08:06
Script that allows you to run some manipulations on images in a threaded way. This script uses celluloid to create actors that manipulate the pictures by resizing them and adding a border.
require "celluloid"
DIRECTORY = "PUT DIRECTORY HERE"
PICTURE_EXTENSIONS = %w{ jpg png }
BORDER_SIZE = "3x3"
BORDER_COLOR = "black"
NEW_SIZE = 1200
DO_AUTO_ORIENT = false
WORKERS = 8
@kvannotten
kvannotten / gist:6462682
Created September 6, 2013 11:41
Log of internet connection script
I, [2013-09-04T19:00:01.810680 #58738] INFO -- : Internet is up!
I, [2013-09-04T19:04:49.426047 #58738] INFO -- : Internet down!
I, [2013-09-04T19:06:11.865051 #58738] INFO -- : Internet is up!
I, [2013-09-04T19:07:26.452834 #58738] INFO -- : Internet down!
I, [2013-09-04T19:07:32.854117 #58738] INFO -- : Internet is up!
I, [2013-09-04T19:12:06.356444 #58738] INFO -- : Internet down!
I, [2013-09-04T19:12:34.224192 #58738] INFO -- : Internet is up!
I, [2013-09-04T19:14:01.071976 #58738] INFO -- : Internet down!
I, [2013-09-04T19:14:07.528719 #58738] INFO -- : Internet is up!
I, [2013-09-04T19:15:22.179518 #58738] INFO -- : Internet down!
@kvannotten
kvannotten / check_internet.rb
Last active December 22, 2015 06:48
Due to having a very unstable connection in China, I wrote a script to alert me when my internet is down. If the internet is down, it will say so every 5 seconds until it is back up. If it is up, it will say this once and then shut up. The log messages are a delta.
#!/usr/bin/env ruby
require 'logger'
class SimpleDaemon
def self.start pid, pidfile, outfile, errfile
unless pid.nil?
raise "Fork failed" if pid == -1
write pid, pidfile if kill pid, pidfile
exit
@kvannotten
kvannotten / strcpy_asm.c
Created January 1, 2011 13:48
Copying a string using asm
static inline char * strcpy(char * dest,const char *src)
{
int d0, d1, d2;
__asm__ __volatile__( "1:\tlodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b"
: "=&S" (d0), "=&D" (d1), "=&a" (d2)
: "0" (src),"1" (dest)
: "memory");