Skip to content

Instantly share code, notes, and snippets.

@johndobrien
johndobrien / gist:3101086
Created July 12, 2012 21:21
Using copy_expert to copy rows to a different database
import psycopg2
from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE
conn_str = "dbname='{db}' user='john' host='localhost' password='john'"
table_sql = "CREATE TABLE bigdata (A INT PRIMARY KEY, b TEXT, c TEXT NOT NULL);"
conn1 = psycopg2.connect(conn_str.format(db='test-1'))
conn2 = psycopg2.connect(conn_str.format(db='test-2'))
@johndobrien
johndobrien / gist:3170211
Created July 24, 2012 14:25
encode a data stream with a 7bit encoded variant
def decode7bit(bytes):
"""Decode the first variant integer in bytes.
This function assumes that bytes begins with an encoded variant of an
integer. It will read one byte at a time until the high order bit is 0 and
the combined value of 7bit integers values will be returned along with how
many bytes have been read.
"""
pos = 0
value = 0
@johndobrien
johndobrien / gist:3371086
Created August 16, 2012 15:27
A really cool script to write stats from postgres to graphite.
#!/bin/bash
# Copyright 2012 Canonical Ltd.
# Author: JuanJo Ciarlante <jjo@canonical.com>
# License: GPLv2
DATABASE=<your databases separated by spaces>
ROLE=master
: ${PUSH_CMD:="nc <your corbon host> <your carbon port>"}
: ${FREQ:=10min}
for db in ${DATABASES};do
(
@johndobrien
johndobrien / gist:3497710
Created August 28, 2012 12:42
filling a u1db with docs
def fill_db(db, count=DOC_COUNT, docsize=STD_DOC_SIZE):
doc_ids = []
if _ in range(count):
doc = db.create_doc({"akey": "*" * docsize})
doc_ids.append(doc.doc_id)
return doc_ids
# ugh...
for i, val in enumerate(my_list):
... do some stuff
my_list.pop(i)
... do more stuff
[23/Feb/2013:09:15:12 -0500] "GET /DevOps/deploy-dashboard?cmd=listkeys HTTP/1.1" 200 167 "-" "mercurial/proto-1.0"
[23/Feb/2013:09:15:12 -0500] "POST /DevOps/deploy-dashboard?cmd=unbundle HTTP/1.1" 500 325 "-" "mercurial/proto-1.0"
var Member = function() {
this.FirstName = ko.observable("");
this.LastName = ko.observable("");
this.Email = ko.observable("");
this.DisplayName = ko.computed(this.getDisplayName, this);
};
CurrentUser.prototype.getDisplayName = function () {
return this.FirstName + " " + this.LastName;
};
CurrentUser.prototype.update = function(response) {
@johndobrien
johndobrien / gist:7603042
Last active January 12, 2018 13:39
A Durandal 2 DialogContext which works with Bootstrap 3
// this is based on the documentation http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals/
// create a dialog context: dialogContext.js
define(['jquery', 'knockout', 'transitions/entrance', 'plugins/dialog', 'bootstrap'],
// Create a dialog using Bootstrap 3
function($, ko, entrance, dialog) {
return {
addHost: function(theDialog) {
var body = $('body');
$('<div class="modal fade" id="myModal"></div>').appendTo(body);
theDialog.host = $('#myModal').get(0);
# Source accepts the protocol s3:// with the host as the bucket
# access_key_id and secret_access_key are just that
s3_file "/var/bulk/the_file.tar.gz" do
source "s3://your.bucket/the_file.tar.gz"
access_key_id your_key
secret_access_key your_secret
owner "root"
group "root"
mode 0644
end
ko.bindingHandlers.btnClick = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var wrappedValueAccessor = function () {
return function (data, event) {
var txt = $(element).text();
$(element).text("Please Wait...");
valueAccessor().call(viewModel, data, event);
$(element).text(txt);
};
};