Skip to content

Instantly share code, notes, and snippets.

@sandyUni
sandyUni / getOnlineIp.php
Last active December 29, 2015 08:29
取客户端IP 如果使用多级代理的用户,真实IP是取不到的。
View getOnlineIp.php
<?php
function getOnlineIp() {
$strOnlineIp = "";
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$onlineip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
@sandyUni
sandyUni / getStrTruncate.php
Last active December 29, 2015 08:29
字符串截取,支持中文
View getStrTruncate.php
<?php
function getStrTruncate($string, $length = 80, $etc = ''){
if ($length == 0) return '';
mb_internal_encoding("UTF-8");
$string = str_replace("\n","",$string);
$strlen = mb_strwidth($string);
if ($strlen > $length) {
$etclen = mb_strwidth($etc);
$length = $length - $etclen;
@sandyUni
sandyUni / delTags.php
Last active December 29, 2015 08:29
过滤部分标签
View delTags.php
<?php
function delTags($str)
{
$farr = array(
"/<(\/?)(script|i?frame|style|html|body|title|link|meta|form|input|embed|object|textarea|\?|\%)([^>]*?)>/isU",
"/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU"
);
$tarr = array(
"",
""
@sandyUni
sandyUni / quantizationNoiseSpectrum.m
Created December 20, 2013 11:34
quantization Noise Spectrum analysis.Mybe there are bug over there
View quantizationNoiseSpectrum.m
close all
clear all
% for n=1:10:10000
fsample=1424424;
f=fsample/1020.32;
A=1;
lens=2^20;
N=15;
View phpPerform_dynamic_static_variable_access.php
/**
* test some performance between this and parent
*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
/*
$time_start = microtime_float();
@sandyUni
sandyUni / Perform_dynamic_static_memory_use.php
Created February 6, 2014 16:28
测试使用static变量和自身变量时实例化变量后的内存消耗,实验证明,Static会消耗很少的内存,前提是实例化的类中数据足够多,以至于类本身需要的内存可以忽略
View Perform_dynamic_static_memory_use.php
*/
/**
* test memory comsuming
*/
class base1{
public $a;
public $b;
public $c;
public $d;
@sandyUni
sandyUni / string.py
Created February 24, 2014 07:28
python中关于字符串操作实例
View string.py
#Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
#去空格及特殊符号
s.strip() .lstrip() .rstrip(',')
#复制字符串
#strcpy(sStr1,sStr)
sStr= 'strcpy'
sStr = sStr
@sandyUni
sandyUni / direction.m
Created September 13, 2016 12:48
% direction of nodes p1 and p2. Support 2D and 3D, return the angle from p2 to p1
View direction.m
function [ theta ] = direction( p1,p2 )
% direction of nodes p1 and p2. Support 2D and 3D, return the angle from p2 to p1
% In 2D case, theta will be a scaler indicates the angle from p2 to p1, which ranges from -pi~pi;
% In 3D case theta will be a vector, theta(1) is azimuthal angle (-pi~ pi) and theta(2) is altitude angle(-pi/2~pi/2)
if(length(p1)==2)
v = p1-p2;
theta = atan(v(2)/v(1));
if(v(1)<0)
if(v(2)<0)
theta = theta- pi;
@sandyUni
sandyUni / polarToCartesian
Created September 13, 2016 13:16
convert polar coordinate to Cartesian
View polarToCartesian
function [X,Y,Z] = polarToCartesian(R,logi,lanti)
% convert polar coordinate to Cartesian
% R, logi(-pi~pi), lanti (-1/2*pi~1/2*pi) are Radius,longitude, lantitude
Z = R* sin(lanti);
Y = R* cos(lanti) *sin(logi);
X = R*cos(lanti) *cos(logi);
@sandyUni
sandyUni / resampleSystematic.m
Created October 17, 2016 08:31
resample method in particle filter
View resampleSystematic.m
function [ indx ] = resampleSystematic(w,N)
Q = cumsum(w);
T = linspace(0,1-1/N,N) + rand(1)/N;
T(N+1) = 1;
i=1;
j=1;
indx = zeros(N,1);