Skip to content

Instantly share code, notes, and snippets.

Avatar

Minsheng Liu notcome

  • XNZG
  • Hangzhou, China
View GitHub Profile
View LRU.v1
class LRUElement {
constructor (data, master, index) {
this.data = data;
this.master = master;
this.index = index;
this.lastAccess = new Date();
}
get value () {
return this.data;
@notcome
notcome / kvo.js
Created Oct 2, 2014
KVO and Binding for JavaScript
View kvo.js
function initWatchProperty (obj, key) {
if (obj['$$watchers$$' + key])
return;
Object.defineProperty(obj, key, {
get: function () {
return this['$$' + key];
},
set: function (val) {
var old = this['$$' + key];
@notcome
notcome / gist:a94e6c0c95cff41c8a10
Created Oct 21, 2014
Simplest way to implement parental control in Qujing.
View gist:a94e6c0c95cff41c8a10
var http = require('http');
var server = http.createServer(onRequest);
function onRequest (req, res) {
res.writeHead(403, 'You are forbidden to visit this page due to Qujing\'s parental control.');
res.write('You are forbidden to visit this page due to Qujing\'s parental control.');
res.end();
}
@notcome
notcome / inline-phrases.html
Created Oct 30, 2014
several IOL.cn problem page prototypes
View inline-phrases.html
<style>
ul, li { padding: 0; margin: 0; }
ul { width: 400px; }
li {
display: inline;
font-family: "Charis SIL";
font-style: italic;
}
@notcome
notcome / initGuard.js
Created Dec 9, 2014
ensure that the function's first invocation will be exclusive
View initGuard.js
var fs = require('fs');
function guardInit (init) {
var delayedCalls = [];
var status = 'not initialized';
return function () {
if (status == 'initializing')
return delayedCalls.push(arguments);
if (status == 'initialized')
@notcome
notcome / gist:52658490bc4bb2f4ad37
Created Feb 6, 2015
Hyphenating English Within Chinese Articles is Possible.
View gist:52658490bc4bb2f4ad37
<html lang="cmn-Hans-CN">
<head>
<style type="text/css">
#block {
width: 10em;
margin-left: 5em;
text-align: justify;
-webkit-hyphens: auto;
}
i {
@notcome
notcome / canvas-compress
Created Feb 11, 2015
Compress selected images using canvas
View canvas-compress
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#picture-select {
display: block;
}
#canvas {
@notcome
notcome / WillBeBack
Created Feb 12, 2015
I will be back after bbq is done
View WillBeBack
{-# LANGUAGE DeriveDataTypeable, TemplateHaskell, TypeFamilies, FlexibleInstances, FlexibleContexts, InstanceSigs #-}
module Data.VCodePool where
import Data.Data (Data, Typeable)
import Data.SafeCopy (base, deriveSafeCopy, SafeCopy(..))
import Control.Applicative ((<$>), (<*>))
import Control.Monad.Reader (ask)
import Control.Monad.State (get, put)
@notcome
notcome / trim-and-spacing.html
Created Feb 23, 2015
标点挤压,汉字与西文的空格
View trim-and-spacing.html
<style>
html {
font-family: Helvetica;
}
body {
width: 30em;
margin: auto;
}
p {
width: 581px;
@notcome
notcome / demo.hs
Created Mar 2, 2015
Human readable Haskell representation for "Quick Quote"
View demo.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE UnicodeSyntax #-}
import Prelude hiding (putStrLn)
import Data.Text.Lazy.IO (putStrLn)
import Control.Monad.Writer
-- Monoid Instance --