Skip to content

Instantly share code, notes, and snippets.

View iolo's full-sized avatar

Dongsu Jang iolo

View GitHub Profile
@iolo
iolo / classlist.js
Created December 10, 2011 08:43
emulate html5 classList api with javascript.
(function () {
if (document.documentElement.classList) { // html tag has no 'classList' property
Object.defineProperty(HTMLElement.prototype, 'classList', {
get: function () {
return new function(node) {
var self = node.className.trim().split(/\s+/);
self.item = function (index) {
return self[index];
};
@iolo
iolo / bind.js
Created December 13, 2011 02:04
emulate ecmascript 5 function bind with javascript.
(function () {
"use strict";
if (typeof Function.prototype.bind !== 'function') {
console.log('mimic Function.prototype.bind...');
/**
* https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
*
* @param {object|null} ctx
require 'sinatra'
get '/hello/:name' do |name|
'Hello, #{name}’
end
import cc.spray._
trait HelloService extends Directives {
val helloService = {
path("hello" / PathElement) { name =>
get {
completeWith { “hello, “ + name }
}
}
}
<script type="text/template" id="item-template">
<div class="view">
<input class="toggle" type="checkbox" <%= done ? 'checked="checked"' : '' %> />
<label><%- title %></label>
<a class="destroy"></a>
</div>
<input class="edit" type="text" value="<%= title %>" />
</script>
<script type="text/javascript">
var Todo = Backbone.Model.extend({
<select data-bind="options: tickets, optionsCaption: 'Choose...', optionsText: 'name', value: chosenTicket"></select>
<button data-bind="enable: chosenTicket, click: resetTicket">Clear</button>
<p data-bind="with: chosenTicket">
You have chosen <b data-bind="text: name"></b>
($<span data-bind="text: price"></span>)
</p>
<script type="text/javascript">
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'pic', type: 'string'}
]
});
var myStore = Ext.create('Ext.data.Store', {
package controllers;
import play.*;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
public static Result index() {
package controllers
import play.api._
import play.api.mvc._
object Application extends Controller {
def index = Action {
Ok(views.html.index("Hello, World!"))
}
@(tasks: List[Task], taskForm: Form[String])
@import helper._
@main("Todo list") {
<h1>@tasks.size task(s)</h1>
<ul>
@tasks.map { task =>
<li>
@task.label