Skip to content

Instantly share code, notes, and snippets.

View jinlong's full-sized avatar

涂鸦码龙 jinlong

View GitHub Profile
@jinlong
jinlong / server.js
Created January 15, 2014 07:59
Node.js as a simple static files server
var fs = require("fs");
var express = require("express");
var host = "127.0.0.1";
var port = 1234;
var index = fs.readFileSync('index.html');
var app = express();
app.use(app.router); //use both root and other routes below
app.use(express.static(__dirname + "/")); //use static files in ROOT/public folder
@jinlong
jinlong / article.html
Last active September 22, 2016 09:50
Express blog demo.
<h1>{{blog.title}}</h1>
Published: {{blog.published}}
<p/>
{{blog.body}}
@jinlong
jinlong / Gruntfile.js
Last active January 1, 2016 03:09
Grunt config
module.exports = function(grunt) {
// 项目配置.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
@jinlong
jinlong / var-fun-hoisting
Created September 9, 2013 09:01
变量,函数提升
//变量提升
var name = "Baggins";
(function () {
// Outputs: "Original name was undefined"
console.log("Original name was " + name);
var name = "Underhill";
// Outputs: "New name is Underhill"
@jinlong
jinlong / revealing-module-pattern
Created September 9, 2013 08:52
Revealing Module Pattern(揭示模块模式):暴露的全局变量和局部变量,保持语法一致。
var module = function(){
var current = null;
var labels = {
'home':'home',
'articles':'articles',
'contact':'contact'
};
var init = function(){
};
var show = function(){
@jinlong
jinlong / module-pattern
Created September 4, 2013 07:58
module pattern 模块模式。
var Module = (function(){
var privateProperty = 'foo';
function privateMethod(args){
//do something
}
return {
publicProperty: "",
@jinlong
jinlong / jsProbability.js
Last active November 24, 2016 08:28
javascript Math.random() 写了个概率函数(项目中要用,记录一下)
//probability : 0.6(60%)
var getRandom = function(probability){
var probability = probability*10 || 1;
var odds = Math.floor(Math.random()*10);
if(probability === 1){return 1};
if(odds < probability){
return 1;
}else{
return 0;
@jinlong
jinlong / accessPrivateVal.js
Created April 28, 2013 09:33
prototype 原型链的方法访问局部变量。
var ClassA = function(){
var a = 111;
this.b = 222;
this.show = function(){
alert(a)
};
};
ClassA.prototype.constructor = ClassA;
ClassA.prototype.showme = function(){
this.show();
@jinlong
jinlong / globalVal
Created April 28, 2013 09:07
用 this 定义的方法可以访问局部变量 a,在 prototype 里定义的方法不能访问局部变量 a; 用 this 定义的方法,在 prototype 上定义的方法均可以访问全局变量 b;
var ClassA = function(){
var a = 111;
this.b = 222;
this.show = function(){
alert(this.b)
}
};
ClassA.prototype.constructor = ClassA;
ClassA.prototype.showme = function(){
alert(this.b)