This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras import layers | |
def residual_block(y, nb_channels, _strides=(1, 1), _project_shortcut=False): | |
shortcut = y | |
# down-sampling is performed with a stride of 2 | |
y = layers.Conv2D(nb_channels, kernel_size=(3, 3), strides=_strides, padding='same')(y) | |
y = layers.BatchNormalization()(y) | |
y = layers.LeakyReLU()(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymongo | |
from nltk.data import LazyLoader | |
from nltk.tokenize import TreebankWordTokenizer | |
from nltk.util import AbstractLazySequence, LazyMap, LazyConcatenation | |
class MongoDBLazySequence(AbstractLazySequence): | |
def __init__(self, host='localhost', port=27017, db='test', collection='corpus', field='text'): | |
self.conn = pymongo.Connection(host, port) | |
self.collection = self.conn[db][collection] | |
self.field = field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import os | |
import shlex | |
from subprocess import Popen, PIPE | |
def execute_in_virtualenv(virtualenv_name, commands): | |
'''Execute Python code in a virtualenv, return its stdout and stderr.''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import socket | |
from time import time | |
import psutil | |
def get_outgoing_ip((host, port)): | |
"""Connect to remote host/port, return local IP used by OS""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import shlex | |
from subprocess import Popen, PIPE | |
from IPython.utils.py3compat import unicode_to_str | |
def shebang(line, cell): | |
cmd = shlex.split(unicode_to_str(line)) | |
p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE) | |
out,err = p.communicate(cell) | |
if err: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from subprocess import Popen, PIPE | |
def magic_pypy(line, cell): | |
cmd = ['pypy', '-c', cell] | |
tic = time.time() | |
p = Popen(cmd, stdout=PIPE, stderr=PIPE) | |
p.wait() | |
toc = time.time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
The following example uses this function to calculate the matrix-vector product using | |
a blas/lapack routine: | |
/ 3 1 3 \ / -1 \ | |
| 1 5 9 | * | -1 |. | |
\ 2 6 5 / \ 1 / | |
D2 version based on the C version at http://www.seehuhn.de/pages/linear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To install this init script, you should save mongodb to /etc/init.d/ and mongosharding.conf to /etc/ | |
then run the following commands as root or with sudo: | |
chmod 755 /etc/init.d/mongodb | |
chown root:root /etc/init.d mongodb | |
update-rc.d mongodb defaults | |
This installation procedure was tested on UBUNTU 11.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ubuntu upstart file at /etc/init/mongodb.conf | |
pre-start script | |
mkdir -p /var/lib/mongodb/ | |
mkdir -p /var/log/mongodb/ | |
end script | |
start on runlevel [2345] | |
stop on runlevel [06] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Pure cython version | |
compile with: | |
$ cython cgibbs.pyx | |
$ gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.6 -o cgibbs.so cgibbs.c | |
then import from python shell and call main() | |
''' | |
import random,math, time |
NewerOlder