Skip to content

Instantly share code, notes, and snippets.

@endpnt
endpnt / mail2graph.py
Created July 26, 2011 10:38
create large social graphs / .gml from raw email data with igraph
#!/usr/bin/env python
from sys import argv, exit
from os import listdir, path
from email.Parser import Parser
from email.utils import parsedate, parseaddr
import cPickle as pickle
import sys
import itertools
import igraph
@endpnt
endpnt / text_selection_with_childNodes.js
Created April 19, 2011 00:32
find actual text start and end position of a selected text, even with childNodes present.
var offset = 0;
var selection = window.getSelection();
var range = selection.getRangeAt(0);
var start = range.startOffset;
var end = range.endOffset;
if ( selection.baseNode.parentNode.hasChildNodes() ) {
for ( var i = 0 ; selection.baseNode.parentNode.childNodes.length > i ; i++ ) {
var cnode = selection.baseNode.parentNode.childNodes[i];
if (cnode.nodeType == document.TEXT_NODE) {