Skip to content

Instantly share code, notes, and snippets.

View swallentin's full-sized avatar

Stephan Wallentin swallentin

View GitHub Profile
@swallentin
swallentin / version.php
Created March 2, 2012 08:17
Find out what version of PHP a website is currently running in
<?php
echo 'Current PHP version: ' . phpversion();
@swallentin
swallentin / TodoView.js
Created September 20, 2012 05:55
Backbone.js ViewTtemplate using Handlebars for templating.
var TodoView = Backbone.View.extend({
tagName: "li",
initialize: function(options) {
_.bindAll(this, "edit");
this.template = Handlebars.compile(options.template || "");
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
@swallentin
swallentin / gist:3754186
Created September 20, 2012 05:56
Backbone.js ListView template using Handlebars for templating.
var TodoListView = Backbone.View.extend({
tagName: "UL",
className: "todos",
initialize: function() {
_.bindAll(this, "addTodo");
},
render: function() {
this.collection.each(this.addTodo);
},
addTodo: function(todo) {
@swallentin
swallentin / Todo.js
Created September 20, 2012 05:57
Backbone.js Model Template
var Todo = Backbone.Model.extend({
urlRoot: '/todos',
defaults: {
"priority": 3
},
validate: function(attrs) {
if (!attrs.title) {
return "cannot have an empty title";
}
}
@swallentin
swallentin / Todos.js
Created September 20, 2012 05:58
Backbone.js Collection Template
var Todos = Backbone.Collection.extend({
url: "/todos",
model: Todo,
parse: function(res) {
return res.response.todos;
},
comparator: function (todo) {
return todo.get("priority");
}
});
@swallentin
swallentin / middleware.js
Created September 20, 2012 06:02
Express.js Middleware Template
module.exports = function(req, res, next) {
console.log(req.method, req.path, req.body);
next();
}
@swallentin
swallentin / Game.js
Created September 20, 2012 06:04
Mongoose.js Model Schema Definition Template
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = Schema.ObjectId
, UserSchema = require('./User').Schema
, GameSchema = new Schema({
'name': { type: String },
'player_a': { type: ObjectId, ref: "User" },
'player_b': { type: ObjectId, ref: "User" },
'score': { type: Number, default: 0}
});
@swallentin
swallentin / AppRouter.js
Created September 20, 2012 06:05
Backbone.js Router Template
var AppRouter = Backbone.Router.extend({
vent: _.extend({}, Backbone.Events),
routes: {
// TODO: index should games-list
"game/:id": "game",
"": "index"
},
index: function() {
var myGames = new Games();
myGames.fetch({
@swallentin
swallentin / Games-RESTful-API-test.js
Created September 21, 2012 03:05
node.js - APIeasy RESTful test template
var APIeasy = require('api-easy')
, assert = require('assert')
, mongoose = require('mongoose');
var suite = APIeasy.describe('Testing the /games RESTful API.');
var game = {
_id: new mongoose.Types.ObjectId,
name: 'new-game'
};
@swallentin
swallentin / Search-form-with-toggles.html
Created September 25, 2012 03:57
Bootstrap: Search form with toggles
<div class="row">
<div class="span2">
<div class="btn-group pull-right" data-toggle="buttons-radio">
<button class="btn active">All</button>
<button class="btn">Starred</button>
</div>
</div>
<div class="span4">
<form class="form-search">
<div class="input-append">