Skip to content

Instantly share code, notes, and snippets.

@akdh
akdh / gorp_tester.rb
Created February 27, 2011 07:47
Runs a compiler and ASM emulator formatting feedback in html.
# GORP Tester
require 'open3'
require 'tmpdir'
unless ARGV.length >= 2
$stderr.puts "usage: path_to_compilerFramework path_to_test_files_or_directory"
exit
end
tests = if ARGV.length == 2 && File.directory?(ARGV[1])
@akdh
akdh / generate_context.rb
Created April 20, 2012 20:42
Generates contexts
require 'iconv'
def content_to_xml(context)
"<context number=\"#{context[:number]}\">
<city>#{context[:city]}</city>
<state>#{context[:state]}</state>
<lat>#{context[:lat]}</lat>
<long>#{context[:long]}</long>
<day>#{context[:day]}</day>
<time>#{context[:time]}</time>
@akdh
akdh / markus_autofill.js
Created June 16, 2012 21:38
Markus auto test field autofill
(function(Prototype) {
Prototype.Version;
$('abc');
var marking_labels=[/Q1\s+Correctness/, /Q2\s+Correctness/, /Q3\s+Correctness/];
var mark_to_tier=[$w("0 1 2 2 3 3 4"),$w("0 1 2 2 3 3 4"),$w("0 1 1 2 2 2 2 3 3 3 4")];
var autotest_labels=[/Question\s+1:\s+(\d+)\/6/,/Question\s+2:\s+(\d+)\/6/,/Question\s+3:\s+(\d+)\/10/];
var contains = function(regex) { return function(element) { return element.textContent.match(regex) } };
var indicies = function(item) { return item[0][item[1]] };
var buttons = function(labels) {
return labels.map(function(regex) {
// IN_FILE should be a file consists of one document per line
// OUT_FILE will be a file that consists of two parts:
// For each document the first part contains:
// DOC_ID DOCUMENT
// For each term the second part contains:
// TERM DOC_ID:POSITION ...
package main
import (
@akdh
akdh / data.json
Created July 13, 2013 16:59
Entity relationship visualizer.
{
"start": "History of Gibraltar",
"nodes": {
"History of Gibraltar": ["Iberian Peninsula", "Mediterranean Sea", "Visigothic Kingdom", "Charles VI"],
"Iberian Peninsula": ["Peninsula", "Europe", "Gibraltar"],
"Peninsula": ["Iberian Peninsula", "Europe"],
"Europe": ["Continent", "Peninsula"],
"Continent": ["Europe"],
"Gibraltar": ["Iberian Peninsula", "British Overseas Territories"],
"British Overseas Territories": ["Gibraltar"],
@akdh
akdh / trec2014context.py
Created April 30, 2014 19:17
TREC 2014 Context Generation
# TREC 2014 Context Generator
#
# This is the script used to generate contexts2014.csv the variables
# filename, username, and contexts2013_filename need to be filled in.
from bs4 import BeautifulSoup
from pandas import read_csv, DataFrame, merge
from random import sample
import requests
@akdh
akdh / index.html
Created April 30, 2014 19:19
TREC 2014 Contexts Map
<html>
<head>
<title>TREC 2014 Contextual Suggestion Track Contexts</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<style type="text/css">
#map { height: 600px; width: 1000px; }
</style>
</head>
<body>
</body>
@akdh
akdh / validate_submission.py
Created July 14, 2014 05:27
Submission validation script used in the TREC Contextual Suggestion Track
#!/usr/bin/env python
from __future__ import print_function
import sys, csv, re
import os.path
def usage():
print("Usage: {0} resultsfile".format(sys.argv[0]))
exit(1)
@akdh
akdh / tagger.py
Created July 15, 2014 22:19
POS Tagger for the 2014 TREC Contextual Suggestion Track
import requests, nltk, math, sqlite3
from pandas import read_csv
from six.moves.urllib.parse import quote
from collections import defaultdict
filename = 'examples2014.csv'
examples = read_csv(filename)
urls = examples['url'].tolist()
@akdh
akdh / read.py
Created July 16, 2014 22:09
Read from Sqlite3 DB
import sqlite3
url = “"
conn = sqlite.connect('fetch.db')
db = conn.curson()
db.execute("SELECT response FROM urls WHERE url = ?", (url,))
response = db.fetchone()[0]
index = response.find('\n\n\n’)
body = response[index+3:]