Skip to content

Instantly share code, notes, and snippets.

View c9s's full-sized avatar

c9s

  • Taipei, Taiwan
  • 09:41 (UTC +08:00)
  • X @c9s
View GitHub Profile
@c9s
c9s / .gvimrc
Created November 3, 2017 06:13
" vim:fdm=marker:et:fdl=0:
"
" Author: Yo-An Lin <yoanlin93 {at} gmail.com>
" URL: http://c9s.blogspot.com/
"
" Font {{{
" set gfn=Dejavu\ Sans\ Mono\ 9
" set gfn=Andale\ Mono:h14
":set guifont=Screen15,\ 7x13,font\\,with\\,commas
if has('gui_mac')
@c9s
c9s / debian-8-opencv-gpu
Last active September 26, 2017 08:26
This script allows you to install Nvidia CUDA 8 and OpenCV with GPU support
#!/bin/bash
# update the base system packages
apt-get update && apt-get upgrade -y
# Update source list for cuda and python3.6
cat <<ENDLIST >> /etc/apt/sources.list
# non-free to nvidia-cuda-toolkit
deb http://ftp.de.debian.org/debian stretch non-free
deb http://ftp.de.debian.org/debian stretch contrib
@c9s
c9s / index.html
Last active August 10, 2017 04:24
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
<?php
public function migrate(Chunk $chunk, Shard $dstShard, array $schemas)
{
$shardId = $chunk->getShardId();
if ($dstShard->id === $shardId) {
throw new InvalidArgumentException("{$dstShard->id} == $shardId");
}
try {
<?php
public function testRepoFetchColumn()
{
$this->assertResultSuccess(Book::create([ 'title' => 'Book 1' ]));
$this->assertResultSuccess(Book::create([ 'title' => 'Book 2' ]));
// create one book with duplicated title
$this->assertResultSuccess(Book::create([ 'title' => 'Book 2' ]));
<?php
/**
* An alias for BaseRepo::loadByKeys
*/
protected static function loadByKeys(array $args, $byKeys = null)
{
if (static::SHARD_MAPPING_ID) {
return static::shards()->first(function(BaseRepo $repo, Shard $shard) use ($arg, $byKeys) {
return $repo->loadByKeys($args, $byKeys);
<?php
namespace AuthorBooks\Model;
require_once __DIR__ . '/AuthorSchemaProxy.php';
use Maghead\Schema\SchemaLoader;
use Maghead\Result;
use Maghead\Inflator;
use SQLBuilder\Bind;
use SQLBuilder\ArgumentArray;
use SQLBuilder\Universal\Query\InsertQuery;
use SQLBuilder\Driver\BaseDriver;
<?php
namespace AuthorBooks\Model;
require_once __DIR__ . '/AuthorSchemaProxy.php';
use Maghead\Schema\SchemaLoader;
use Maghead\Result;
use Maghead\Runtime\BaseModel;
use Maghead\Inflator;
use SQLBuilder\Bind;
use SQLBuilder\ArgumentArray;
use PDO;
|-------------------------------------------------------------------------------------------------------|
| Library | Insert | findPk | complex| hydrate| with | memory usage | time |
| --------------------------------:| ------:| ------:| ------:| ------:| ------:| ------------:| ------:|
| PDO | 72 | 12 | 29 | 69 | 220 | 1,689,176 | 0.41 |
| Maghead | 395 | 9 | 176 | 205 | 365 | 10,485,760 | 1.16 |
| | | | | | | | |
| LessQL | 366 | 70 | 377 | 364 | 363 | 10,078,872 | 1.55 |
| | | | | | | | |
| YiiM | 714 | 86 | 436 | 292 | 614 | 8,388,608 | 2.16 |
| YiiMWithCache | 693 | 83 | 435 | 303
<?php
namespace AuthorBooks\Model;
require_once __DIR__ . '/AuthorSchemaProxy.php';
use Maghead\Schema\SchemaLoader;
use Maghead\Result;
use Maghead\BaseModel;
use Maghead\Inflator;
use SQLBuilder\Bind;
use SQLBuilder\ArgumentArray;
use PDO;