Skip to content

Instantly share code, notes, and snippets.

@jayhjkwon
jayhjkwon / server.js
Last active December 19, 2015 13:59
allow cross domain for express
var app = express();
//CORS middleware
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
};
@jayhjkwon
jayhjkwon / Gruntfile.js
Created June 27, 2013 02:51
Gruntfile.js with livereload configuration
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch : {
options: {
livereload: true
},
less : {
tasks : 'less:development',
@jayhjkwon
jayhjkwon / resettable.coffee
Created June 17, 2013 02:45
Reset/Undo in Knockout.js
ko.extenders.resettable = (target, option) ->
if option
original = ko.utils.unwrapObservable(option.initialValue) ? ''
if $.isArray(original)
copiedOriginal = $.extend(true, [], original)
else if typeof original is 'object'
copiedOriginal = $.extend(true, {}, original)
else
copiedOriginal = original
@jayhjkwon
jayhjkwon / main.js
Last active December 17, 2015 19:30
Configuration for requirejs with Marionette and Handlebars template
require.config({
baseUrl: './javascripts',
paths: {
jquery : '../components/jquery/jquery',
domReady : '../components/requirejs-domready/domReady',
underscore : '../components/underscore/underscore',
backbone : '../components/backbone/backbone',
marionette : '../components/marionette/lib/backbone.marionette',
handlebars : '../components/handlebars.js/dist/handlebars',
hbs : '../components/require-handlebars-plugin/hbs',
@jayhjkwon
jayhjkwon / gist:5607477
Last active December 17, 2015 12:09
Change underscore template delimiters from "{% %}" to "{{ }}"
_.templateSettings = {
interpolate : /\{\{\=(.+?)\}\}/g,
evaluate : /\{\{(.+?)\}\}/g
};
@jayhjkwon
jayhjkwon / index.coffee
Created April 10, 2013 08:29
How to use Knockout.js with CoffeeScript
class NewsItem
constructor : (itemText) ->
@content = ko.observable(itemText)
class NewsViewModel
constructor : ->
@items = ko.observableArray()
@itemText = ko.observable()
addItem : ->
@jayhjkwon
jayhjkwon / Gruntfile.js
Last active December 16, 2015 01:08
Compile coffee-script using Grunt v0.4.1, one-to-one basis
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch : {
tasks : 'coffee',
files : ['**/*.coffee']
},
coffee: {
@jayhjkwon
jayhjkwon / index.html
Last active December 15, 2015 11:29
Backbone History API Usage
<a href=''>Home</a>
<a href='about'>About</a>
@jayhjkwon
jayhjkwon / app.coffee
Created March 25, 2013 10:36
Backbone View with CoffeeScript
class AboutModel extends Backbone.Model
defaults:
firstName: 'Hyojung'
class HomeView extends Backbone.View
initialize: ->
@render()
render: ->
templateContent = $('#home-template').html()
@jayhjkwon
jayhjkwon / app.js
Created January 28, 2013 13:55
require.js configuration to use bootstrap
require([
'bootstrap'
],
function (bootstrap) {
}
);
})