Skip to content

Instantly share code, notes, and snippets.

View meonkeys's full-sized avatar

Adam Monsen meonkeys

View GitHub Profile
var dbs = db.getMongo().getDBNames();
for(var i = 0; i < dbs.length; i++){
print("dropping " + dbs[i]);
db = db.getSiblingDB(dbs[i]);
db.dropDatabase();
}
// see also: http://stackoverflow.com/questions/4727127/mongodb-shell-scripting
// see also: http://stackoverflow.com/a/3010848/156060
@meonkeys
meonkeys / shrinkpdf
Created February 6, 2012 22:53
Bash script to reduce PDF filesize.
#!/bin/bash
# shrinkpdf - Reduce PDF filesize.
# Copyright (C) 2012 Adam Monsen <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
@meonkeys
meonkeys / skype-notify.py
Created August 22, 2012 17:26 — forked from nzjrs/skype-notify.py
Python script to make Skype co-operate with GNOME3 notifications
#!/usr/bin/env python
# Python script to make Skype co-operate with GNOME3 notifications.
#
#
# Copyright (c) 2011, John Stowers
#
# Adapted from skype-notify.py
# Copyright (c) 2009, Lightbreeze
#
#
@meonkeys
meonkeys / FacebookSessionPersistence.php
Created September 24, 2012 19:18 — forked from MattKetmo/FacebookSessionPersistence.php
Quick (and dirty) fix for running tests using FosFacebookBundle
<?php
namespace Foo\BarBundle\Facebook;
use FOS\FacebookBundle\Facebook\FacebookSessionPersistence as BaseFacebookSessionPersistence;
use Symfony\Component\HttpFoundation\Session\Session;
/**
* Quick (and dirty) fix for running tests using FosFacebookBundle.
* It may have unwanted consequences (not tested)!
@meonkeys
meonkeys / repro.php
Created November 6, 2012 16:52
Papertrail API repro
<?php
// Demonstrate Papertrail API issue. This stopped working 2012-11-05.
// workaround: create a new curl handle before every request
$ch = curl_init();
// First request. Output ignored.
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Papertrail-Token: ' . $argv[1]));
@meonkeys
meonkeys / assets_version.php
Created November 17, 2012 00:44 — forked from lavoiesl/assets_version.php
Automatic cache busting using Git commit in Symfony2
<?php
// app/config/assets_version.php
$container->loadFromExtension('framework', array(
'templating' => array(
'engines' => array('twig'),
'assets_version' => exec('git rev-parse --short HEAD'),
),
));
@meonkeys
meonkeys / topCollections.js
Created November 26, 2012 22:02
List largest MongoDB collections
// I wanted to know the top five largest collections in my MongoDB database in
// terms of document count. This MongoDB-specific JavaScript gets the job done.
//
// Edit variables in the config section, then execute like so:
//
// mongo --quiet topCollections.js
// config
var dbname = 'FIXME';
@meonkeys
meonkeys / route53octals.py
Last active December 10, 2015 19:38
Stand-alone sample code for converting some three-character octal escapes in Route 53 DNS domain names to their equivalent low-ASCII characters.
#!/usr/bin/python
# coding: utf-8
import re, unittest
def octalReplace(x):
c = int(x.group(1), 8)
if c > 0x20 and c < 0x2e or c > 0x2e and c < 0x7f:
return chr(c)
else:
@meonkeys
meonkeys / test.py
Last active December 10, 2015 22:49
Python Idiom - don't try to declare instance variables like you might in Java or PHP.
# I was surprised today by Python's class semantics. tl;dr is that
# "pre-declaration" (like you might do in Java or PHP) is unnecessary, and can
# lead to some unexpected results.
#
# See: https://twitter.com/meonkeys/status/289454306707521536
# and: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables
# and: http://stackoverflow.com/questions/664294/just-declaring-a-variable-in-python
# and: http://stackoverflow.com/questions/68645/static-class-variables-in-python
# and: http://stackoverflow.com/questions/207000/python-difference-between-class-and-instance-attributes
@meonkeys
meonkeys / gist:4675618
Last active December 11, 2015 23:18
Mesos SVN r1439229 compile error. Ubuntu 12.10 32-bit desktop. See http://tinyurl.com/m9ob7bc
$ svn checkout https://svn.apache.org/repos/asf/incubator/mesos/trunk mesos-trunk
$ cd mesos-trunk
$ ./bootstrap
...
$ ./configure && make
...
make[2]: Entering directory `/tmp/mesos/mesos-trunk/src'
/bin/bash ../libtool --tag=CXX --mode=compile g++ -DPACKAGE_NAME=\"mesos\" -DPACKAGE_TARNAME=\"mesos\" -DPACKAGE_VERSION=\"0.12.0\" -DPACKAGE_STRING=\"mesos\ 0.12.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"mesos\" -DVERSION=\"0.12.0\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_PTHREAD=1 -DMESOS_HAS_JAVA=1 -DMESOS_HAS_PYTHON=1 -DHAVE_LIBZ=1 -DHAVE_LIBCRYPTO=1 -DHAVE_LIBSSL=1 -DHAVE_LIBCURL=1 -I. -Wall -Werror -DMESOS_WEBUI_DIR=\"/usr/local/share/mesos/webui\" -DMESOS_LIBEXECDIR=\"/usr/local/libexec/mesos\" -I../include -I../third_party/libprocess/include -I../include -I../third_party/boost-1.51.0 -I../thi