Skip to content

Instantly share code, notes, and snippets.

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

billyct billyct

🍎
一只想变成橘子的苹果
View GitHub Profile
// 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>',
'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];
};
@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);
}
@billyct
billyct / promise.js
Created November 3, 2015 20:07 — forked from jish/promise.js
An example "always" behavior for ES6 promises. This only works if you do not create / return intermediate promises.
// A thing I want to do
// This flow only involves **one** promise, for example an ajax call
// None of the subsequent `then` or `catch` calls, return new promises.
var explode = false;
var promise = new Promise(function(resolve, reject) {
if (explode) {