Skip to content

Instantly share code, notes, and snippets.

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

Dafrok Dafrok

🏳️‍🌈
正在变基
View GitHub Profile
(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 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), []))
@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 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'
export default (str, ...val) => console.log(str.reduce((a, b, i) => `${a}${b}${val[i] || ''}`, ''))
@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]]), [])
var table = document.createElement('table')
var thead = document.createElement('thead')
var tbody = document.createElement('tbody')
var firstTr = document.createElement('tr')
var firstTh = document.createElement('th')
table.appendChild(thead)
table.appendChild(tbody)
thead.appendChild(firstTr)
firstTr.appendChild(firstTh)
~function () {
var flag = true
var interval
function refresh() {
if (flag) {
console.log((new Date).toLocaleString())
var iframe = document.createElement('iframe')
iframe.src = 'https://shop103422196.taobao.com/category.htm?spm=a1z10.3-c.w4002-6402908702.30.83cQDQ&_ksTS=1465271481288_143&callback=jsonp144&mid=w-6402908702-0&wid=6402908702&path=%2Fcategory.htm&orderType=newOn_desc'
document.body.appendChild(iframe)
iframe.onload = function () {
@Dafrok
Dafrok / shuffle.js
Created May 12, 2016 03:29
shuffle
function shuffle(ary) {
let times = ary.length
while (times) {
ary.push(ary.splice(0 | Math.random() * times, 1)[0])
times--
}
return ary
}
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->