Skip to content

Instantly share code, notes, and snippets.

View billyct's full-sized avatar
🍎
一只想变成橘子的苹果

billyct billyct

🍎
一只想变成橘子的苹果
View GitHub Profile
'use strict';
var arr = [ 1, 2, 3, 4, 5 ];
var fnArr = [];
// Wrong 1
for (var i = 0; i < arr.length; i++) {
fnArr[i] = function() {
return arr[i];
};
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
# This little gist shows how to easily internationalize your application using the meteor-just-i18n package.
# Package repository: https://github.com/subhog/meteor-just-i18n/
# 1. Installing the package with Meteorite.
$ mrt add just-i18n
ion $ cd ..
ion $ rm -Rf my-test-project/
ion $ mrt uninstall --system
Deleting ~/.meteorite. Note that previously installed projects will no longer work...
ion $ mrt create my-test-project
Fetching Meteor (branch: master)...
Downloading Meteor development bundle...
######################################################################## 100.0%
my-test-project: created.
<head>
<title>meteor_servercall</title>
</head>
<body>
{{> simple}}
{{> passData}}
</body>
<template name="simple">
app.use(express.methodOverride());
// ## CORS middleware
//
// see: http://stackoverflow.com/questions/7067966/how-to-allow-cors-in-express-nodejs
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, Authorization');
/*
*usage: <textarea ui:pagedown-bootstrap ng:model="box.content"></textarea>
*/
myApp.directive('uiPagedownBootstrap', function() {
var nextId = 0;
return {
require: 'ngModel',
replace:true,
template:'<div class="pagedown-bootstrap-editor"></div>',
@billyct
billyct / casper.addcookies.js
Created September 16, 2015 00:19
casper js add cookies,extend phatom.addCookie()
casper.__addCookies = function (cookies) {
if (Array.isArray(cookies)) {
cookies.forEach(function(cookie) {
if (typeof cookie === 'object') {
phantom.addCookie(cookie);
} else {
this.log('its a object like {name: xxxx, value: xxxx...}?', 'warning');
}
});
@billyct
billyct / gulpfile.js
Created September 30, 2015 17:38 — forked from danharper/gulpfile.js
New ES6 project with Babel, Browserify & Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
@billyct
billyct / WebStorage.js
Created October 13, 2015 14:27 — forked from heyimalex/WebStorage.js
localStorage sync with redux
export default class WebStorage {
constructor(key, storageArea = window.localStorage) {
this.key = key;
this.storageArea = storageArea;
}
load(defaultValue) {
const serialized = this.storageArea.getItem(this.key);
return serialized === null ? defaultValue : this.deserialize(serialized);
}