Skip to content

Instantly share code, notes, and snippets.

View yyong37's full-sized avatar

yyong yyong37

  • Mars
View GitHub Profile
@yyong37
yyong37 / javascrpit-function.js
Last active March 7, 2017 12:31
Javascript
Function.prototype.method = function(name, func) {
if(!this.prototype[name]) {
this.prototype[name] = func;
}
return this;
};
Number.method('integer', function() {
return Math[this < 0 ? 'ceil' : 'floor'](this);
});
@yyong37
yyong37 / memoizer.js
Created March 25, 2016 15:22
Javascripts
var memoizer = function (memo, formula) {
var recur = function(n) {
var result = memo[n];
if(typeof result !== 'number') {
result = formula(recur, n);
memo[n] = result;
}
return result;
};
return recur;
@yyong37
yyong37 / is_array.js
Created March 25, 2016 16:40
Javascript
var is_array = function(value) {
return Object.prototype.toString.apply(value) === '[object Array]';
};
@yyong37
yyong37 / nginx
Created September 26, 2016 04:42 — forked from vdel26/nginx
Openresty init.d script
#!/bin/sh
#
# chkconfig: 2345 55 25
# Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx
# For Debian, run: update-rc.d -f nginx defaults
# For CentOS, run: chkconfig --add nginx
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
def split(x):
def sp(n,m):
if m>n:
raise StopIteration
else:
for i in range(m,n//2+1):
for l in sp(n-i,i):
yield [i]+l
yield [n]
for i in sp(x,1):
@yyong37
yyong37 / txt2epub.py
Created November 27, 2017 02:57 — forked from scturtle/txt2epub.py
txt to epub
# coding: utf-8
import os
#书籍信息
title='test book'
creator='scturtle'
description='blablablabla'
#章节文件
txtlist=['1.txt','2.txt']
class Post extends Component {
constructor () {
super()
this.state = { content: '' }
}
componentWillMount () {
this._loadData()
}
@yyong37
yyong37 / Parser.js
Created June 22, 2018 04:58 — forked from Saul-Mirone/MVVM.js
A simple mvvm
class Register {
constructor() {
this.routes = []
}
regist(obj, k, fn) {
const _i = this.routes.find(function(el) {
if((el.key === k || el.key.toString() === k.toString())
&& Object.is(el.obj, obj)) {
return el
<?php
class Singleton {
private $_instance;
private function __construct() {}
private function __clone() {}
<?php
// we can use this, make our code simple and short.
class MethodTest
{
public function __call($name, $arguments)
{
// Note: value of $name is case sensitive.
echo "Calling object method '$name' "