Skip to content

Instantly share code, notes, and snippets.

@dimitrovs
dimitrovs / gist:27556c0c1598e229cda2
Last active August 29, 2015 14:23
Greedy matching of complex names in CoreNLP XML
# This script matches names like "Mr. Bennet" (and not just "Bennet")
# in the XML output of CoreNLP, which has one word per token
import xml.etree.ElementTree as ET
e = ET.parse('test.xml').getroot()
word_list = []
character_dict = dict()
@dimitrovs
dimitrovs / to_heatmap.py
Last active August 29, 2015 14:26
Convert CSV to heatmap
import numpy as np
import codecs
import matplotlib.pyplot as plt
import sys
import csv
reload(sys)
sys.setdefaultencoding("ISO-8859-1")
in_file = sys.argv[1]
out_file = sys.argv[2]
setInterval(function() {
var ts = Math.round((new Date()).getTime() / 1000);
client.query('BEGIN', function(err, result) {
if (err) {
return console.error('error running query', err);
}
for (var k in big_dict) {
// use hasOwnProperty to filter out keys from the Object.prototype
if (big_dict.hasOwnProperty(k)) {
var symbol = k;
@dimitrovs
dimitrovs / dockerhost.sh
Last active September 17, 2017 20:36
Add the IP of a dockerhost to the /etc/hosts file of a Docker container if not already there.
#!/bin/bash
if [[ -z $(grep dockerhost /etc/hosts) ]]
then
echo `/sbin/ip route|awk '/default/ { print $3 }'` dockerhost >> /etc/hosts
fi
@dimitrovs
dimitrovs / crontab
Created July 31, 2016 00:11
Script to update IPv6 tunnel when IPv4 changes
0,15,30,45 * * * * sh *full path to script here*/*scriptnamehere*.sh &>/dev/null
@dimitrovs
dimitrovs / IndexController.js
Created August 19, 2016 04:55
Sails.js SPA routes
module.exports = {
index: function(req, res) {
res.sendfile(__dirname, 'index.html');
}
};
@dimitrovs
dimitrovs / client_up.sh
Created October 5, 2016 01:48
OpenVPN Client Up Script
#!/bin/bash
#Clear all routes on vpn routing table (this is to make sure there isn't any crap left over from a previous vpn connection
/sbin/ip route flush table 100
#Copy routing table from main routing table into vpn table
/sbin/ip route show table main | grep -Ev ^default | while read ROUTE ; do ip route add table vpn $ROUTE; done
#Add default gateway to vpn routing table
/sbin/ip route add default via ${route_vpn_gateway} dev ${dev} table 100
/sbin/ip rule add from ${ifconfig_local} table 100
events {
worker_connections 4096;
}
http {
client_max_body_size 0;
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:3000/;
@dimitrovs
dimitrovs / gist:124efbfb95ed27616b48bb2fe505c513
Created March 29, 2017 00:22
Start iPython in current directory
docker run -d -v $(pwd):/home/jovyan/work -p 8888:8888 jupyter/minimal-notebook
@dimitrovs
dimitrovs / gist.sh
Created August 27, 2017 04:42
Most useful Docker command
docker images -q | xargs docker rmi