Skip to content

Instantly share code, notes, and snippets.

def get_or_none(model, *args, **kwargs):
"""
look for a model instance, return None if it doesn't exists
"""
try:
return model.objects.get(*args,**kwargs)
except model.DoesNotExist:
return None
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
@EyePulp
EyePulp / found .extend() in node.js
Created January 12, 2011 17:26
adding .extend()
Object.defineProperty(Object.prototype, "extend", {
enumerable: false,
value: function(from) {
var props = Object.getOwnPropertyNames(from);
var dest = this;
props.forEach(function(name) {
if (name in dest) {
var destination = Object.getOwnPropertyDescriptor(from, name);
Object.defineProperty(dest, name, destination);
}
@EyePulp
EyePulp / resin.img.burner.sh
Created September 10, 2015 21:44
Make resin.io SD image burning a little less painful on a Mac
#!/bin/bash
echo "------------------------------------------------------------------------"
if [[ "$#" -ne 2 ]]; then
echo "IMG Burner -- Built for macbook pros w/ the SD card slot on the right."
echo " - Insert a blank SD card"
echo " - run with two args - img file and destination disk (typically disk2, disk3, etc. NEVER disk1 or sda1)"
echo " - run $ mount to see what disks are available"
echo " - Example: $ ./resin.img.burn.sh path/to/resin.img disk2"
exit
fi
define([], function() {
/* See also: "Learning Javascript Design Patterns" by Addy Osmani
* http://addyosmani.com/resources/essentialjsdesignpatterns/book/
*
* for examples on how to use pubsub as event aggregator (Mediator)
*
*/
var pubsub = function(){};
(function(q) {
var topics = {}, subUid = -1;