Skip to content

Instantly share code, notes, and snippets.

View nod's full-sized avatar
💻
i writes the codes, sometimes.

Jeremy Kelley nod

💻
i writes the codes, sometimes.
View GitHub Profile
class BaseHandler(RequestHandler):
# .... other stuff ....
def _handle_request_exception(self, e):
RequestHandler._handle_request_exception(self,e)
import pdb
pdb.post_mortem()
def bp():
import tornado.web
class route(object):
"""
decorates RequestHandlers and builds up a list of routables handlers
Tech Notes (or "What the *@# is really happening here?")
--------------------------------------------------------
Everytime @route('...') is called, we instantiate a new route object which
@nod
nod / pdbcolor.py
Created March 16, 2011 16:24
syntax highlighting for pdb source listings
# put the following in your usercustomize.py file.
# see https://33ad.org/blog/pycon-2011-and-colorized-pdb-source-listings
# for more info and explanation.
# colorize pdb source output
import pdb
import StringIO
from pygments import highlight
from pygments.lexers import PythonLexer, PythonTracebackLexer
from pygments.formatters import TerminalFormatter
@nod
nod / minimal_ansible_playbook.py
Last active May 23, 2024 12:13
Minimal code to run an Ansible Playbook from within python and get stats back on success or fail
from ansible import playbook, callbacks
# uncomment the following to enable silent running on the playbook call
# this monkey-patches the display method on the callbacks module
# callbacks.display = lambda *a,**ka: None
# the meat of the meal. run a playbook on a path with a hosts file and ssh key
def run_playbook(playbook_path, hosts_path, key_file):
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=0)
@nod
nod / gist:0e12567203e94e3646c1
Created October 23, 2014 04:33
sample location stanzas for nginx to proxy back to couchbase syncgateway
location /syncgw {
proxy_pass http://127.0.0.1:4984/syncgw;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass_header Server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass_header Accept;
@nod
nod / ios_icons
Last active August 29, 2015 14:13
Create iOS icons in the needed sizes from one image on OS X
#!/bin/sh
# usage: ios_icons some_file.png
# output: creates images in needed sizes for iOS icon files
# ex: some_file_SIZE.png
inf=$1
filename=$(basename "$inf")
ext="${filename##*.}"
@nod
nod / textfind.py
Last active February 3, 2016 21:16
Use text search in mongo 3.2+ with pymongo
# For pymongo against mongodb 3.2...
# Given a collection of documents like
# {'textfield': 'cool stuff in a doc', 'other': 'fields...'}
#
# To perform the query, and get results sorted by the textual score:
db.my_collection.create_index([('textfield','text')])
cursor = db.my_collection.find(
{'textfield': 'some string query'},
@nod
nod / readme.md
Created February 19, 2016 16:21
Ionic in a directory... The easy way

local tooling for ionic

Instead of installing bower, gulp, ionic, cordova globally - I prefer to put them in the directory with the project. This way projects can have their own versions as needed.

dev

You'll create a file env.sh that lives at the root of your ionic project that you'll source when you start working to ensure everything is setup properly.

Keybase proof

I hereby claim:

  • I am nod on github.
  • I am nod (https://keybase.io/nod) on keybase.
  • I have a public key whose fingerprint is 67FA B939 5A9C 1A30 5E3F DE2B 4FC8 016B 8E58 67CA

To claim this, I am signing this object:

@nod
nod / uglytest.py
Created September 27, 2017 16:07
import random
import time
s = set()
for x in xrange(1000):
s.add(str(random.randint(1,1000000)))
d = {x:1 for x in s}
n = d.keys()[:400]
n.extend([ str(random.randint(1,1000000)) for i in xrange(1000) ])