Skip to content

Instantly share code, notes, and snippets.

View magicdawn's full-sized avatar
🐟
Fishing

Tao magicdawn

🐟
Fishing
View GitHub Profile
def alias_task(name, old_name)
t = Rake::Task[old_name]
desc t.full_comment if t.full_comment
task name, *t.arg_names do |_, args|
# values_at is broken on Rake::TaskArguments
args = t.arg_names.map { |a| args[a] }
t.invoke(args)
end
end
@magicdawn
magicdawn / test_Object#hash
Created October 5, 2014 05:56
test Object#hash
Object.prototype.hash1 = function(string) {
var code = "try{ return this."+ string +" } catch(e){ return undefined }"
return (new Function(code)).call(this);
};
var test = {
'a':{
'b':{
'c':{
@magicdawn
magicdawn / _require.js
Created October 12, 2014 01:14
nodejs module 热更新
/*
require -> Module.prototype.require -> Module.load(request,module)
require.reslove -> Module._resolveFilename(request, module);
*/
var Module = module.constructor
Module.prototype._require = function(request) {
@magicdawn
magicdawn / _parse.js
Created October 21, 2014 13:16
JSON._parse not quoted key string
module.exports = parse
function parse(s) {
s = s.replace(/'/g, "\'")
.replace(/"/g, '\"')
.replace(/\n/g, '\\n')
.replace(/\r/, '\\r')
var code = "return " + s
var f = new Function(code)
@magicdawn
magicdawn / kuaidi.js
Last active April 15, 2016 06:50
kuaidi.js
/**
* http://v2ex.com/t/271065
* http://www.kuaidadi.com/assets/js/animate.js
*
* ES6 环境可用
* babelify: regenerator 到ES5可用。
*/
const pify = require('promise.ify').noerr;
const cowrap = require('co').wrap;
@magicdawn
magicdawn / ImageCaptcha.js
Created November 21, 2016 14:21
image captcha with node-gd
'use strict'
const fs = require('fs')
const _ = require('lodash')
const onecolor = require('onecolor')
const gd = require('node-gd')
// https://github.com/y-a-v-a/node-gd/blob/master/docs/index.md
// Set full path to font file
const fontpath = __home + '/files/fonts/arial.ttf'
@magicdawn
magicdawn / yargs.js
Last active July 19, 2017 13:15
yargs
const i = yargs
.usage('$0 -u <url> [options]')
.option('url', {
alias: 'u',
describe: '专辑/歌单 url',
required: true,
type: 'string',
})
.option('concurrency', {
alias: 'c',
@magicdawn
magicdawn / collision.js
Last active September 8, 2018 02:43
stable collison detect use in mapbox symbol layer
/**
* 初始的 filter
*/
export function initialFilter({ map, list }) {
list.forEach(item => setBox({ map, item }))
let i = 0
while (i < list.length) {
let prev = list.slice(0, i)
@magicdawn
magicdawn / ascii-logo-for-cli.js
Created January 1, 2021 18:26
ascii logo for cli
const gradient = require('gradient-string')
const figlet = require('figlet')
console.log(
gradient.rainbow(
figlet.textSync('Hello World !', {
font: 'Standard',
horizontalLayout: 'full',
})
)