Skip to content

Instantly share code, notes, and snippets.

View imehr's full-sized avatar

Mehran Mozaffari imehr

View GitHub Profile
@imehr
imehr / .gitconfig
Created September 18, 2011 13:58 — forked from jfexyz/.gitconfig
This file should be renamed ".gitconfig" and placed inside your home directory
##
# This file should be renamed ".gitconfig" and placed inside your home directory.
##
[user]
name = YOUR_NAME
email = YOUR_EMAIL
[github]
user = YOUR_GITHUB_USERNAME
token = YOUR_GITHUB_TOKEN
@imehr
imehr / .profile
Created September 18, 2011 13:58 — forked from jfexyz/.profile
Add the following code to your .profile or .bash_profile
##
# Bash completion scripts
##
if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then
# Git OS X Installer: http://code.google.com/p/git-osx-installer/
. /usr/local/git/contrib/completion/git-completion.bash
elif type brew > /dev/null 2>&1 && [ -f `brew --prefix`/etc/bash_completion ]; then
# Homebrew: http://mxcl.github.com/homebrew/
. `brew --prefix`/etc/bash_completion
elif [ -f /opt/local/etc/bash_completion.d/git ]; then
@imehr
imehr / backbone-tutorial.js
Created January 29, 2012 06:54 — forked from jacob414/backbone-tutorial.js
Minimal example of data handling in Backbone.js
/* Scaled-down Backbone.js demonstration
* By Jacob Oscarson (http://twitter.com/jacob414), 2010
* MIT Licenced, see http://www.opensource.org/licenses/mit-license.php */
$(function() {
window.ulog = function(msg) { $('#log').append($('<div>'+msg+'</div>')); }
// Faking a little bit of Backbone.sync functionallity
Backbone.sync = function(method, model, succeeded) {
ulog('<strong>'+method + ":</strong> " + model.get('label'));
if(typeof model.cid != 'undefined') {

A Backbone.js demo app (Sinatra Backend)

Oct 16 2010

Updates

  • 04/10/2011 - Updated application.js and application.rb thanks to @rebo's comments

In this article, I will walk through some simple steps to get a [demo app][2] up and running with [Backbone.js][3] and [Sinatra][4] on [Heroku][5].

importTemplate: =>
if C2.user.credentials.length
@renderImportConfig()
# when creds are missing, create an error popup
else
content =
message: "Warning: Missing Credentials"
body: "AWS Credentials are required to import Templates"
@imehr
imehr / gist:1835413
Created February 15, 2012 12:39
BackboneJS View
// render() function is a no-op (an empty function).
// Your view should call this function whenever the view needs to be redrawn.
var UserView = Backbone.View.extend(
initialize: function(){
/* ... */
}
render: function(){
/* ... */
}
);
@imehr
imehr / gist:1835449
Created February 15, 2012 12:49
BackboneJS View
/*el is created using the attributes from the view’s tagName, className, or id properties. If none of these is specified, el is an empty div:
*/
var UserView = Backbone.View.extend({
tagName: "span",
className: "users"
});
// Binding a view onto an existing element in the page.
// Make sure the view is set up after the page has loaded.
@imehr
imehr / gist:1844243
Created February 16, 2012 11:34
_.bindAll()
/*
_.bindAll() ensures that all the functions you indicate are always invoked in the specified context. This is especially useful for event callbacks, as their context is always changing.
*/
Account = Backbone.Model.extend({
initialize: function() {
_.bindAll(this, 'removeElement');
},
removeElement: function() {
@imehr
imehr / fiddle.css
Created March 2, 2012 23:39
Using Gist and Jsfiddle
body {
font-family: Helvetica, Verdana
}
p {
padding: 7px 10px;
}
#demo {
border: 1px solid #999;
}
@imehr
imehr / gist:5226810
Created March 23, 2013 07:29
#javascript - Fisher-Yates shuffle
jQuery.fn.shuffleChildren = (function(){
function fisherYatesShuffle(arr) {
// Fisher-Yates shuffle has been proven
// to be more random than the conventional
// arr.sort(function(){return Math.random()-.5})
// http://www.robweir.com/blog/2010/02/microsoft-random-browser-ballot.html
var i = arr.length,