Skip to content

Instantly share code, notes, and snippets.

View fredyang's full-sized avatar

Fred Yang fredyang

View GitHub Profile
@fredyang
fredyang / jquery.ba-simple-ajax-mocking.js
Created December 8, 2011 02:52 — forked from cowboy/jquery.ba-simple-ajax-mocking.js
Simple jQuery (1.5+) AJAX Mocking (requires JSON, tested in jQuery 1.7))
/*!
* Simple jQuery (1.5+) AJAX Mocking - v0.1.0 - 11/16/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($) {
@fredyang
fredyang / silly-array-shuffle.js
Created December 8, 2011 15:16 — forked from cowboy/silly-array-shuffle.js
JavaScript: Silly Array Shuffle
// Array.indexed(4) returns [0, 1, 2, 3]
Array.indexed = function(n) {
var result = [];
while (n--) {
result[n] = n;
}
return result;
};
// Shuffle an array in a not too efficient way.
@fredyang
fredyang / ECMAScript5.js
Created February 27, 2012 02:05 — forked from think49/ECMAScript5.js
ECMAScript5.js : ES5 準拠のメソッドを定義するJavaScriptライブラリ
/**
* ECMAScript5.js (ECMA-262 Edition 5)
*
* @version 1.0
* @author think49
*/
// 15.4.3.2 Array.isArray ( arg )
//
// 1. If Type(arg) is not Object, return false.
<script type="text/ng-template" id="one.html">
<div>This is first template</div>
</script>
<script type="text/ng-template" id="two.html">
<div>This is second template</div>
</script>
// 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!"
// Console arguments testing
var apc = [].slice;
(function(){
console.log( apc.call(arguments) );
})( "false", 1, undefined, null, ["foo","bar","baz"], {a:1,b:2}, false );
(function(){
console.log.call( console, apc.call(arguments) );
@fredyang
fredyang / SassMeister-input-HTML.html
Created January 29, 2014 06:36 — forked from una/SassMeister-input-HTML.html
Generated by SassMeister.com.
<!-- @una made this -->
<ul class="color-list">
<li class="color-box brick-red"></li>
<li class="color-box strawberry"></li>
<li class="color-box deep-orange"></li>
<li class="color-box tangerine"></li>
<li class="color-box gold"></li>
<li class="color-box sunshine"></li>
<li class="color-box grass-green"></li>
# Thanks to this post:
# http://blog.ikato.com/post/15675823000/how-to-install-consolas-font-on-mac-os-x
$ brew install cabextract
$ cd ~/Downloads
$ mkdir consolas
$ cd consolas
$ curl -O http://download.microsoft.com/download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26/PowerPointViewer.exe
$ cabextract PowerPointViewer.exe
$ cabextract ppviewer.cab
@fredyang
fredyang / client.js
Created April 23, 2020 01:31 — forked from PaulMougel/client.js
File upload in Node.js to an Express server, using streams
// node: v0.10.21
// request: 2.27.0
var request = require('request');
var fs = require('fs');
var r = request.post("http://server.com:3000/");
// See http://nodejs.org/api/stream.html#stream_new_stream_readable_options
// for more information about the highWaterMark
// Basically, this will make the stream emit smaller chunks of data (ie. more precise upload state)
var upload = fs.createReadStream('f.jpg', { highWaterMark: 500 });
@fredyang
fredyang / microsyntax.md
Created August 29, 2020 10:33 — forked from mhevery/microsyntax.md
Angular microsyntax gramar

Microsyntax

Microsyntax in Angular allows you to write <div *ngFor="let item of items">{{item}}</div> instead of <ng-template ngFor [ngForOf]="items"><div>{{item}}</div></ng-template.

Constraints

The microsyntax must:

  • be know ahead of time so that IDEs can parse it without knowing what is the underlying semantics of the directive or what directives are present.
  • must translate to key-value attributes in the DOM.