Skip to content

Instantly share code, notes, and snippets.

@johnnncodes
johnnncodes / gist:5276195
Created March 30, 2013 10:09
Backbone.js and Marionette.js references
http://backbonejs.org/
http://marionettejs.com/
https://github.com/documentcloud/backbone/wiki/Tutorials,-blog-posts-and-example-sites
http://backbonefu.com/2011/11/modifying-your-urls-on-the-fly-using-the-request-method-with-sync-in-backbone-js/
http://addyosmani.github.com/backbone-fundamentals/#marionette
http://addyosmani.github.com/backbone-fundamentals/#memory-management
https://github.com/jsoverson/todomvc/tree/master/labs/architecture-examples/backbone_marionette
http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/
http://davidsulc.com/blog/2012/04/22/a-simple-backbone-marionette-tutorial-part-2/
http://davidsulc.github.com/backbone.marionette-collection-example/
@johnnncodes
johnnncodes / gist:7278495
Created November 2, 2013 12:38
Django Forms ChoiceField Snippets
class SearchForm(SearchForm):
city = forms.ChoiceField(required=False)
province = forms.ChoiceField(required=False)
def __init__(self, *args, **kwargs):
# DEMO: to get list of fields w/ changed data
# example: check if city choice data has changed
if 'city' in self.changed_data:
self.fields['city'].widget.attrs['class'] = 'show'
@johnnncodes
johnnncodes / gist:7941786
Created December 13, 2013 09:17
Get nearby placenames using geonames.
http://api.geonames.org/findNearbyPostalCodesJSON?postalcode=4501&country=PH&radius=30&maxRows=30&username=demo
@johnnncodes
johnnncodes / api.js
Created December 23, 2013 16:16 — forked from fwielstra/api.js
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
<?php
if (Config::has('sentry.key')) {
$bufferHandler = new Monolog\Handler\BufferHandler(
new Monolog\Handler\RavenHandler(
new Raven_Client(Config::get('sentry.key')),
Monolog\Logger::WARNING
)
);
@johnnncodes
johnnncodes / gist:8176318
Last active January 1, 2016 17:19
Using custom validation messages in Sails.js by Rifat (itsrifat) - https://github.com/itsrifat Reference: https://github.com/balderdashy/sails/issues/1173#issuecomment-31327958
// make a module in node_modules named 'my-validation-utils'. create a index.js file there. and put the following content there:
var user = {
email:{
required:'Email Required',
email:'Should be an email'
},
name:{
required:'name required'
}
@johnnncodes
johnnncodes / gist:8436644
Created January 15, 2014 13:54
Using custom validation messages in Sails.js. Credits to: sfb_
/**
* Takes a Sails Model object (e.g. User) and a ValidationError object and translates it into a friendly
* object for sending via JSON to client-side frameworks.
*
* To use add a new object on your model describing what validation errors should be translated:
*
* module.exports = {
* attributes: {
* name: {
* type: 'string',
@johnnncodes
johnnncodes / gist:8683891
Created January 29, 2014 08:29
Cities auto complete separated by commas using jQuery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/themes/flick/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<style type="text/css">
.ui-menu .ui-menu-item a,.ui-menu .ui-menu-item a.ui-state-hover, .ui-menu .ui-menu-item a.ui-state-active {
font-weight: normal;
margin: -1px;
text-align:left;
font-size:14px;
}
// 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);