Skip to content

Instantly share code, notes, and snippets.

@marufsiddiqui
marufsiddiqui / forms.py
Created June 11, 2013 06:37
# Add a class to a form widget # Modify the default queryset of a foreign key fields
def __init__(self, website, *args, **kwargs):
self.website = website
super(PageForm, self).__init__(*args, **kwargs)
# Modify the default queryset of a foreign key fields
self.fields["page_layout"].queryset = Layout.objects.filter(website=website)
# Add a class to a form widget
self.fields['page_layout'].widget.attrs['class'] = 'nc-popup-select'
self.old_url = self.instance.url
@marufsiddiqui
marufsiddiqui / schema.txt
Created June 16, 2013 20:12
DB Fields for Catalog Management
id -
title - String
orig_air_date - Date
added - Date
updated - Date
tags - Array of strings
stars - Array of strings
studio - String
poster - String
description - String (Text)
app.directive('collection', function () {
return {
restrict: "E",
replace: true,
scope: {
collection: '='
},
template: "<ul><member ng-repeat='member in collection' member='member'></member></ul>"
}
});
/**
* Module dependencies.
*/
var express = require('express');
var http = require('http');
var app = express();
// all environments
app.use(express.favicon());
// Generated on 2013-04-23 using generator-webapp 0.1.7
'use strict';
var path = require('path');
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to match all subfolders:
// 'test/spec/**/*.js'

This is a small collection of scripts showing how to use require.js. It's only one of several ways of setting up a require.js project, but it's enough to get started.

At its core, require.js is about three things:

  1. Dependency management
  2. Modularity
  3. Dynamic script loading

The following files show how these are achieved.

@marufsiddiqui
marufsiddiqui / gist:6260896
Created August 18, 2013 10:09
ssh-favourite-hosts
Host staging
HostName test1.compute-1.amazonaws.com
User ubuntu
IdentityFile ~/id_rsa-default
Host dev
HostName test2.compute-1.amazonaws.com
User root
IdentityFile ~/id_rsa-default
if __name__ == "__main__":
website = raw_input("Enter website name: ")
ws = Website.objects.get(subdomain=website)
print "you entered ", ws.name
page = raw_input("Enter page urls, comma separated for multiple pages: ")
pg = Page.objects.get(url=page,website=ws)
print "you entered ", pg
modules = raw_input("Enter module type and block comma separated for multiple modules: ")
print "you entered ", modules
var utils = require('utils');
var casper = require('casper').create({
verbose: true,
logLevel: 'error',
pageSettings: {
loadImages: false,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
},
clientScripts: ['lib/jquery.min.js'] // Inject jquery library, allows use of $ variables
// articles per page
var limit = 10;
// pagination middleware function sets some
// local view variables that any view can use
function pagination(req, res, next) {
var page = parseInt(req.params.page) || 1,
num = page * limit;
db.articles.count(function(err, total) {
res.local("total", total);