Skip to content

Instantly share code, notes, and snippets.

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

Dafrok Dafrok

🏳️‍🌈
正在变基
View GitHub Profile
@Dafrok
Dafrok / gulpfile.js
Last active August 29, 2015 14:16
sample gulpfile
var gulp = require("gulp")
var gulpif = require( 'gulp-if')
var jade = require("gulp-jade")
var stylus = require("gulp-stylus")
var autoprefixer = require("gulp-autoprefixer")
var minifyImg = require("gulp-imagemin")
var changed = require("gulp-changed")
var uglify = require("gulp-uglify")
var minifyCss = require("gulp-minify-css")
var browserSync = require('browser-sync')
@Dafrok
Dafrok / gist:251a4b67afb74f20bd0a
Created May 20, 2015 03:22
一个计算多维数组深度的奇淫算法
ary=[1,[2,3],[4,[5,6],["7,8"],9],0,[1,2,[3,4,[5,"[6]",[7]],[8],[9]],0],[1,2,3]]
Math.max.apply({},JSON.stringify(ary).replace(/"[^"]*"|[0-9]|,/g,"").replace(/\[\]/g,"[x]").split("x").map(function(str,index,list){str += list.slice(0, index).join('');return str.split('[').length - str.split(']').length}))
function add(n){
var _callee=arguments.callee
if(typeof(n)=='number'){
return function(m){
if(typeof(m)=='number'){return _callee(n+m)}
else{return n}
}
}
}
@Dafrok
Dafrok / Math.Gaussian
Created November 19, 2015 09:31
Gaussian
Math.Gaussian = function (x, mu, sigma) {
return (1 / (Math.sqrt(2 * Math.PI) * sigma)) * Math.pow(Math.E, -Math.pow(x - mu, 2) / 2 * Math.pow(sigma, 2));
};
@Dafrok
Dafrok / vue-file-creater.js
Last active November 26, 2015 05:27
Create Vue files.
var fs = require('fs')
var createVueFile = function (path, option) {
console.log('Creating vue files...')
var files = fs.readdirSync(path)
files.forEach(function (componentName) {
var componentPath = path + '/' + componentName;
var stats = fs.statSync(componentPath)
stats.isDirectory() && ~function () {
var vueFile = componentPath + '/' + componentName + '.vue'
var htmlLang = option.html ? 'lang="' + option.html + '"' : ''
@Dafrok
Dafrok / empty.js
Created January 25, 2016 05:15
Check an object if all of its childrens are empty.
/*
* @file Check an object if all of its childrens are empty.
* @author Dafrok
* @param {object} obj
* @return {boolean} If all of the childrens of the target object are empty, it will be true, else, false.
*/
;var empty = (function () {
var isEmpty
function type (obj) {
# 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 ->
@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
}
~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 () {
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)