Skip to content

Instantly share code, notes, and snippets.

View cyjake's full-sized avatar

Chen Yangjian cyjake

View GitHub Profile
@cyjake
cyjake / foo.js
Created May 13, 2019 05:55
analyse web dependencies with porter
const Porter = require('@cara/porter');
const porter = new Porter({
paths: '.',
entries: 'examples/index.js',
});
(async function() {
await porter.ready;
const packages = [];
for (const pkg of porter.package.all) {
@cyjake
cyjake / event-emitter.js
Last active October 14, 2015 02:25
A simple event emitter mixin modified a bit from seajs
/*
* EventEmitter from seajs
*/
var EventEmitter = {
// Bind event
on: function(name, callback) {
var events = this.events
var list = events[name] || (events[name] = [])
list.push(callback)
return this
http://srd.simba.taobao.com/rd?w=mmp4ptest&f=http%3A%2F%2Fre.ai.taobao.com%2Fauction%3Fkeyword%3D%25D3%25BE%25BE%25B5%26catid%3D50016744%26refpid%3Dtt_16143929_2253494_8923336%26digest%3D14FFF3C95FDA79ECFD67C9BA19A9D3FB%26crtid%3D253374519%26itemid%3D25806828678%26adgrid%3D235827263%26elemtid%3D1%26eurl%3Dhttp%253A%252F%252Fclick.simba.taobao.com%252Fcc_im%253Fp%253D%2526s%253D1799020187%2526k%253D352%2526e%253DQCZhRciE%25252FhTsxQVKHpFcmpc5YPYV6uFQprYu2z%25252F1K7zCYH%25252FUB1Nb7s%25252BBGq5aFChlq6RTjAgq%25252BzWlQHM0vuyxD9%25252Bf1Nn8M%25252BvaGRAspkN7yHcUDirHF4jO%25252BsAhcUsRUe7pU4Okciyvb8MIkcj9FYsTf1pHY46HLYgaAoxpU5IeHihh2hk%25252B0boTXJlmrsgRDZ%25252FIqyGUPVFVApkLrWUZFICO%25252F3RGbeo%25252FYMH51brGK2Aeohvd51nD6zvbfr9%25252Fmf3ATTyoOAVfDfrjX%25252FLA%25252FjjO5m71GBPYPt1who2n2nhdyq4uw94YXnHDMXiHba2kmgyMwxYKqyGUPVFVApkLrWUZFICO%25252FwwyPNmHIw4z%26clk1info%3D1799020187%2C64%2CyCPeEAXW8cjNluokAwCJS3%252BwNv5tQ%252B2sCH23yplrNbwKBDDBuPY%252Fb9qBmJSKUspq%26sbid%3D1059%2C0%2C4%3B%3B%2C&k=a5181f062a3ad5fc&pv
@cyjake
cyjake / subp
Last active August 29, 2015 14:02
Simple subl wrap that is project configuration aware
#!/usr/bin/env node
'use strict';
/* jshint asi: true */
var fs = require('fs')
var path = require('path')
var spawn = require('child_process').spawn
// 基于 Promise 的分批函数
// 遇到文件句柄不够用、并发请求数限制等场景的时候挺方便的
function batch(arr, size, fn) {
var offset = 0
var length = arr.length
var limit = size
function _batch(offset, limit) {
return Promise.all(arr.slice(offset, limit).map(fn)).then(function() {
if (limit <= length) {
@cyjake
cyjake / wrong_sub_class.js
Last active January 3, 2016 00:19
Creating sub classes with prototype assigning directly will confuse instanceof operator.
var util = require('util')
function Class() {}
function SubClass() {}
function WrongSubClass() {}
util.inherits(SubClass, Class)
util.inherits(WrongSubClass, Class)
@cyjake
cyjake / auto_curry.js
Created December 13, 2013 09:15
Auto currying function
function multiply() {
// implementation code goes here
}
multiply(3)(4)(5) // ==> 60
@cyjake
cyjake / unique.js
Created December 13, 2013 09:13
Array.unique?
var data = [{
sizes: [1, 0]
},{
sizes: [2, 3]
},{
sizes: [2, 2]
},{
sizes: [3, 5]
},{
sizes: [1, 0]
# How to create a favicon with multiple image sizes and keep alpha transparency
- export your images in the desired sizes (16x16, 32x32 ... max 256x256) as PNGs + alpha
- install ImageMagick
Run this command (replacing the .png files for your own images):
convert favicon-16.png favicon-32.png favicon-64.png -colors 256 -alpha background favicon.ico
@cyjake
cyjake / restore.sh
Created November 29, 2013 06:23
Make bootable usb stick to Install Mavericks
$ sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction