Skip to content

Instantly share code, notes, and snippets.

View terhechte's full-sized avatar
💭
I may be slow to respond.

Benedikt Terhechte terhechte

💭
I may be slow to respond.
View GitHub Profile
@terhechte
terhechte / gist:9699534
Created March 22, 2014 00:58
Use PKCS5_PBKDF2_HMAC_SHA1 from widthin Lua to decrypt aes128 with several roundtrips
functions = {}
aes = require("resty.aes")
local ffi = require "ffi"
ffi.cdef[[
int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
const unsigned char *salt, int saltlen, int iter,
int keylen, unsigned char *out);
]]
@terhechte
terhechte / gist:a8059c45f259b7a5ba01
Created October 12, 2014 15:30
Implement "cond" expression (from Lisp) in Swift
//
// AppDelegate.swift
// testasdfsadf
//
// Created by Benedikt Terhechte on 10/12/14.
// Copyright (c) 2014 Benedikt Terhechte. All rights reserved.
//
import Cocoa
@terhechte
terhechte / csstest1
Last active August 29, 2015 14:16
Test CSS
.iu-collection.cz-collection {
display: none !important;
visibility: hidden !important;
}
div.cz-container div.sc-push div.iu-collection {
display: none !important;
visibility: hidden !important;
}
.pm-category-active {
background-color: #000 !important;
@terhechte
terhechte / gist:4541442
Created January 15, 2013 19:52
Example of how to use the category key/value approach from my blogpost here: http://appventure.me/2011/12/fast-nsdictionary-traversal-in-objective-c.html
#import <Cocoa/Cocoa.h>
@interface NSDictionary (objectForKeyList)
- (id)objectForKeyList:(id)key, ...;
@end
@implementation NSDictionary (objectForKeyList)
- (id)objectForKeyList:(id)key, ...
{
import os
# go through the whole folder, and add all directories, that contain sourcecode
# Which directories to scan
directories = ("MyFantasticProject", "External", "libs")
def find_all_source_directories(parentDir):
def directories_contains_source(files):
for f in files:
@terhechte
terhechte / postgresql-trigger.sql
Last active January 4, 2016 11:49
Postgresql url partition scheme action trigger function
CREATE OR REPLACE FUNCTION url_insert_trigger()
RETURNS TRIGGER AS $$
BEGIN
IF (ascii(NEW.url) in (115)) THEN
INSERT INTO urls_s VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (97, 107)) THEN
INSERT INTO urls_ak VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (98, 108)) THEN
INSERT INTO urls_bl VALUES (NEW.*);
@terhechte
terhechte / urlschemetables.sql
Created January 25, 2014 15:21
postgresql url partition scheme setup
CREATE TABLE urls_s (CHECK (ascii(url) in (115))) INHERITS (urls);
CREATE TABLE urls_ak (CHECK (ascii(url) in (97, 107))) INHERITS (urls);
CREATE TABLE urls_bl (CHECK (ascii(url) in (98, 108))) INHERITS (urls);
CREATE TABLE urls_cj (CHECK (ascii(url) in (99, 106))) INHERITS (urls);
CREATE TABLE urls_de (CHECK (ascii(url) in (100, 101))) INHERITS (urls);
CREATE TABLE urls_fg (CHECK (ascii(url) in (102, 103))) INHERITS (urls);
CREATE TABLE urls_hiv (CHECK (ascii(url) in (104, 105, 118))) INHERITS (urls);
CREATE TABLE urls_mr (CHECK (ascii(url) in (109, 114))) INHERITS (urls);
CREATE TABLE urls_np (CHECK (ascii(url) in (110, 112))) INHERITS (urls);
CREATE TABLE urls_txzyo (CHECK (ascii(url) in (116, 120, 122, 121, 111))) INHERITS (urls);
@terhechte
terhechte / gtk3-swift-package-issues.scala
Last active January 23, 2016 23:21
GTK3 Linux Swift header issues
/**
I tried to get GTK running with Swift. To run this, a Linux machine with a working GTK3
installation is needed (could also work with OSX && brew install gtk+3, however I did not try that);
i.e.
`sudo apt-get install libgtk-3-dev`
Initially I tried with GTK but since GTK has dependencies to a lot of other things, I tried something
simpler, i.e. in this case GDK which has only dependencies to X11.
@terhechte
terhechte / keybase.md
Created February 5, 2016 14:32
keybase.md

Keybase proof

I hereby claim:

  • I am terhechte on github.
  • I am terhechte (https://keybase.io/terhechte) on keybase.
  • I have a public key whose fingerprint is 9637 08F2 4838 F953 6D90 FA3F 7CD9 6B05 258B 7980

To claim this, I am signing this object:

@terhechte
terhechte / slow_kvo_dictionary_example2.m
Created December 7, 2011 20:34
Example 1 of slow and fast NSDictionary access
// Created by Benedikt Terhechte on 07.12.11.
// Appventure.me
//
#import <Foundation/Foundation.h>
#define AKeyPathDictionary(dictionary, A) [dictionary objectForKey:@A]
#define BKeyPathDictionary(dictionary, A, B) [AKeyPathDictionary(dictionary, A) objectForKey:@B]
#define CKeyPathDictionary(dictionary, A, B, C) [BKeyPathDictionary(dictionary, A, B) objectForKey:@C]
#define DKeyPathDictionary(dictionary, A, B, C, D) [CKeyPathDictionary(dictionary, A, B, C) objectForKey:@D]