Skip to content

Instantly share code, notes, and snippets.

@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);
}
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
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
@EyePulp
EyePulp / gist:4962327
Last active December 13, 2015 19:28
django templated e-mail using markdown/html -- supports attaching files or streaming file attachments
from django.conf import settings
def email_template(
template_name = None,
template_context = None,
subject = '',
recipients = None,
sender = settings.DEFAULT_FROM_EMAIL,
fail_silently = False,
use_markdown = False,
#!/usr/bin/python
# don't forget each model needs
# class Meta:
# app_label = 'app_name' # or whatever the app name is
PACKAGE = 'project_name.app_name.models' # <--- SET YOUR PACKAGE NAME
import os
define(['ko','ko.mapping','underscore','moment'],
function(ko,mapping,_,moment) {
console.log('dashboard VM loaded:',arguments);
return function(){
var self = this;
};
});
@EyePulp
EyePulp / example.js
Last active December 18, 2015 04:28
knockout.js, jquery, and tastypie: Automattically perform a "PUT" to your model's resource_uri when certain observables change value
// usage inside a vm:
var fooVM = function(){
var self = this;
var resource_uri = ko.observable('/api/v1/foo/');
var bar = ko.observable(1);
var baz = ko.observable(1);
ko.saveOnChange(self,['bar']);
}
var f = new fooVM();
f.bar(2); // causes a PUT to /api/v1/foo/
@EyePulp
EyePulp / gist:5815203
Created June 19, 2013 15:26
Basic attempt @ using knockback to read from a tastypie resource and add to a collection. Wondering how to properly and most succinctly create a new Payment instance on the client side and have it show up in its finished, saved incarnation via the observableCollection. Wondering if there's any two-way binding between the collection and the colle…
var Payment = kb.Model.extend({
urlRoot: '/api/v1/payment_backbone/'
});
var PaymentCollection = kb.Collection.extend({
model: Payment
// Constructor method
, initialize: function(data, options) {
this.limit = options.limit || 20;
@EyePulp
EyePulp / ko.binding.js
Created August 20, 2013 20:06
Simple KO binding for getting context data from within a VM
ko.bindingHandlers.console = {
init: function (element, valueAccessor,allBindingsAccessor) {
console.info('ko.console:',valueAccessor());
},
update: function (element, valueAccessor, allBindingsAccessor) {
console.info('ko.console:',valueAccessor());
}
};
@EyePulp
EyePulp / main.js
Created August 21, 2013 00:27
require.js module example
require(['some_module'], // import your module
function(mm){ // give it a local reference
var MyInstance = new mm({'yo':'ho ho'}); // instantiate it with a value
MyInstance.bar(); // run some functions off of it
}
);