Skip to content

Instantly share code, notes, and snippets.

@wgm89
wgm89 / gist:7331642
Created November 6, 2013 06:02
substr
function sub_str($str,$start=0,$length=60,$left="...",$charset="utf-8")
{
if($charset=="utf-8"){
$index=0;
$index1=0;
$result="";
$haslen=0;
for($i=0;$i<$length;$i++)
{
$index1=$index;
@wgm89
wgm89 / gist:7347613
Created November 7, 2013 01:51
算法
合并排序
-----------------------------------
$lista = array(3,8,4);
$listb = array(5,6,2);
print_r(mergeSort($lista, $listb));
function mergeSort($la,$lb) {
//sort two sub-lists
sort($la);
@wgm89
wgm89 / gist:8091154
Created December 23, 2013 02:55
google pronunciation
<?php
$newfname = __DIR__.'/1.wmv';
$reqBaseURL = 'http://translate.google.com/translate_tts?tl=en&q=how%20do%20you%20do';
$remote_file = fopen($reqBaseURL, "rb");
if ($remote_file){
$newf = fopen($newfname, "wb");
if ($newf){
while(!feof($remote_file)){
fwrite($newf, fread($remote_file, 1024 * 8),1024 * 8);
}
@wgm89
wgm89 / gist:11030047
Created April 18, 2014 07:47
repair ubuntu resolution
Screen Resolution stuck at 640x480 after installing
In /etc/X11/xorg.conf, look for these two lines :
HorizSync 28.0 - 33.0
VertRefresh 43.0 - 72.0
and replace them with
HorizSync 30.0 - 83.0
@wgm89
wgm89 / gist:a35003b585a84966a4b7
Created May 9, 2014 04:00
点击 排除 某区域
$(document).click(function(e){
// Check if click was triggered on or within #menu_content
if( $(e.target).closest("#menu_content").length > 0 ) {
return false;
}
// Otherwise
// trigger your click function
});
@wgm89
wgm89 / gist:af5811f2d4a2797ff6ec
Last active August 29, 2015 14:01
php message queue
消息队列(message queue)也是Linux系统进程间通信的一种方式。
除了现有的一些消息队列解决方案以外,PHP对共享内存段的操作有两组函数:System V IPC和Shared Memory。 其中System V IPC由AT&T的贝尔实验室对早期的UNIX系统贡献而来,现在的linux系统都完美的继承了下来,该系列函数能够更方便的操作数据,无需像Shared Memory那样必须自己掌握读写时的偏移量、长度等,也不用序列化/反序列化来回转换(因为Shared Memory函数只支持字符串格式的数据参数)。但是System V IPC系列不支持Windows,所以如果要在win环境下使用,只能选Shared Memory。
PHP的System V msg模块是对Linux系统支持的System V IPC中的System V消息队列函数族的封装。我们需要利用sysvmsg模块提供的函数来进进程间通信。
<?php
$message_queue_key = ftok(__FILE__, 'a');
$message_queue = msg_get_queue($message_queue_key, 0666);
var_dump($message_queue);
$message_queue_status = msg_stat_queue($message_queue);
@wgm89
wgm89 / gist:ec9a7cb5dafbea9947a7
Last active August 29, 2015 14:01
filter data
<?php
protected function _strip_text($data, $type=false){
if(is_array($data)){
foreach($data as $key=>$val){
$data[$key] = $this->_strip_text($val, $type);
}
}elseif(is_object($data)){
foreach(get_object_vars($data) as $property => $val) {
$data->$property = $this->_strip_text($val, $type);
@wgm89
wgm89 / gist:51b880a32323e3722be2
Created June 19, 2014 10:44
encrypt , decrypt
<?php
class encrypt
{
private $key;
private $uword;
private $eword;
private $letters;
/**
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 设定主题
set t_Co=256
syntax enable
set background=dark
colorscheme molokai
" 设定默认解码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#define POSTURL "http://127.0.0.1"
#define LOGFILE "post.log"
#define RESOURCE_KEY ""
#define CUSTOM_VALUE ""
#define UPLOAD_TOKEN ""