First install https://github.com/dunovank/jupyter-themes
then do jt -t themename
to install a theme.
You can list all available themes by
jt -l
then do jt -t themename
to install a theme.
You can list all available themes by
jt -l
This blog covers various topics from technical tweaks to latest in computational linguistics, Artificial Intelligence, Machine Learning and Wed Data Mining.
>mongodThis will start the deamon.
>mongoTo use a DB do
#include YOU HAVE TO INCLUDE boost/python.hpp within tag markers. char const* greet() { return "hello, world"; } BOOST_PYTHON_MODULE(hello) { using namespace boost::python; def("greet", greet); }
$ pip install ipdbTo insert a breakpoint (hard coded break points) in the code use ipdb.set_trace(). You can insert many breakpoints as you like. To run the code:
$ python mycode.pyWhen the breakpoint is hit, you will be dropped to ipdb prompt, similar to the ipython prompt. Use "c" (continue) command to continue the code until the next breakpoint or until the program ends.
import sparsesvd import ipdb def f(x): print x y = 2 *x ipdb.set_trace() print y z = y * 3 ipdb.set_trace() print z pass if __name__ == "__main__": f(10) print "all done"
nosetests -v test.py
nosetests -v -s test.py
nosetests -v -s test.py:className:test_method
def synchronized(lock): """ Synchronization decorator. """ def wrap(f): def newFunction(*args, **kw): lock.acquire() try: return f(*args, **kw) finally: lock.release() return newFunction return wrap if __name__ == '__main__': from threading import Thread, Lock import time myLock = Lock() class MyThread(Thread): def __init__(self, n): Thread.__init__(self) self.n = n @synchronized(myLock) def run(self): """ Print out some stuff. The method sleeps for a second each iteration. If another thread were running, it would execute then. But since the only active threads are all synchronized on the same lock, no other thread will run. """ for i in range(5): print 'Thread %d: Start %d...' % (self.n, i), time.sleep(1) print '...stop [%d].' % self.n threads = [MyThread(i) for i in range(10)] for t in threads: t.start() for t in threads: t.join()
A = [[x1, x2], [x3, x4]]
B = [[y1, y2], [y3, y4]]
from multiprocessing import Pool from functools import partial import time import sys def doWork(i, x): """ Does the actual work. """ print i time.sleep(2) return (x * i) pass def multi(): """ Does the actual multiprocessing. """ # Create the pool. pool = Pool() # We must convert the doWork to a function of one argument. # This argument will be filled in by an iterator. partialWorker = partial(doWork, x=5) tasks = range(100) p = pool.map_async(partialWorker, tasks) try: results = p.get(0xFFFF) except KeyboardInterrupt: print "Received Ctrl-c" sys.exit(1) pool.close() pool.join() pass if __name__ == "__main__": multi()
$ pygmentize test.py
$ pygmentize -f html -o test.html test.py
$ pygmentize -f html -O full -o test.html test.py
$ pygmentize -S default -f html > style.css
import urllib
import re
httpProxy = "http://85.172.205.91.static.giga-dns.com:3128"
webSite = "http://whatismyipaddress.com/"
if False:
# no proxy.
txt = urllib.urlopen(webSite).read()
if True:
# with proxy.
proxies = {'http':httpProxy}
txt = urllib.urlopen(webSite, proxies=proxies).read()
IPreg = re.compile('import numpy numpy.seterr(all='raise') s = 10000.0 try: x = numpy.exp(s) print x except: print "That is too big!"
python -u myprogram.pyAlternatively, if you are using sys.stdout.write to print messages to the terminal, then you can do sys.stdout.flush() right after the sys.stdout.write() to do the same. This works even with file I/O.
from multiprocessing import Process import os def info(title): print title print 'module name:', __name__ print 'parent process:', os.getppid() print 'process id:', os.getpid() def f(name): info('function f') print 'hello', name c = 0 for i in range(1,100000): for j in range(1, 100000): if i == j: c += 1 pass if __name__ == "__main__": info('main line') p = Process(target=f, args=('bob',)) q = Process(target=f, args=('sam',)) r = Process(target=f, args=('dan',)) s = Process(target=f, args=('david',)) q.start() p.start() r.start() s.start() p.join() q.join() r.join() s.join() pass
For nvidia GPUs do the follwing: nvidia-smi -l 1