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 ->
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)
@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] || ''}`, ''))