Skip to content

Instantly share code, notes, and snippets.

View YidaChen's full-sized avatar
🎯
Focusing

Yida Chen YidaChen

🎯
Focusing
View GitHub Profile
# -*- coding: utf-8 -*-
import urllib
import requests
import json
import execjs
VIDEO_ID = 'lZnqmZ4ZTP8'
START_TOKEN = 'ytplayer.config = '
END_TOKEN = ';ytplayer.load'
@YidaChen
YidaChen / tcp_server.c
Created August 1, 2016 07:42
Simple socket server in C using threads (pthread library) Compiles on linux
/*
C socket server example, handles multiple clients using threads
Compile
gcc server.c -lpthread -o server
*/
#include<stdio.h>
#include<string.h> //strlen
#include<stdlib.h> //strlen
#include<sys/socket.h>
@YidaChen
YidaChen / SplClassLoader.php
Created July 21, 2016 01:13 — forked from jwage/SplClassLoader.php
Add MIT license.
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
@YidaChen
YidaChen / Install-php7.md
Created July 16, 2016 05:03 — forked from hollodotme/Install-php7.md
Installing php7-fpm with phpredis and xdebug extension on Ubuntu 14.04

Install php7.0-fpm

# remove php5 modules
apt-get autoremove --purge php5-*
# add php-7.0 source list by [Ondřej Surý](https://github.com/oerdnj)
add-apt-repository ppa:ondrej/php
# Update index
apt-get update
# Install php7.0-fpm with needed extensions
@YidaChen
YidaChen / ajax.js
Created June 28, 2016 08:28
ajax.js
$.ajax({
url: 'ajax/edit/marker.php',
type: 'POST',
dataType: 'json',
data: {action: 'delete', type: typeStr, id: id}
})
.done(function(data) {
if(data){
markersType[id].setMap(null);
delete markersType[id];
@YidaChen
YidaChen / mb_substr_replace.php
Created March 15, 2016 03:01 — forked from stemar/mb_substr_replace.php
Multibyte substr_replace(). The mbstring library doesn’t come with a multibyte equivalent of substr_replace(). This function behaves exactly like substr_replace() even when the arguments are arrays.
function mb_substr_replace($string, $replacement, $start, $length=NULL) {
if (is_array($string)) {
$num = count($string);
// $replacement
$replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement);
// $start
if (is_array($start)) {
$start = array_slice($start, 0, $num);
foreach ($start as $key => $value)
$start[$key] = is_int($value) ? $value : 0;
@YidaChen
YidaChen / laravel-ajax.php
Last active September 22, 2015 02:30 — forked from davestewart/laravel-ajax.php
A lightweight example to get Laravel 5 users up to speed with jQuery AJAX
/**
* Laravel / jQuery AJAX code example
* See conversation here: http://laravel.io/forum/04-29-2015-people-asking-about-jquery-ajax
*
* Drop this code into your App/Http/routes.php file, and go to /ajax/view in your browser
* Be sure to bring up the JavaScript console by pressing F12.
*/
// This is your View AJAX route - load this in your browser
Route::get('/ajax/view', function () {
@YidaChen
YidaChen / CSS-third-level-drop-down-menu(transition:opacity).markdown
Created February 3, 2015 10:30
CSS third-level drop-down menu(transition:opacity)
@YidaChen
YidaChen / CSS-third-level-drop-down-menu.markdown
Created February 3, 2015 10:15
CSS third-level drop-down menu