Skip to content

Instantly share code, notes, and snippets.

View Dafrok's full-sized avatar
🏳️‍🌈
正在变基

Dafrok Dafrok

🏳️‍🌈
正在变基
View GitHub Profile
@Dafrok
Dafrok / group.js
Last active January 20, 2017 05:34
[1,2,2,3,3,3,5,4,4,4,6].reduce((a, b, i, o) => (l = a.length, m = a[l - 1], l ? (m[m.length - 1] === b ? m.push(b) : (!~-m.length && (a[l - 1] = m[0]), a.push(i - o.length + 1 ? [b] : b)), a) : [[b]]), [])
export default (str, ...val) => console.log(str.reduce((a, b, i) => `${a}${b}${val[i] || ''}`, ''))
const gulp = require('gulp')
const rev = require('gulp-rev')
const revCssUrl = require('gulp-rev-css-url')
const cssSpriter = require('gulp-css-spriter')
const clean = require('gulp-clean')
gulp.task('sprite', ['clean'], () => gulp.src('./src/main.css')
.pipe(cssSpriter({
spriteSheet: './temp/sprite.png',
pathToSpriteSheetFromCSS: './sprite.png'
@Dafrok
Dafrok / clone.js
Last active October 12, 2017 02:26
deep copy function
function clone (obj) {
let ret
switch (Object.prototype.toString.call(obj).slice(8, -1)) {
case 'Array':
return obj.map(val => clone(val))
case 'Set':
case 'WeakSet':
ret = []
obj.forEach(val => ret.push(clone(val)))
return new Set(ret)
const flatten = (f =>
(x => f(y => x(x)(y)))
(x => f(y => x(x)(y)))
)(fn => data => data.reduce((ary, item) => ary.concat(item.length ? fn(item) : item), []))
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.getJSONP = factory());
}(this, function () { 'use strict';
var global = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this;
return function getJSONP (url, callback) {
var dt = new Date();
var callbackName = 'JSONP_' + Date.parse(dt) + dt.getMilliseconds();
const http = require('http')
const fs = require('fs')
const path = require('path')
const STEP = 50
const MAX = 65536
const file = {}
const getKana = range => new Promise((resolve, reject) => {
let text = ''
git filter-branch --env-filter '
OLD_EMAIL="OLD_EMAIL"
CORRECT_NAME="Dafrok"
CORRECT_EMAIL="o.o@mug.dog"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
git pull origin pull/28/head
# or
git fetch origin pull/28/head:28
git checkout 28
@Dafrok
Dafrok / timeDec.js
Last active September 14, 2017 08:43
function timeDec(t1, t2) {
const DAY = 24 * 60 * 60 * 1000
const SPACING = DAY * 7 / 24
const t = d => ((r = new Date(d), (22<= r < 6) ? new Date(r.setHours(22)) : r >= 0 ? new Date(r - DAY) : new Date(r)).getTime())
const dec = t(t1) - t(t2)
return Math.abs(dec- ((dec / DAY) | 0) * SPACING)
}