Skip to content

Instantly share code, notes, and snippets.

@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);
@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
#!/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)
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/ruby
class Integer
def to_b
Bin.new 0 == self ? [] : [self % 2] + (self / 2).to_b
end
end
1)
public class Median {
public static int median(int a, int b, int c) {
if (a < b) {
if (b < c)
return b;
else
//
// 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>
require "azure"
require "net/http"
require 'active_support/inflector'
require "random-word"
Azure.configure do |config|
config.account_name = "martinmd"
config.access_key = "P9m7mlh1+jDAcRKvj8PV0pTRuL+2qHJ/YNdRn1YRRpfMwSNSh/QRFoqk3gMM5gqrSZcE3au13mvdbyfrd0vkUg=="
end
class Array
def comprehend &block
return self unless block
head, *tail = self.map(&:to_a)
return head.map(&block).compact if tail.empty?
return head.product(*tail).map(&block).compact
end
end
def sieve list
# Run this once
openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt