Skip to content

Instantly share code, notes, and snippets.

View fwielstra's full-sized avatar

Freek Wielstra fwielstra

View GitHub Profile
@fwielstra
fwielstra / api.js
Created June 14, 2011 15:02
Our controller refactored
module.exports = function(Thread, Post) {
return {
post: function(req, res) {
new Thread({title: req.body.title, author: req.body.author}).save();
},
list: function(req, res) {
Thread.find(function(err, threads) {
res.send(threads);
});
@fwielstra
fwielstra / api.js
Created June 14, 2011 14:46
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* 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');
@fwielstra
fwielstra / app.js
Created June 13, 2011 10:26
Sammy.js - Full example
(function($) {
var app = $.sammy('#main', function() {
this.use('Template');
this.get('#/', function(context) {
this.load('thread')
.then( function(threads) {
$.each(threads, function(i, thread) {
context.render('templates/thread.template', {thread : thread})
.appendTo(context.$element());
});
@fwielstra
fwielstra / app-backbone.js
Created June 13, 2011 10:25
The same application in Backbone.js
$(function() {
window.ThreadController = Backbone.Controller.extend({
initialize: function() {
this.threadListModel = new ThreadListModel;
this.threadListView = new ThreadListView;
Backbone.history.start();
},
routes: {
"/" : "listThreads"
@fwielstra
fwielstra / app.js
Created June 13, 2011 10:24
Sammy.js - Do a POST on the back-end
this.post('#/thread', function(context) {
$.post('thread', this.params);
this.redirect('#/thread/' + this.params.title);
});
@fwielstra
fwielstra / thread.html
Created June 13, 2011 10:24
A thread display template
<pre>
<div class="thread">
<div class="thread-title">
<a href="#/thread/<%= thread.title %>"><%= thread.title %></a>
</div>
<time><%= thread.postdate %></time>
<div class="thread-author"><%= thread.author %></div>
</div>
</pre>
@fwielstra
fwielstra / app.js
Created June 13, 2011 10:22
Sammy.js - Load data from an API
this.get('#/', function(context) {
this.load('thread')
.then( function(threads) {
$.each(threads, function(i, thread) {
context.render('templates/thread.template', {thread : thread}).appendTo(context.$element());
});
});
});
@fwielstra
fwielstra / app.js
Created June 13, 2011 10:21
Sammy.js - Basic application
(function($) {
var app = $.sammy('#main', function() {
this.get('#/', function(context) {
alert('index!');
});
});
$(function() {
app.run('#/');
});
@fwielstra
fwielstra / WebDriverUtils.java
Created May 16, 2011 09:48
Workaround for clicking elements from a WebDriver test in Internet Explorer
public static void clickElement(WebDriver driver, By condition) {
WebElement sbutton = driver.findElement(condition);
sbutton.sendKeys("\n");
try {
sbutton = driver.findElement(condition);
sbutton.click();
} catch (NoSuchElementException e) {}
}
@fwielstra
fwielstra / WebDriverSupplier.java
Created May 16, 2011 09:26
Only add the Internet Explorer WebDriver instance when the running system is Windows.
if (System.getProperty("os.name").startsWith("Windows"))
suppliers.add(INTERNET_EXPLORER_SUPPLIER)
}