Skip to content

Instantly share code, notes, and snippets.

View evandrix's full-sized avatar
💭
offline

evandrix evandrix

💭
offline
View GitHub Profile
@evandrix
evandrix / new.js
Created December 3, 2012 04:55
jQuery Nested Callbacks using Deferred Object
app.saveRows = function(obj) {
var d = new $.Deferred(),
count = obj.rows.length;
$.each(obj.rows,function(i, row) {
row.parentId = obj.id;
$.post(otherURL,row,function(data2) {
count--;
$.when(app.saveImgs(row))
.then(function() {
if (count == 0) {
@evandrix
evandrix / windows.h__.js
Created November 18, 2012 12:53
windows.h.js INFINITY
var ffi = require('ffi'),
ref = require('ref'),
Struct = require('ref-struct'),
Library = require('./Library'),
Type = ref.Type,
NULL = ref.NULL,
isNull = ref.isNull;
var groups = ['libs', 'types', 'structs', 'callbacks', 'enums'];
@evandrix
evandrix / xor.py
Created November 1, 2012 07:20
Fastest bitwise xor between two multibyte binary data variables
def xor(data, key):
import numpy, math
# key multiplication in order to match the data length
key = (key*int(math.ceil(float(len(data))/float(len(key)))))[:len(data)]
# Select the type size in bytes
for i in (8,4,2,1):
if not len(data) % i: break
@evandrix
evandrix / convert.py
Created October 10, 2012 05:00
Epoch to MSSQL DateTime (hex)
#1262166663 / 2009-12-30 09:51:03.000
epoch = 1262166663L
# 70 years = 2,208,988,800 seconds, 01-01-1900 00:00 to 01:01-1970 00:00
offset = 2208988800L
actual = epoch + offset # no. secs since 1st Jan 1900
num_days = actual / 86400
num_secs = 300*(actual % 86400)
mssql_dt = "0x"+("%08x%08x"%(num_days,num_secs)).upper()
assert mssql_dt == "0x00009CEF00A25634"
@evandrix
evandrix / gist:3711590
Created September 13, 2012 03:11
NLP Readings
Parsing
Klein & Manning: "Accurate Unlexicalized Parsing" (shows that lexicalization is not necessary to achieve reasonably good parsing accuracy)
Klein & Manning: "Corpus-Based Induction of Syntactic Structure: Models of Dependency and Constituency" (a revolution in unsupervised dependency parsing)
Nivre "Deterministic Dependency Parsing of English Text" (shows that deterministic parsing actually works quite well)
McDonald et al. "Non-Projective Dependency Parsing using Spanning-Tree Algorithms" (the other main method of dependency parsing, MST parsing)
Machine Translation
Knight "A statistical MT tutorial workbook" (easy to understand, use instead of the original Brown paper)
Och "The Alignment-Template Approach to Statistical Machine Translation" (foundations of phrase based systems)
Wu "Inversion Transduction Grammars and the Bilingual Parsing of Parallel Corpora" (arguably the first realistic method for biparsing, which is used in many systems)
@evandrix
evandrix / sammple1.scala
Created September 11, 2012 09:50
Codeforces
import java.io.{File, PrintWriter}
import java.util.{Locale, Scanner}
import scala.util.control.Breaks._
object B extends App {
val test = "B-small-attempt1"
val input = new Scanner(new File(test + ".in"))
val output = new PrintWriter(test + ".out")
val T = input.nextInt()
for (t <- 1 to T) {
@evandrix
evandrix / README.md
Created September 11, 2012 00:06
Headless web browsers

Here are a list of headless browsers that I know about:

  • [HtmlUnit][1] - Java. Custom browser engine. JavaScript support/DOM emulated. Open source.
  • [Ghost][2] - Python only. WebKit-based. Full JavaScript support. Open source.
  • [Twill][3] - Python/command line. Custom browser engine. No JavaScript. Open source.
  • [PhantomJS][4] - Command line/all platforms. WebKit-based. Full JavaScript support. Open source.
  • [Awesomium][5] - C++/.Net/all platforms. Chromium-based. Full JavaScript support. Commercial/free.
  • [SimpleBrowser][6] - .Net 4/C#. Custom browser engine. No JavaScript support. Open source.
  • [ZombieJS][7] - Node.js. Custom browser engine. JavaScript support/emulated DOM. Open source.
  • [EnvJS][8] - JavaScript via Java/Rhino. Custom browser engine. JavaScript support/emulated DOM. Open source.
@evandrix
evandrix / README
Created September 5, 2012 23:49
Unix Commands I Abuse Every Day (everythingsysadmin.com)
1. grep dot (view the contents of files prefixed by their filename)
I want to view the contents of a few files but I want each line prepended with the the file's name. My solution?
$ grep . *.txt
jack.txt:Once upon a time
jack.txt:there was a fellow named Jack.
lyingryan.txt:Now that "trickle down economics" has been
lyingryan.txt:tested for 30 years and the data shows it
lyingryan.txt:has been a total failure, candidates
@evandrix
evandrix / script.php
Created September 3, 2012 08:46
Stopwords removal
<?php
if (count($argv) != 4) {
echo("Usage: text file, stop words file, output file.\n");
exit;
}
if (!file_exists($argv[1])) {
exit("Unable to open file $argv[1]!\n");
}
@evandrix
evandrix / gist:3606904
Created September 3, 2012 05:20
Optimising MATLAB
mlint, mex (C/C++ bridge)
Vectorize sensibly.
Use `bsxfun` in lieu of `repmat` where possible.
loop access arrays/matrix data in column-major order to maximize cache hits, since this is the same
order that MATLAB stores the data in
Profile the code
Pay attention to messages from the Code Analyzer.
Use functions instead of scripts.
Don't "poof" variables into any workspaces. Translation, don't use load without a left-hand side;
avoid eval, evalin, and assignin.