Skip to content

Instantly share code, notes, and snippets.

View fredyang's full-sized avatar

Fred Yang fredyang

View GitHub Profile
@fredyang
fredyang / jasmine_spec.js
Created June 26, 2015 15:12
jasmine test template
'use strict';
describe('A suite', function () {
it('contains spec with an expectation', function () {
expect(true).toBe(true);
});
});
describe('A suite is just a function', function () {
var a;
@fredyang
fredyang / SassMeister-input.scss
Created October 1, 2015 04:29
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
.sidebar {
width: 300px;
@media screen and (orientation: landscape) {
width: 500px;
}
}
@fredyang
fredyang / SassMeister-input.scss
Created December 31, 2015 22:27
Generated by SassMeister.com.
// ----
// libsass (v3.3.2)
// ----
//case 1
.modal {
&__header { color: red};
}
@fredyang
fredyang / SassMeister-input.scss
Created January 27, 2016 16:36
Generated by SassMeister.com.
// ----
// libsass (v3.3.2)
// ----
//nested rules
#main p {
color: #00ff00;
width: 97%;
.redbox {
# 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 / test-parallel-function.js
Last active February 15, 2019 18:54
a parallel wrapper function
//run this in node.js, firefox only, not in browser chrome for now
const parallel = async (...items) => {
const temp = [];
for (const item of items) {
temp.push(await item);
}
return temp;
};
const someResult = async () => {
@fredyang
fredyang / cloudSettings
Last active May 21, 2020 00:55
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-04-22T13:57:07.464Z","extensionVersion":"v3.4.3"}
@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 });
interface Constructor<T> {
new(...args: []): T;
}
interface Base {
}
interface Items {
items: [];
}
@fredyang
fredyang / catchit.ts
Last active May 4, 2020 02:22
a function that allow you convert async express middleware without worry about exception
const catchit = asynFn => (req, res, next) => asynFn(req, res, next).catch(next);
//usage
router.get('/', catchit(async (req, res, next) => {
await data = db.get();
throw 'err';
res.json(data);
}));