Skip to content

Instantly share code, notes, and snippets.

@dbrandt
dbrandt / jinja_test.sh
Created May 15, 2013 07:41
Simple way to test jinja templates. Depends on Flask (and by extension, Jinja2). Copy shell script to the directory where you have the templates you want to test run then execute script and visit localhost:5000/<template_name>
#!/bin/bash
/bin/chmod 0755 $0
if [ ! -f "jinja_test.py" ]; then
cat <<EOF > jinja_test.py
import os
from flask import Flask, abort, render_template
from jinja2 import FileSystemLoader
app = Flask(__name__)
app.jinja_loader = FileSystemLoader(
@dbrandt
dbrandt / python_logging.py
Created June 13, 2013 07:40
Exhaustive python logging example.
#!/usr/bin/env python
import sys
import logging
# Do this in the top level of your module.
logging.root.setLevel(logging.DEBUG) # Or root logger level might override yours.
fmter = logging.Formatter("%(asctime)s %(levelname)s %(name)s(%(lineno)d): %(message)s")
# h = logging.FileHandler("logfile.log")
h = logging.StreamHandler(sys.stderr)
h.setFormatter(fmter)
diff --git a/datamongo/dbobject.py b/datamongo/dbobject.py
index c824e47..2fe9e21 100644
--- a/datamongo/dbobject.py
+++ b/datamongo/dbobject.py
@@ -146,13 +146,15 @@ class DBObject(DataObject, SchemaValidatorMixIn):
return None
@classmethod
- def find_all(cls, params=None, filter_data=None, limit=100):
- return list(cls.find_iter(params=params, filter_data=filter_data, limit=limit))
function restart_balancer() {
sh.stopBalancer();
while (sh.isBalancerRunning()) {
sleep(1000);
}
sh.startBalancer();
print("Balancer restarted at " + new ISODate() + ".");
}
ERROR in api [/Users/dbr/socmongo/socmongo/views/api.py:140]:
comment/new.html: Invalid entry id: 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
import magic
f = open("/Users/dbrandt/Desktop/Screen Shot 2014-05-26 at 17.44.34.png")
buf = f.read(32)
with magic.Magic() as m:
print m.id_buffer(buf)
"PNG image data, 1094 x 126, 8-bit/color RGB, non-interlaced"
@dbrandt
dbrandt / ping.py
Created February 13, 2015 13:59
RabbitMQ ping
import rabbitpy
def send():
with rabbitpy.Connection() as conn:
with conn.channel() as chan:
ex = rabbitpy.DirectExchange(chan, "ping_ex")
ex.declare()
while True:
m = rabbitpy.Message(chan, "ping")
m.publish(ex, "ping_ex")
@dbrandt
dbrandt / install_from_git_checkout.txt
Last active May 13, 2016 06:28
Test install of loadimpact-cli on OS X
[dbrandt@Daniels-MacBook-Pro|~]
% git clone https://github.com/loadimpact/loadimpact-cli.git
Cloning into 'loadimpact-cli'...
remote: Counting objects: 258, done.
remote: Total 258 (delta 0), reused 0 (delta 0), pack-reused 258
Receiving objects: 100% (258/258), 43.08 KiB | 0 bytes/s, done.
Resolving deltas: 100% (161/161), done.
Checking connectivity... done.
[dbrandt@Daniels-MacBook-Pro|~]
% virtualenv licli
@dbrandt
dbrandt / awsudo.py
Created July 22, 2016 10:33
Set AWS environment (key ID, secret key and token) from AWS CLI credentials
#!/usr/bin/env python
import os
import sys
import pickle
from datetime import datetime, timedelta, tzinfo
import boto3
import botocore
### Keybase proof
I hereby claim:
* I am dbrandt on github.
* I am dbrandt (https://keybase.io/dbrandt) on keybase.
* I have a public key ASCf44IqsQTGrasyo4xohTzlrOdsjQugB9u0G3e0MT0WhAo
To claim this, I am signing this object: