Skip to content

Instantly share code, notes, and snippets.

@kimjoar
kimjoar / 4.diff
Created July 13, 2012 20:17
Step 4 -> 5
var Statuses = function() {
};
Statuses.prototype.add = function(options) {
$.ajax({
url: '/status',
type: 'POST',
dataType: 'json',
data: { text: options.text },
success: options.success
});
@kimjoar
kimjoar / 3.diff
Created July 13, 2012 20:17
Step 3 -> 4
-function addStatus(options) {
+var Statuses = function() {
+};
+Statuses.prototype.add = function(options) {
$.ajax({
url: '/status',
type: 'POST',
dataType: 'json',
data: { text: options.text },
success: options.success
@kimjoar
kimjoar / 2.diff
Created July 13, 2012 20:17
Step 2 -> 3
function addStatus(options) {
$.ajax({
url: '/status',
type: 'POST',
dataType: 'json',
- data: { text: $('#new-status textarea').val() },
- success: function(data) {
- $('#statuses ul').append('<li>' + data.text + '</li>');
- $('#new-status textarea').val('');
- }
We couldn’t find that file to show.
@kimjoar
kimjoar / 1.diff
Created July 13, 2012 19:57
Step 1 -> 2
+function addStatus(options) {
+ $.ajax({
+ url: '/status',
+ type: 'POST',
+ dataType: 'json',
+ data: { text: $('#new-status textarea').val() },
+ success: function(data) {
+ $('#statuses ul').append('<li>' + data.text + '</li>');
+ $('#new-status textarea').val('');
+ }
@kimjoar
kimjoar / create_xml.rb
Created May 23, 2012 06:47
Simple Ruby DSL to generate XML
require './xmldsl'
Twitter = Struct.new :name, :avatar, :text
twitters = []
5.times { twitters << Twitter.new("Jonas", "/profile.png", "Hello World!") }
xml = XML.generate do
html do
body do
twitters.each do |tw|
@kimjoar
kimjoar / RubyXmlDslExercise.md
Created May 23, 2012 06:25 — forked from follesoe/RubyXmlDslExercise.md
Simple Ruby XML DSL exercise implemented by Torgeir and Jonas

Simple Ruby DSL to generate XML

Implemented as an exercise to learn about metaprogramming in Ruby. The DSL is implemented using instance_eval and method_missing.

Usage

require 'xmldsl'

Twitter = Struct.new :name, :avatar, :text
twitters = []
5.times { twitters << Twitter.new("Jonas", "/profile.png", "Hello World!") }
@kimjoar
kimjoar / events-example.js
Created May 2, 2012 12:02
EventEmitter example
var events = new EventEmitter();
var UserView = function(el, user) {
this.el = el;
this.user = user;
// Let's listen for someone emitting the event 'user:showImage', which
// we listen for and then show the user's image.
// The first parameter is the event name, the second is the function
// to call when the event is triggered, and the third is the context
@kimjoar
kimjoar / view-helper.js
Created May 2, 2012 12:02
jQuery view helper
UserView.prototype.$ = function(selector) {
return this.el.find(selector);
}
describe('user view', function() {
it('should be able to show image', function() {
var user = {
image: "user.png"
};
var view = new UserView($('<div></div>'), user);
view.showImage();
// remember that `view.el` is a jQuery object. So now we can call