Skip to content

Instantly share code, notes, and snippets.

View kballenegger's full-sized avatar

Kenneth Ballenegger kballenegger

View GitHub Profile
@kballenegger
kballenegger / 1-base64.h
Created March 12, 2013 07:28
Base 64 encoding / decoding routines written in C.
// out must be cb_b642bytes_outsize(sizeof(in)-1) aka cb_b642bytes_outsize(strlen(in))
// returns length of out, (which *may* be zero-padded) if return val > cb_b642bytes_outsize
static inline int cb_b642bytes_outsize(int insize) { return ((insize-insize%4)+(insize%4==0?0:4))/4*3; }
int cb_b642bytes(unsigned char *out, const char *in);
// out must be cb_bytes2b64_outsize(sizeof(in))
// returns null-terminated string
static inline int cb_bytes2b64_outsize(int insize) { return ((insize-insize%3)+(insize%3==0?0:3))/3*4+1; }
void cb_bytes2b64(char *out, const unsigned char *in, int in_length);
@kballenegger
kballenegger / crypto_box_test.c
Created March 1, 2013 00:59
A working test of using NaCl's crypto_box.
#include <stdio.h>
#include <sodium/crypto_box.h>
#include <sodium/randombytes.h>
int main(int argc, char *argv[]) {
// payload
unsigned char payload[] = "Hello world, this is a test payload to test NaCl's cipher.";
unsigned char payload_padded[crypto_box_ZEROBYTES + sizeof(payload)] = {0};
for (int i = 0; i < sizeof(payload); i++)
@kballenegger
kballenegger / hn.css
Created February 24, 2013 03:50
Custom Hacker News stylesheet. Edited from something I found on the web.
.comment p, .comment + p {
line-height: 16px;
}
.comment u, .comment u a, .comment u a:visited, .comment + p u, .comment + p u a, .comment + p u a:visited {
color: #777;
text-decoration: none ;
}
.pagetop {
[eye ~/Desktop•dotfiles]$ cat HelloWorldClient.java
//
// Hello World client in Java
// Connects REQ socket to tcp://localhost:5555
// Sends "Hello" to server, expects "World" back
//
// Naveen Chawla <[email protected]>
//
import org.zeromq.ZMQ;
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/kenneth/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
checking for zmq.h... yes
checking for zmq_init() in -lzmq... yes
Cool, I found your zmq install...
creating Makefile
make
compiling rbzmq.c
@kballenegger
kballenegger / desopafy.js
Created January 18, 2012 05:45 — forked from timraymond/desopafy.js
Bookmarklet: Remove SOPA overlay from Wikipedia pages
javascript:%24(%22%23mw-page-base%2C%20%23mw-head-base%2C%20%23content%2C%20%23mw-head%2C%20%23mw-panel%2C%20%23footer%22).css(%22display%22%2C%22inherit%22)%3B%24(%22%23mw-sopaOverlay%22).css(%22display%22%2C%22none%22)
require 'chartboost'
connection = Chartboost::ApiConnection.new
connection.app_id = my_app_id
connection.app_signature = my_app_secret
request = Chartboost::ApiRequest.new
request.controller = :api
request.action = :install
@kballenegger
kballenegger / MainFile.m
Created August 2, 2011 21:54
Forcing category linking in static libraries.
// [...]
#import "NSInvocation+ForwardedConstruction.h"
void linkToMyCategoryProperly(void);
void linkToMyCategoryProperly() {
emptyCFunctionToForceLinkerToIncludeNSInvocationForwardedConstruction(); // make sure it's linked to properly
}
// [...]
<?php
// Adapted by Kenneth Ballenegger
// From php.net
function arguments ($args) {
array_shift($args);
$endofoptions = false;
$ret = array(
@kballenegger
kballenegger / xor.php
Created January 31, 2011 02:49
A toy cypher written in PHP. (I have no idea why I wrote this...)
<?php
function xor_cipher($data, $key) {
$data = bitify($data);
$key = bitify($key);
$cipher = array();
$k_i = 0;
for($d_i=0; $d_i<count($data); $d_i++) {
$d = $data[$d_i];
$k = $key[$k_i];