Skip to content

Instantly share code, notes, and snippets.

View bcho's full-sized avatar
💍
一起来发财吧!Let's make some money!

hbc bcho

💍
一起来发财吧!Let's make some money!
View GitHub Profile
package main
import (
"flag"
"log"
"math/rand"
"os"
"time"
)
fs = require 'fs'
path = require 'path'
dataPath = './data'
fullPath = (name) -> path.join dataPath, name
evalFile = (name) -> eval fs.readFileSync(fullPath name).toString 'utf8'
import dis
def f():
False is False is False
def f2():
1 <= 1 <= 1
@bcho
bcho / proxy.go
Created April 3, 2015 14:37
trick
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
@bcho
bcho / qsort.clj
Created March 8, 2015 08:26
trick
(def arr (-> 100 range shuffle))
(defn qsort [[pivot & remains]]
(when pivot
(let [left (for [x remains :when (< x pivot)] x)
right (for [x remains :when (> x pivot)] x)]
(lazy-cat (qsort left) (list pivot) (qsort right)))))
(-> arr qsort prn)
@bcho
bcho / unicode.py
Created February 28, 2015 14:21
trick
import unicodedata
def must_be_ascii(raw):
'''Convert all non-ascii characters to ascii substitutes.
:param raw: raw input.
'''
if not isinstance(raw, (str, unicode)):
raise TypeError('Cannot convert to ascii, expected str or unicode.')
<?php
use Widget\Form;
use Widget\Checkbox;
class ProductPresenter {
protected $resource;
public function withProduct($product)
@bcho
bcho / PostPresenter.php
Created February 1, 2015 02:05
PostPresenter.php
<?php namespace Vtmer\Blog\Presenter;
use ArrayAccess;
use JsonSerializable;
use Illuminate\Support\Contracts\JsonableInterface;
use Illuminate\Support\Contracts\ArrayableInterface;
use Vtmer\Blog\Model\PostModel;
<?php namespace Vtmer\Blog\Model;
class PostModel extends \Eloquent {
// 文章查看相关的记录
use PostVisitTrait;
// 作者关联定义
use PostAuthorTrait;
<?php namespace Vtmer\Blog\Model;
trait PostAuthorTrait {
/**
* 文章作者关联
*
* @return \Illumniate\Database\Eloquent\Relations\BelongsTo
*/
public function author()