Skip to content

Instantly share code, notes, and snippets.

// querying and cursors
cursor = db.people.find(); null ;
cursor.hasNext() // returns true (if there is another set of results) and false (if not)
cursor.next() // returns the next result and move the cursor foward
// Limiting the set of results returned by the queries
cursor.limit(5); null; // limit the results returned by the cursor (default is 20)
// note: the 'null' keyword is used to prevent the mongoshell from printing that query out
@bodiam
bodiam / gist:6376782
Created August 29, 2013 11:10
Bash script to show the name of branch per module.
#!/bin/bash
txt_green=$(tput setaf 2)
txt_purple=$(tput setaf 5)
txt_reset=$(tput sgr0)
for i in */
do
cd $i
git_branch=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1'/`
@bodiam
bodiam / gist:6376802
Created August 29, 2013 11:14
Git branchname of current module displayed in bash shell. Add this to .bashrc
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
function proml {
local BLUE="\[\033[0;34m\]"
# OPTIONAL - if you want to use any of these other colors:
local RED="\[\033[0;31m\]"
@bodiam
bodiam / dict_to_object.py
Last active December 22, 2015 02:59
Transforming a dict to objects in Python
class Light:
def __init__(self, id, name):
self.id = id
self.name = name
response = {"1": {"name": "bedroom"}, "2": {"name": "kitchen"}}
lights = [Light(id, response[id]["name"]) for id in response]
@bodiam
bodiam / object_to_json_mapping.py
Created September 2, 2013 19:15
Simple Python object to JSON mapping
import json
class Light:
def __init__(self, id, name):
self.id = id
self.name = name
lights = [Light("1", "bedroom"),Light("2","kitchen")]
@bodiam
bodiam / gutenberg_rsync.sh
Created September 8, 2013 18:51
This script mirrors the gutenberg cache of generated file formats.
#!/bin/bash
# This script mirrors the gutenberg cache
# of generated file formats
# By Braddock Gaskill 2013
DIR=/knowledge/data/gutenberg/cache/generated
mkdir -p "${DIR}"
cd "${DIR}"
pwd
while (true); do
@bodiam
bodiam / not_working_sudo_in_java
Created September 9, 2013 23:14
A sudo example for stackoverflow. Note that this on is NOT working.
public static void main(String[] args) throws IOException {
Process pb = new ProcessBuilder("sudo", "ls").start();
OutputStream out = pb.getOutputStream();
out.write(password.getBytes());
String line;
BufferedReader input = new BufferedReader(new InputStreamReader(pb.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
# Fluent Interface Definition
class sql:
class select:
def __init__(self, dbcolumn, context=None):
self.dbcolumn = dbcolumn
self.context = context
def select(self, dbcolumn):
return self.__class__(dbcolumn,self)
# Demo
@bodiam
bodiam / uninstall_gvm.sh
Created October 24, 2013 23:18
Uninstall GVM
#!/bin/bash
if [ ! -d ~/.gvm ]; then
echo "No .gvm directory found in home directory. Are you sure GVM is installed?"
exit 1
fi
rm -rf ~/.gvm
for file in '.bashrc' '.bash_profile' '.zshrc'
do
@bodiam
bodiam / gist:7552076
Created November 19, 2013 20:34
Raspberry Pi WIFI
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid "ssid"