Skip to content

Instantly share code, notes, and snippets.

@puentesarrin
puentesarrin / FileSplitter.py
Last active February 16, 2021 05:19 — forked from msharp/FileSplitter.py
python script to split a (large) file into multiple (smaller) files with specified number of lines
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
class FileSplitter(object):
def __init__(self):
self.parse_args(sys.argv)
@puentesarrin
puentesarrin / ez_setup.py.diff
Created April 25, 2016 18:30
Setuptools quickfix :)
➜ ~ diff ez_setup.py ez_setup.py.edited
331c331
< url = download_base + zip_name
---
> url = 'https://pypi.python.org/packages/86/ee/622e83b0dbede6d48891ed209fa5ca83fcc485f9b6696cf56796eda40806/{}'.format(zip_name)
import motor
from functools import partial
from tornado import gen, ioloop, web
class MyHandler(web.RequestHandler):
@gen.coroutine
def get(self):
import pymongo
db = pymongo.MongoClient().school
for student in db.students.find():
hws = {s['score']: i for i, s in enumerate(student['scores'])
if s['type']=='homework'}
index = hws[min(hws.keys())]
del student['scores'][index]
@puentesarrin
puentesarrin / zsh.md
Created June 11, 2014 19:29 — forked from tsabat/zsh.md
@puentesarrin
puentesarrin / week_1.txt
Last active August 29, 2015 14:02
M101J Week 1 & 2 Video List
M101J Week 1 Video List
https://www.youtube.com/watch?feature=player_embedded&v=FN10crzDOjk
https://www.youtube.com/watch?feature=player_embedded&v=ysg0vfgg6fI
https://www.youtube.com/watch?feature=player_embedded&v=q2iLKZ1LgjI
https://www.youtube.com/watch?feature=player_embedded&v=CAR42sMkXEo
https://www.youtube.com/watch?feature=player_embedded&v=-KIC1LXxcGM
https://www.youtube.com/watch?feature=player_embedded&v=IAvnMgvHuLw
https://www.youtube.com/watch?feature=player_embedded&v=swhH4q_2Ttc
https://www.youtube.com/watch?feature=player_embedded&v=f-lyGAMnNY4
@puentesarrin
puentesarrin / blocking_vertx.py
Last active August 29, 2015 14:01
vert.x: Samples of blocking and non-blocking Python Web Server
import time
import vertx
server = vertx.create_http_server()
@server.request_handler
def request_handler(req):
if request.uri == '/sleep':
time.sleep(60 * 1)
@puentesarrin
puentesarrin / qualname.py
Created February 18, 2014 20:46
__qualname__
# http://www.python.org/dev/peps/pep-0395/
if sys.version_info >= (3, 3):
def qualname(obj):
if not hasattr(obj, '__name__') and hasattr(obj, '__class__'):
return qualname(obj.__class__)
return '.'.join((obj.__module__,
getattr(obj, '__qualname__', None) or obj.__name__))
else:
def qualname(obj):
@puentesarrin
puentesarrin / gist:8290754
Created January 6, 2014 22:13
Python alternative installation
$ cd /usr/local/src
$ wget http://www.python.org/ftp/python/3.4.0/Python-3.4.0b2.tgz
$ tar -xzf Python-3.4.0b2.tgz Python-3.4.0b2
$ cd Python-3.4.0b2
$ ./configure --enable-shared --prefix=/usr/local
$ make
$ make altinstall
$ python3.4
@puentesarrin
puentesarrin / xxd.py
Created September 15, 2013 02:15
Basic xxd command using Python
# -*- coding: utf-8 -*-
import os.path
import string
import sys
def print_buf(counter, buf):
buf2 = [('%02x' % ord(i)) for i in buf]
print '{0}: {1:<39} {2}'.format(('%07x' % (counter * 16)),
' '.join([''.join(buf2[i:i + 2]) for i in range(0, len(buf2), 2)]),