Skip to content

Instantly share code, notes, and snippets.

View chunpu's full-sized avatar
🎯
Focusing

chunpu chunpu

🎯
Focusing
  • 360
  • China
View GitHub Profile
<script type='x' id='markdown'>
title
===
> blockquote
code
code2
### head
var tokenRules = [
['number', /^\d+/],
['space', /^ +/],
'+', '-', '*', '/'
]
var str = '1 + 2 * 3 + 33 / 3'
function lex(str, tokenRules) {
var tokens = []
var tokenRules = [
['number', /^\d+/],
['space', /^ +/],
'+', '-', '*', '/'
]
var str = '1 + 2 * 3 + 33 / 3'
function lex(str, tokenRules) {
var tokens = []
@chunpu
chunpu / template.html
Last active August 29, 2015 13:57
A standard html layout I think, ( to be improved
<!-- default tab (easy to paste) -->
<!-- html5 is here to replace aria role, no role -->
<!-- to validator (http://validator.w3.org/nu/) -->
<!doctype html>
<!-- no html lang (avoid chrome translation) -->
<html>
<head>
<!-- default utf-8 -->
<meta charset="utf-8">
<!-- title -->
@chunpu
chunpu / simple-demo.html
Last active August 29, 2015 13:56
a simple and stupid html template
<script src='./template.js'></script>
<script id='tmpl' type='x'>
<p>Hi {{=name}}</p>
<ul>
{{for (var i = -1; i++ != arr.length - 1;) { }}
<li>{{=arr[i]}}</li>
{{ } }}
</ul>
</script>
<div>
@chunpu
chunpu / mvvm.js
Created March 1, 2014 05:09
really fucking simple javascript mvvm
!function(f) {
if (window.define && define.amd) define(f)
else window.mvvm = f()
}(function() {
var start = '{{'
var end = '}}'
function mvvm(sel, opt) {
return new MVVM(sel, opt)
@chunpu
chunpu / promise.js
Last active August 29, 2015 13:56
simple promise.js, implemented basic features like `chain then`, `resolve`, `reject`
!function() {
function Promise(resolver) {
var queue = []
resolver(resolve, reject)
function next(i, val) {
setTimeout(function() { // dirty but out queue(resolve, reject) must wait then inqueue
while (queue.length) {
var arr = queue.shift()
@chunpu
chunpu / amd.js
Last active August 29, 2015 13:56
really simple amd, can only load jquery or projects as simple as jquery..
;(function(window, undefined) {
function loadScript(url) {
count++
var script = document.createElement('script')
path = ''
script.async = true
script.src = path + url + '.js'
document.getElementsByTagName("head")[0].appendChild(script)
script.onload = function(e) {
currentPath = getPath(script.src)
@chunpu
chunpu / test.md
Last active January 4, 2016 15:38
Welcome document

Welcome to StackEdit! {#welcome}

Hello, I am your first Markdown document within StackEdit[^stackedit]. Don't delete me, I can be helpful. I can be recovered anyway in the Utils tab of the Settings dialog.


Documents

@chunpu
chunpu / quicksort.js
Last active January 3, 2016 23:29
quicksort pure js
Array.prototype.sort = function(compareFN) {
var compareFN = compareFN || function(a, b) {
return a - b
}
var arr = this
function getThirdIndex(from, to) {
// get suitable pivot