Skip to content

Instantly share code, notes, and snippets.

@watert
watert / markdown-body.css
Last active August 29, 2015 14:09
github markdown doc style extracted from github page
.markdown-body { overflow: hidden; font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif; font-size: 16px; line-height: 1.6; word-wrap: break-word }
.markdown-body>*:first-child { margin-top: 0 !important }
.markdown-body>*:last-child { margin-bottom: 0 !important }
.markdown-body .absent { color: #c00 }
.markdown-body .anchor { position: absolute; top: 0; bottom: 0; left: 0; display: block; padding-right: 6px; padding-left: 30px; margin-left: -30px }
.markdown-body .anchor:focus { outline: none }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { position: relative; margin-top: 1em; margin-bottom: 16px; font-weight: bold; line-height: 1.4 }
.markdown-body h1 .octicon-link, .markdown-body h2 .octicon-link, .markdown-body h3 .octicon-link, .markdown-body h4 .octicon-link, .markdown-body h5 .octicon-link, .markdown-body h6 .octicon-link { display: none; color: #000; vertical-align: middle }
.markdown-body h1:hover .ancho
@watert
watert / jQuery.directive.coffee
Last active August 29, 2015 14:08
jQuery based simple directives by coffeescript
// based on requirejs and backbone style views currently
$.fn.directive = (method,options)->
$dom = $(this)
if not method #init
viewName = $dom.attr("directive")
if viewName then require ["directive/#{viewName}"], (View)->
view = new View(el:$dom[0])
isRender = $dom.attr("render")
if isRender=="" or isRender
view.render()
@watert
watert / gdutgeek_blogs.md
Last active August 29, 2015 14:08
gdutgeek
@watert
watert / timer.coffee
Created October 14, 2014 14:48
Minimal timer in coffeescript
timer = do ->
start = (new Date).getTime()
(log...)->
time = ((new Date).getTime()-start)/1000
console.warn "timer: ",time, log...
@watert
watert / gruntfile.coffee
Last active August 29, 2015 14:07
require config with bower
###
Gruntfile example for requirejs optimizing and less files watching
###
module.exports = (grunt) ->
out = (path)-> "../public-dist/#{path}"
grunt.initConfig
requirejs:
options:
mainConfigFile: "../public/require-config.js"
baseUrl: "../public"
@watert
watert / .htaccess
Last active August 29, 2015 14:07
Backbone Router Example
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
@watert
watert / utilView.coffee
Last active August 29, 2015 14:06
util.js / coffee without libs
View = do ->
extend = (obj,objs...)->
while o = objs.shift()
obj[k] = o[k] for k of o
return obj
class BaseView
constructor:(o={})->
@el = o.el
@$el = $(o.el)
@initialize?()
@watert
watert / amd.factory.coffee
Created September 21, 2014 08:06
AMD Factory for CoffeeScript
if typeof define == 'function' && define.amd then define(["jquery"],factory)
else factory(jQuery)
factory = ($)->
## Do Something
@watert
watert / backbone.view.minimal.coffee
Last active August 29, 2015 14:06
Minimal Backbone View without backbone framework for minimal web app
class BaseView
constructor:(options)->
@options = options
@el = options.el
@$el = $(@el)
@initialize?(options)
@watert
watert / model.router.coffee
Created July 30, 2014 09:41
RestfulAPI router with expressjs and mongoose
# usage: app.use "/[collectionName]", require("./routes/[collectionName]")
express = require('express')
class ModelRestfulRouter
findOne:(req,res)->
@model.findById req.params.id,(err,data)->
unless err then res.json(data)
find:(req,res)->
query = req?.query or {}