Skip to content

Instantly share code, notes, and snippets.

View thbourlove's full-sized avatar
💭
I may be slow to respond.

Tang Hongbo thbourlove

💭
I may be slow to respond.
View GitHub Profile
https://press.one/p/address/v?s=8107de06d9025a7f77e9ea7ea5288eb3dcd7566b2cc3d72dd309d87f4253b08ddc34cc87ef9f4e1fd7b05c97d44cbc56c6ee20b69c393c98e24a37315520764c1&h=4c78a8627c979b50d97564066ececb253f4f1eb14a67f31cee7ff7159969d636&a=dc7c0a6d420bc9707f73a7d1496e2f5a23e5741d&f=P1&v=2
@thbourlove
thbourlove / timeout_read_stdin.go
Created July 28, 2016 13:51
read stdin with timeout
package main
import (
"fmt"
"log"
"syscall"
)
func main() {
rfdset := syscall.FdSet{Bits: [16]int64{int64(1)}}
@thbourlove
thbourlove / 0_reuse_code.js
Created June 26, 2014 11:57
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<?php
$funcache = function ($callable) {
static $backend = [];
return function () use ($callable, &$backend) {
$args = func_get_args();
$key = json_encode($args);
if (array_key_exists($key, $backend)) {
return $backend[$key];
}
return $backend[$key] = call_user_func_array($callable, func_get_args());
<?php
$arr = [];
for ($i = 0; $i < 5000; $i++) {
$arr[$i] = range($i, $i+1);
}
$res = array();
array_walk_recursive($arr, function ($item, $key) use (&$res) {
$res[] = $item;
});
<?php
for ($i = 1; $i <= 10; $i++) {
print implode(range($i, 1), '*').'='.gmp_strval(gmp_fact($i))."\n";
}
@thbourlove
thbourlove / foo.php
Last active December 22, 2015 17:09 — forked from jmikola/foo.php
<?php
$m = new MongoClient('mongodb://admin:admin@192.168.108.19:27017');
$c = $m->findone->foo;
$c->drop();
$c->insert(['_id' => 1, 'x' => str_repeat('z', 1000)]);
$c->insert(['_id' => 2, 'x' => str_repeat('z', 1000)]);
$c->insert(['_id' => 3, 'x' => str_repeat('z', 1000)]);
$c->insert(['_id' => 4, 'x' => str_repeat('z', 1000)]);
$c->insert(['_id' => 5, 'x' => str_repeat('z', 1000)]);
<?php
$arr = [];
for ($i = 0; $i < 100000; $i++) {
$arr[] = rand();
}
$timeStart1 = microtime(true);
foreach ($arr as $value){
$tmp = $value > 1000000000 ? $value : $value - 1000000000;
}
<?php
namespace BmTest;
use Athletic\AthleticEvent;
class IfElse extends AthleticEvent
{
private $arr = [];
public function SetUp()
{