Skip to content

Instantly share code, notes, and snippets.

@lukhnos
lukhnos / gist:2892699
Created June 8, 2012 00:45
Enumerate all available keyboard layouts on Mac OS X and write out their icons
// need to include <Carbon/Carbon.h> and link against Carbon.framework
// not every layout/input method has TIFF icon
CFArrayRef list = TISCreateInputSourceList(NULL, true);
for (int i = 0; i < CFArrayGetCount(list); i++) {
TISInputSourceRef source = (TISInputSourceRef)CFArrayGetValueAtIndex(list, i);
IconRef icon = TISGetInputSourceProperty(source, kTISPropertyIconRef);
CFStringRef sourceID = TISGetInputSourceProperty(source, kTISPropertyInputSourceID);
@lukhnos
lukhnos / pbkdf2test.c
Created July 19, 2012 05:25
An example of using CommonCrypto's PBKDF2 function
// an example of using CommonCrypto's PBKDF2 function
//
// build with:
//
// clang -o pbkdf2test pbkdf2test.c
//
// test with:
//
// ./pbkdf2test <some plaintext password here>
@lukhnos
lukhnos / mcbopomofo-parser.dot
Created November 1, 2012 05:13
DFA for parsing McBopomofo data.txt (Graphviz)
# Parser DFA for McBopomofo's data.txt
#
# Regular expression equivalent:
#
# (\n*\w\w*\s\w\w*\s\w\w*)*$
#
digraph finite_state_machine {
rankdir = LR;
size = "10";
@lukhnos
lukhnos / OpenVanilla-Info.plist
Created January 27, 2013 03:47
A patch to OpenVanilla's Info.plist to allow CrossOver to use the input method toolset. This is actually a bug of CrossOver – it cannot activate any input method with no input modes. This works around the bug. This is for OpenVanilla 1.0.6.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>12C60</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>OpenVanilla</string>
@lukhnos
lukhnos / encfs-on-darwin-13.md
Last active January 3, 2016 07:39
Installing encfs 1.7.5 on OS X 10.9

Currently it's not possible to install encfs on OS X 10.9 using MacPorts (not without manually changing the portfile at least). You can try Brew, although I don't use it.

Here's how I installed it:

  1. Do sudo port install encfs. This will fail in the last step, and it's ok – the point is to have port install the dependencies for you

  2. Check out the latest stable version of encfs:

    svn co http://encfs.googlecode.com/svn/branches/1.x encfs-1.x
    
  3. Change to encfs-1.x, run:

@lukhnos
lukhnos / encfs-on-ec2.md
Last active April 23, 2018 12:32
Installing encfs on an Amazon EC2 instance

encfs is not available on the default yum repository (I run a micro instance), but it's in the Extra Packages for Enterprise Linux (EPEL) repository. See Amazon's own FAQ on enabling that repository, then all you need is to run yum:

sudo yum install fuse-encfs

As of writing this installs encfs 1.7.4 for you. It's hassle-free, and so it's good.

@lukhnos
lukhnos / whoosh-cjk-analyser.md
Created February 4, 2014 09:12
How to Use Whoosh to Index Documents that Contain CJK Characters (First Take)

Whoosh's default analyzer does not handle CJK characters (in particular Chinese and Japanese) well. If you pass typical Chinese or Japanese paragraphes, often you'll find an entire sentence is treated as one token.

A Whoosh analyzer is consists of one tokenizer and zero or more filters. As a result, we can easily use this recipe from Lucene's CJKAnalyzer:

An Analyzer that tokenizes text with StandardTokenizer, normalizes content with CJKWidthFilter, folds case with LowerCaseFilter, forms bigrams of CJK with CJKBigramFilter, and filters stopwords with StopFilter

Which inspired me to make this first take:

class CJKFilter(Filter):
    def __call__(self, tokens):
@lukhnos
lukhnos / otpbox.py
Created February 6, 2015 08:24
A simple command line pyotp wrapper
import argparse
import json
import pyotp
def main():
parser = argparse.ArgumentParser()
parser.add_argument('json', nargs=1)
parser.add_argument('key', nargs=1)
@lukhnos
lukhnos / PreadBug.java
Last active August 29, 2015 14:23
libcore.io.Posix.preadBytes bug reproducible sample
// To reproduce the bug:
//
// j2objc PreadBug.java
// j2objcc PreadBug.m
// ./a.out PreadBug
//
// You'll see the following exception:
//
// java.io.IOException: pread failed: EBADF (Bad file descriptor)
@lukhnos
lukhnos / build.gradle
Created July 10, 2015 06:03
A typical Java project gradle setup that combines META-INF/services in the "super JAR"
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
// ...
}