Skip to content

Instantly share code, notes, and snippets.

@theaspect
theaspect / nltk.07.13.py
Created November 22, 2012 18:46
NLTK book chapter 07 task 13
#Pick one of the three chunk types in the CoNLL corpus.
#Write functions to do the following tasks for your chosen type:
#1. List all the tag sequences that occur with each instance of this chunk type.
#2. Count the frequency of each tag sequence, and produce a ranked list in order of decreasing
# frequency; each line should consist of an integer (the frequency) and the tag sequence.
#3. Inspect the high-frequency tag sequences. Use these as the basis for developing a better chunker.
import nltk, sys
from nltk.corpus import conll2000
from nltk.probability import FreqDist
@theaspect
theaspect / nltk.07.15.py
Created November 22, 2012 18:47
NLTK book chapter 07 task 13
#Develop an NP chunker that converts POS-tagged text into a list of tuples, where each tuple
#consists of a verb followed by a sequence of noun phrases and prepositions, e.g. the little cat
#sat on the mat becomes ('sat', 'on', 'NP')...
import nltk
# Tagged corpus
brown = nltk.corpus.brown
# Grammar from chapter 7
grammar = r"""
@theaspect
theaspect / participation.py
Last active December 28, 2015 12:38
Calculates participation in project over time. Usage: 1. run python participation.py 2. edit config.ini 3. set repo=~/path/to/repo and calculate=false 4. run python participation.py 5. set [Alias] and calculate=true 6. run python participation.py last time 7. ????? 8. PROFIT
from __future__ import division
import sys, datetime, string, ConfigParser, textwrap
def count_revs(branch, count, get_alias, output, repo, separator, start, users):
out = open(output, 'w', 0)
# Output header
out.write(separator + string.join(users, separator) + '\n')
for revid in repo.changelog:
@theaspect
theaspect / skypestat.py
Created December 9, 2013 19:04
Calculate Skype conversation statistics
#!/usr/bin/python
#-*- coding: utf-8 -*-
import os, sys, re, sqlite3, operator
if len(sys.argv) >= 2:
dbpath = sys.argv[1]
else:
print "Pass Skype's main.db path:"
print "/home/constantine/.Skype/theaspect/main.db"
@theaspect
theaspect / muterbot.py
Created March 7, 2014 12:19
Funny bot for Skype chats to tell something to annoyers
#!/usr/bin/python
# coding=utf-8
#
# USAGE
#
# Download and install
# https://pypi.python.org/pypi/Skype4Py/
# https://pypi.python.org/pypi/pysqlite
# Edit config
@theaspect
theaspect / demo.sh
Last active August 29, 2015 14:14
Demo history editing in git
#!/bin/bash
#
# Constantine Linnick <theaspect@gmail.com>
# https://gist.github.com/theaspect/09d0c0e516d41bfcdb7f
set -e
BASE="$PWD"
ORIGIN="$PWD/origin"
ALICE="$PWD/alice"
@theaspect
theaspect / Script.java
Created March 4, 2015 07:32
Nashorn two-way binding
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.lang.reflect.InvocationTargetException;
public class Script {
public static void main(String... args) throws ScriptException, IllegalAccessException, InvocationTargetException, InstantiationException {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
engine.eval("" +
@theaspect
theaspect / gist:fe09d76ed2b38f82405d
Created October 5, 2015 14:15
Count number of line in folder
# theaspect at constantine.local in ~/workspace/aaa on git:master o [16:48:17]
$ find . -name '*.java' -exec wc -l {} \; | awk "{s+=int($1);} END {print s}"
418
@theaspect
theaspect / pool.py
Created October 15, 2015 11:54
Python worker pool
#!/usr/bin/python
# -*- coding: utf-8 -*-
import random
import multiprocessing
def counter(x):
cnt = 0
for i in xrange(0,x):
cnt+=1
print "Worker %d counted to %d" % (multiprocessing.current_process().pid, cnt)
return cnt
@theaspect
theaspect / regular.txt
Created March 10, 2016 18:36
Text file for regexp learning
a
ab
abc
abbc
aabb
abcd
aaaa
acbd
dacb
baaa