Skip to content

Instantly share code, notes, and snippets.

View notcome's full-sized avatar

Minsheng Liu notcome

View GitHub Profile
@notcome
notcome / LRU.v1
Last active August 29, 2015 14:04
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 October 2, 2014 13:10
KVO and Binding for JavaScript
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 October 21, 2014 00:52
Simplest way to implement parental control in Qujing.
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 October 30, 2014 13:58
several IOL.cn problem page prototypes
<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 December 9, 2014 04:33
ensure that the function's first invocation will be exclusive
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 February 6, 2015 13:12
Hyphenating English Within Chinese Articles is Possible.
<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 February 11, 2015 20:52
Compress selected images using canvas
<!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 February 12, 2015 12:30
I will be back after bbq is done
{-# 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 February 23, 2015 10:07
标点挤压,汉字与西文的空格
<style>
html {
font-family: Helvetica;
}
body {
width: 30em;
margin: auto;
}
p {
width: 581px;
@notcome
notcome / demo.hs
Created March 2, 2015 15:32
Human readable Haskell representation for "Quick Quote"
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE UnicodeSyntax #-}
import Prelude hiding (putStrLn)
import Data.Text.Lazy.IO (putStrLn)
import Control.Monad.Writer
-- Monoid Instance --