Skip to content

Instantly share code, notes, and snippets.

//
// main.c
// kun
//
// Created by Martin Knoll on 17.10.12.
// Copyright (c) 2012 Martin Knoll. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
1)
public class Median {
public static int median(int a, int b, int c) {
if (a < b) {
if (b < c)
return b;
else
#!/usr/bin/ruby
class Integer
def to_b
Bin.new 0 == self ? [] : [self % 2] + (self / 2).to_b
end
end
import java.awt.Graphics;
public class HelloWorld extends javax.swing.JApplet {
public void paint(Graphics g) {
for (int i = 0; i < 5; i++) {
g.drawString("Hello World", 5, 25 + (25 * i));
}
}
}
#!/usr/bin/env python
def keygen( mac ):
bytes = [int(x, 16) for x in mac.split(':')]
c1 = (bytes[-2] << 8) + bytes[-1]
(s6, s7, s8, s9, s10) = [int(x) for x in '%05d' % (c1)]
(m7, m8, m9, m10, m11, m12) = [int(x, 16) for x in mac.replace(':', '')[6:]]
k1 = (s7 + s8 + m11 + m12) & (0x0F)
@maknoll
maknoll / json2tweet
Created December 28, 2011 23:57
parses json twitter objects from stdin and prints to stdout
#!/usr/bin/env ruby
require 'json'
while line = gets
if json = line.match(/\{.*\}/)
tweet = JSON.parse(json[0], :symbolize_names => true)
puts "@#{tweet[:user][:screen_name]}: #{tweet[:text]}"
end
end
@maknoll
maknoll / PdfboxUmlauts.java
Created August 15, 2011 22:38
Fixes widths of german umlauts when loading ttf fonts with PdfBox
PDFont font = PDTrueTypeFont.loadTTF(document, "putr8a.ttf"); // example font (Utopia)
List<Float> widths = font.getWidths();
for (int i = 1; i <= 22; i++)
widths.add(250f); // add 22 floats to cover all 255 ascii chars
widths.set(246, widths.get(111)); // copy width of o to ö
widths.set(252, widths.get(117)); // u to ü
font.setWidths(widths);