Skip to content

Instantly share code, notes, and snippets.

@shanelau
shanelau / timezone
Created November 10, 2014 02:32
时区转化 timezone translate
/**
*
* @param date need translate
* @returns {string} date
*/
function calcTime(date) {
var d = new Date(date);
//Deal with dates in milliseconds for most accuracy
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
@shanelau
shanelau / .jshintrc
Created November 10, 2014 07:51
jsHint
{ "twise": true, //prohibits the use of bitwise operators such as ^ (XOR), | (OR) and others
"camelcase": false, //force all variable names to use either camelCase style or UPPER_CASE with underscores
"curly": true, //requires you to always put curly braces around blocks in loops and conditionals
"eqeqeq": true, //prohibits the use of == and != in favor of === and !==
"es3": false, //tells JSHint that your code needs to adhere to ECMAScript 3 specification
"forin": true, //requires all `for in` loops to filter object's items with `hasOwnProperty()`
"immed": true, //prohibits the use of immediate function invocations without wrapping them in parentheses
"indent": 2, //enforces specific tab width
"latedef": true, //prohibits the use of a variable before it was defined
"newcap": true, //requires you to capitalize names of constructor functions
@shanelau
shanelau / User
Created November 24, 2014 09:32
waterline demo 不使用sails, 连接数据库 without sails
/**
* Copyright (c) 2014 Meizu bigertech, All rights reserved.
* http://www.bigertech.com/
* @author liuxing
* @date 14-11-24
* @description
*
*/
var Waterline = require('waterline');
@shanelau
shanelau / User.test.js
Created November 25, 2014 01:40
sails test before
var bootstrap = require('../../bootstrap.test.js');
var should = require('should');
describe.only('UsersModel', function() {
describe('#find()', function() {
it('should check find function', function (done) {
sails.models.user.find()
.then(function(results) {
// some tests
@shanelau
shanelau / index.javascript
Created November 27, 2014 08:43
安全字符串输出 中文转拼音
var unidecode = require('unidecode');
var safeString = function (string) {
string = string.trim();
// Remove non ascii characters
string = unidecode(string);
// Remove URL reserved chars: `:/?#[]@!$&'()*+,;=` as well as `\%<>|^~£"`
string = string.replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '')
// Replace dots and spaces with a dash
@shanelau
shanelau / index.javascript
Created December 4, 2014 02:43
ember model fixture data
import DS from 'ember-data';
var Article = DS.Model.extend({
title: DS.attr(),
body: DS.attr(),
comments: DS.hasMany('comment',{async:true})
});
Article.reopenClass({
FIXTURES: [
@shanelau
shanelau / weixin_share.javascript
Created December 4, 2014 06:18
微信分享到朋友圈,或者发送给朋友
var imgUrl =
'http://www.bigertech.com/content/images/2014/Dec/wallhaven-34414-1.jpg';
var lineLink = 'http://www.bigertech.com';
var descContent = "这是笔戈科技的博客"; // 小于 100个字
var shareTitle = '分享标题'; // 小于 30个字
var appid = '';
function shareFriend() {
WeixinJSBridge.invoke('sendAppMessage', {
"appid": appid,
@shanelau
shanelau / nginx.conf
Last active August 29, 2015 14:10
nginx 配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@shanelau
shanelau / generate_slug
Last active August 29, 2015 14:11
不重复 url 生成
/**
* Copyright (c) 2014 Meizu bigertech, All rights reserved.
* http://www.bigertech.com/
* @author liuxing
* @date 15/3/19
* @description
*
*/
var unidecode = require('unidecode');
@shanelau
shanelau / 0_reuse_code.js
Last active August 29, 2015 14:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console