Skip to content

Instantly share code, notes, and snippets.

@watert
watert / context.coffee
Created June 13, 2012 02:10 — forked from al6x/context.coffee
Adding context for Express.js req/res cycle
# Adding context for req/res cycle for Express.js.
# With context it would be possible to write more terse code:
#
# app.use ->
# @user = {name: 'Anonymous'}
# @next()
#
# app.get '/', ->
# @res.end "Hello, #{@user.name}"
#
/*
var dom = $("#form"); //empty dom
dom.quickform({
title:"Test Edit",
fields:{
user:"text",
email:"text",
comment:"textarea"
},
save:function(object){
/** Example:
<script src="bootstrap.quickform.js"></script>
<form id="test" class="form hide">
<legend>Hello</legend>
<label for="">Something</label><input type="text" value="hello">
</form>
<script>
var dom = $("#test");
var config = {
title:"Hello World",
@watert
watert / App.js
Last active December 19, 2015 20:59
Minimal Initialization for Backbonejs & jQuery based web application.
// My App
window.App = $.extend(true,window.App||{},{
Views:{},Collections:{},Models:{}
},Backbone.Events);
/* PHP Port for accessing Data example
App._GET = <?=count($_GET)?json_encode($_GET):"{}"?>;
App._DATA = <?=count($data)?json_encode($data):"{}"?>;
*/
@watert
watert / server.coffee
Last active December 19, 2015 20:59
Basic server based on coffee-script & express & underscore
###== Basic server based on coffee-script & express ==
# run by forever:
sudo forever -w -c coffee server.coffee
###
_ = require("underscore")._
express = require "express"
app = express()
console.log "\n--- BEGIN --- @ " + new Date()
### Config Part ###
@watert
watert / bookmarklet.js
Last active December 19, 2015 20:59
Bookmarklet based on loading scripts
// Bookmarklet Example
// javascript:(function(){ })();
// load script For bookmarklet
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "helper.js";
head.appendChild(script);
.modColor(@hue,@sat,@light:85%){
@color:hsl(@hue,@sat,@light);
border-color:@color;
strong,h3,h4,h5,h6 { color:desaturate(darken(@color,15%),10%) }
.mod-header {
background-color:lighten(@color,0.8*(100%-@light));
border-color: lighten(@color,0.7*(100%-@light)); }
.mod-footer {
/*! Copyright
* (c) 2010, Brandon Aaron (http://brandonaaron.net)
* (c) 2012 - 2013, Alexander Zaytsev (http://hazzik.ru/en)
* Dual licensed under the MIT (MIT_LICENSE.txt)
* and GPL Version 2 (GPL_LICENSE.txt) licenses.
*
* Version: 1.3.4
* Requires jQuery 1.3+
* Docs: http://docs.jquery.com/Plugins/livequery
*/
@watert
watert / addcss.js
Created July 19, 2013 09:16
dynamicly add css contents for IE6+ and modern browsers. source: http://stackoverflow.com/questions/3922139/add-css-to-head-with-javascript
/**
* dynamicly add css contents for IE6+ and modern browsers.
* source: http://stackoverflow.com/questions/3922139/add-css-to-head-with-javascript
* example: addcss("strong { color: red }");
*/
function addcss(css){
var head = document.getElementsByTagName('head')[0];
var s = document.createElement('style');
s.setAttribute('type', 'text/css');
if (s.styleSheet) { // IE
@watert
watert / Backbone.QueryModel.js
Last active December 20, 2015 02:49
for filter query dom setting & listening.
/**
* QueryModel based on jQuery,momentjs,backbonejs.
* usage:
* // _GET = {"pre_key":"value","pre_key2":"value2"};
* var query = new QueryModel(_GET,{prefix:"pre"});
* // console.log(query.toJSON());
* // Object {key: "value", key2: "value2"}
* // console.log(query.getUrl())
* // "http://localhost/path/?key=value&key2=value2"
*/