Skip to content

Instantly share code, notes, and snippets.

View AaronFlower's full-sized avatar
💭
I may be slow to respond.

AaronFlower

💭
I may be slow to respond.
View GitHub Profile
@AaronFlower
AaronFlower / box-sizing-02.css
Created December 2, 2017 08:31
box-sizing best practice 02
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
@AaronFlower
AaronFlower / box-sizing.css
Created December 2, 2017 08:30
css box-sizing best practice 01
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
@AaronFlower
AaronFlower / currying-add.js
Created November 30, 2017 16:07
javascript currying
function add (a, b) {
return a + b
}
foo = [10, 20, 30, 40]
bar = foo.map(add.bind(null, 5))
console.log(bar)
@AaronFlower
AaronFlower / proxy-observable.js
Created November 30, 2017 15:47
javascript Proxy Reflect
/**
* Use Proxy to implement observable
*/
function observable (obj, onchange) {
return new Proxy(obj, {
set (target, key, value) {
Reflect.set(target, key, value)
onchange(key, value)
},
delete (target, key) {
@AaronFlower
AaronFlower / router.html
Created November 26, 2017 08:49 — forked from joakimbeng/router.html
A really simple Javascript router
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Building a router</title>
<script>
// Put John's template engine code here...
(function () {
// A hash to store our routes:
@AaronFlower
AaronFlower / adder-function.js
Created November 21, 2017 05:07
Javascript Function Object
const adder = new Function('a', 'b', 'return a + b')
adder(2, 3)
@AaronFlower
AaronFlower / c_cpp_properties.json
Created November 18, 2017 08:12
vs code mac c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include",
@AaronFlower
AaronFlower / escapeHtml.js
Created November 13, 2017 13:27
js escape html
/**
* 参考 https://github.com/janl/mustache.js/blob/b283da5c8c26dbf78c357a1f67bfed26d18f5e32/mustache.js#L60
*/
var entityMap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'/': '&#x2F;',
@AaronFlower
AaronFlower / mustache.js
Created November 13, 2017 07:38
a simple mustache js
str = 'hello {name}, say {msg}. {name} is a handsome boy, {age}!'
reg = /{([^{}]+)}/g
data = {
name: 'eason',
msg: 'hi'
}
str.replace(reg, function (_, key) {
return data[key] || `{${key}}`
})
// "hello eason, say hi. eason is a handsome boy, {age}!"
@AaronFlower
AaronFlower / if-statement.sh
Last active November 9, 2017 05:17
bash shell if statement
if [ -f .bashrc ] ; then
echo "bashrc exists"
else
echo "bashrc does not exist"
fi
if [[ -r .bashrc ]]
then
echo ".bashrc exists and have permission granted."
fi