Skip to content

Instantly share code, notes, and snippets.

@suyan
suyan / test.json
Created September 16, 2018 05:05
[test snippet] This is a test snippet #test
{
"test"
}
# Dropzone Action Info
# Name: Qiniu
# Description: Upload images to qiniu.com
# Handles: Files
# Creator: Su Yan
# URL: http://yansu.org
# OptionsNIB: ExtendedLogin
# Events: Clicked, Dragged
# KeyModifiers: Command, Option, Control, Shift
# SkipConfig: No
class Solution {
public:
int strStr(const char *source, const char *target) {
// check if source or target is nullptr
if (source == nullptr || target == nullptr) {
return -1;
}
string s(source), t(target);
if (t.size() == 0) {
return 0;
<?php
$test_json = file_get_contents('/tmp/test_json');
$byte_array = json_decode($test_json, true);
$byte_string = implode(array_map("chr", $byte_array['fieldInfo']['image']));
$img_string = base64_encode($byte_string);
echo '<img src="data:image/jpg;base64,'.$img_string.'"/>';
#!/bin/bash
if inotifywait -e modify -e move -e create -r /var/www ; then
while inotifywait -e modify -e move -e create -t 30 -r /var/www ; do echo "waiting" ; done
supervisorctl reload
fi
@suyan
suyan / git_update_history
Last active October 6, 2015 22:50
update git history
git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "test@test.com" ];
then
GIT_AUTHOR_NAME="First Last";
GIT_COMMITTER_NAME="First Last";
GIT_AUTHOR_EMAIL="user@user.com";
GIT_COMMITTER_EMAIL="user@user.com";
git commit-tree "$@";
else
git commit-tree "$@";
@suyan
suyan / dump_closure.php
Last active October 6, 2015 22:50
dump closure
<?php
function closure_dump(Closure $c) {
$str = 'function (';
$r = new ReflectionFunction($c);
$params = array();
foreach($r->getParameters() as $p) {
$s = '';
if($p->isArray()) {
$s .= 'array ';
} else if($p->getClass()) {
@suyan
suyan / php_socket.php
Last active August 29, 2015 14:00
php socket
<?php
// server
$Server = D('Server');
set_time_limit(0);
$host = C('DAEMON_HOST');
$port = C('DAEMON_PORT');
// 创建一个tcp流
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)
or die("socket_create() failed:" . socket_strerror(socket_last_error()));
// 设置阻塞模式
@suyan
suyan / database_insert.php
Last active August 29, 2015 14:00
database test of large number of insert
<?php
/*
* @Author: Su Yan <http://yansu.org>
* @Date: 2014-04-16 09:26:21
* @Last Modified by: Su Yan
* @Last Modified time: 2014-04-16 16:43:23
*/
$dsn = 'mysql:host=localhost;dbname=test';
$db = new PDO($dsn,'root',''array(PDO::ATTR_PERSISTENT => true));
//删除上次的插入数据
@suyan
suyan / laravel_xhprof.php
Last active August 29, 2015 13:57
laravel_xhprof
<?php
include_once '/usr/local/Cellar/php55-xhprof/254eb24/xhprof_lib/utils/xhprof_lib.php';
include_once '/usr/local/Cellar/php55-xhprof/254eb24/xhprof_lib/utils/xhprof_runs.php';
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
$app->run();
$xhprof_data = xhprof_disable();