Skip to content

Instantly share code, notes, and snippets.

View RemyPorter's full-sized avatar

Remy Porter RemyPorter

View GitHub Profile
#import <Foundation/Foundation.h>
@interface TextProcessor : NSObject {
NSLinguisticTagger* tagger;
}
- (id) initWithLanguage:(NSString*) language;
- (void) setString:(NSMutableString*) str;
- (NSRange) expandToSentenceBreak:(NSRange) original;
- (void) stringEditedInRange:(NSRange) range changeInLength:(NSInteger) delta;
- (void)enumerateTagsInRange:(NSRange)range scheme:(NSString *)tagScheme options:(NSLinguisticTaggerOptions)opts usingBlock:(void (^)(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop))block;
xindent = str(11.553572)
ystart = 894.94238
incr = 907.44238 - 894.94238
def lines(text):
words = text.split()
result = ""
currentLeg = ""
count = 0
for w in words:
from sys import argv
import os
import csv
import re
import subprocess
xindent = str(11.553572)
ystart = 894.94238
incr = 907.44238 - 894.94238
@RemyPorter
RemyPorter / grammar.py
Last active August 29, 2015 14:05
Text Bundler DSL - parsing this file never terminates
from pyparsing import *
from collections import namedtuple
Entry = namedtuple("Entry", "description path section")
__currentsection = None
def __section(section):
global __currentsection
__currentsection = section.Section
@RemyPorter
RemyPorter / hashwords.py
Last active August 29, 2015 14:05
Friendly Hash Printing
import linecache
import math
def wordhash(hash, wordlist="all.short", address_size=4):
words = []
for i in range(0, len(hash), address_size):
hx = "00"
try:
hx = hash[i:i+address_size]
except IndexError as err:
class EffectCompose(EffectMeta):
def __init__(cls, name, bases, dct):
super().__init__(name, bases, dct)
def compose(a,b,abort_on_fail=False):
if not a:
return b
if abort_on_fail:
def f(statecont, *args, **kwargs):
res = a(statecont)
if res.opstate:
import sys
def lift_to_module(module_name, types):
"""Take a list of dynamically generated types, or anything really,
and lift them to the root level of the module.
I mostly use this when I do something like this:
>>> some_data_source = ["Foo", "Bar", "Goo"]
>>> types = [
SomeMetaClass("TypeName"+ i, (object,), inputs)
@RemyPorter
RemyPorter / metaclasses.py
Created October 4, 2014 11:59
I'm building tools to generate a declarative API. The purpose of the API is to describe rules for manipulating a state object, and is specifically designed around describing board game rules.
"""
>>> SomeEffect = Effect("SomeEffect", someFunc)
>>> OtherEffect = Effect("OtherEffect", someFunc)
>>> CompositeEffect = SomeEffect + OtherEffect
>>> newstate = CompositeEffect()(oldstate)
And we can generate effects, too:
>>> effects = [Effect("Do" + e.title(), funcGen(e)) for e in effectTypes]
This is the real strength of this snippet of code- generating variations of behaviors
import random
choices = ["da","ja"]
truth = random.choice(choices)
false =[c for c in choices if c != truth]
false = false[0]
gods = [lambda: truth, lambda: false, lambda: random.choice(choices)]
a = random.choice(gods)
b = a
while b == a:
b = random.choice(gods)

Keybase proof

I hereby claim:

  • I am remyporter on github.
  • I am remyporter (https://keybase.io/remyporter) on keybase.
  • I have a public key whose fingerprint is D840 B879 0B81 8F62 5F75 5BF9 E7DF E43C 3AB9 6896

To claim this, I am signing this object: