Skip to content

Instantly share code, notes, and snippets.

View nothingrealhappen's full-sized avatar
🏠
Working from home

NothingRealHappen nothingrealhappen

🏠
Working from home
  • Mars
View GitHub Profile
@nothingrealhappen
nothingrealhappen / upload.html
Created May 25, 2016 05:37
qiniu-upload-demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
</head>
<body>
<textarea id="content" cols="30" rows="10"></textarea>
<button id="upload">上传</button>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta content="initial-scale=1.0, width=device-width" name="viewport">
</head>
<body>
<pre id="lines" data-lining>
print("Hello, WWDC!")

###1 The Method Invocation Pattern obj.action()

this -> obj

###2 The Function Invocation Pattern fun()

'use strict';
var test = [10,4,3,5,6,2,8];
const swap = function(a, b) {
if(this[a] > this[b]) this[a] = [this[b], this[b] = this[a]][0];
}
const bubbleSort = a => {
a.forEach((x, index) => {
@nothingrealhappen
nothingrealhappen / beer.js
Created March 3, 2016 05:54
每日一题
const exchange = ({ money, bottle, cap, drinked }) => {
if(money === 0 && bottle < 2 && cap < 4) return drinked;
const newDrink = parseInt(money/2) + parseInt(bottle/2) + parseInt(cap/4);
return exchange({
money: money % 2,
cap: cap % 4 + newDrink,
bottle: bottle % 2 + newDrink,
drinked: drinked + newDrink,
});

>Write a method to shuffle a deck of cards. It must be a perfect shuffle - in other words, each 52! permutations of the deck has to be equally likely. Assume that you are given a random number generator which is perfect.

@nothingrealhappen
nothingrealhappen / webpack.config.js
Last active December 4, 2015 07:06
webpack config
const path = require('path');
const webpack = require('webpack'); const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const OUT_DIR = path.join(__dirname, './bundle/');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
var config = {
context: __dirname,
entry: {
home: './src/home.js'
},
# general
color default 15 235
color cursor 15 241
color title-focus 242 221
color title-blur 242 221
color delimiter 213 default
color author 156 default
color date 33 default
color line-number 221 default
color mode 255 default
@nothingrealhappen
nothingrealhappen / surge_main.conf
Created October 30, 2015 07:41 — forked from jason5ng32/surge.conf
Surge Configs ( Both 2 files are needed )
[General]
loglevel = notify
skip-proxy = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12,127.0.0.0/24,100.64.0.0/10
bypass-tun = 0.0.0.0/8, 1.0.0.0/9, 1.160.0.0/11, 1.192.0.0/11, 10.0.0.0/8, 14.0.0.0/11, 14.96.0.0/11, 14.128.0.0/11, 14.192.0.0/11, 27.0.0.0/10, 27.96.0.0/11, 27.128.0.0/9, 36.0.0.0/10, 36.96.0.0/11, 36.128.0.0/9, 39.0.0.0/11, 39.64.0.0/10, 39.128.0.0/10, 42.0.0.0/8, 43.224.0.0/11, 45.64.0.0/10, 47.64.0.0/10, 49.0.0.0/9, 49.128.0.0/11, 49.192.0.0/10, 54.192.0.0/11, 58.0.0.0/9, 58.128.0.0/11, 58.192.0.0/10, 59.32.0.0/11, 59.64.0.0/10, 59.128.0.0/9, 60.0.0.0/10, 60.160.0.0/11, 60.192.0.0/10, 61.0.0.0/10, 61.64.0.0/11, 61.128.0.0/10, 61.224.0.0/11, 100.64.0.0/10, 101.0.0.0/9, 101.128.0.0/11, 101.192.0.0/10, 103.0.0.0/10, 103.192.0.0/10, 106.0.0.0/9, 106.224.0.0/11, 110.0.0.0/7, 112.0.0.0/9, 112.128.0.0/11, 112.192.0.0/10, 113.0.0.0/9, 113.128.0.0/11, 113.192.0.0/10, 114.0.0.0/9, 114.128.0.0/11, 114.192.0.0/10, 115.0.0.0/8, 116.0.0.0/8, 117.0.0.0/9, 117.128.0.0/10, 118.0.0.0/11, 118.64.0.0/10, 118.128.0.0
```javascript
const cat = (head, ...items) => head.length ? head.concat.apply(head, items) : [];
const flat = arr => Array.isArray(arr) ? cat.apply(cat, arr.map(flat)) : [arr];
```