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

>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 / 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,
});
'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) => {

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

this -> obj

###2 The Function Invocation Pattern fun()

<!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!")
@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>
@nothingrealhappen
nothingrealhappen / upload.js
Last active May 25, 2016 08:22
Crop avatar before upload to server
// import crop package
import crop from 'crop-image';
// input file onChange callback
this.upload = e => {
const files = e.target.files;
if (files && files[0]) {
const image = new Image();
image.onload = () => {
@nothingrealhappen
nothingrealhappen / install.sh
Created June 21, 2016 04:33
dotfile install script
#!/bin/bash
safe_link(){
local src="$1"
local dest="$HOME/`basename $src`"
[ ! -e "$dest" ] && ln -sf "$src" "$dest"
}
DOTFILES="/Users/x/Dropbox/dotfile/dotfiles"
@nothingrealhappen
nothingrealhappen / use_find_server.js
Created June 29, 2016 09:18
find localnet server
const findServer = require('./find_server');
findServer({
pingKey: 'your pingkey in config.js',
port: '3001',
path: '/ping',
cb: ip => {
console.log(ip);
},
});
@nothingrealhappen
nothingrealhappen / iterm2.profile.json
Last active July 1, 2016 08:54
my iterm2 profile
{
"Working Directory" : "\/Users\/vanilla",
"Prompt Before Closing 2" : 0,
"Selected Text Color" : {
"Red Component" : 0.8379544019699097,
"Color Space" : "Calibrated",
"Blue Component" : 0.8379434943199158,
"Alpha Component" : 1,
"Green Component" : 0.837929368019104
},