Skip to content

Instantly share code, notes, and snippets.

View changs1986's full-sized avatar

changs1986

  • 22:38 (UTC +08:00)
View GitHub Profile
@changs1986
changs1986 / util.php
Created November 25, 2015 04:05
utility php gitst
<?php
//生成唯一数字id
base_convert(uniqid('', true), 16, 10);
?>
@changs1986
changs1986 / uuid.js
Created March 29, 2016 02:12
js uuid
function uuid() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
<?php
/**
* 读取文件前几个字节 判断文件类型
*
* @return String
*/
function checkTitle($filename) {
$file = fopen($filename, "rb");
$bin = fread($file, 2); //只读2字节
fclose($file);
@changs1986
changs1986 / geohash
Created October 12, 2016 02:01
用geohash来定位
<?php
/**
* Geohash:将一个经纬度信息,转换成一个可以排序,可以比较的字符串编码
* ref http://blog.jobbole.com/80633/
*
* 找一个点附近的所有人 步骤:先将当前经纬度编码,然后根据需要的精度选择编码长度(eg:长度为8位精度like '12345678%'在19米左右)
* 找出附近的八个和当前格子前缀相同的记录,如果需要排序则需要计算每个点到当前点的距离然后排序
*
* $hashcode = $hash->encode($lat, $long);
* //十公里范围的hash长度为5位
@changs1986
changs1986 / js数组遍历删除元素
Created November 22, 2016 02:47
js数组遍历删除元素
for (var i = array.length - 1; i >= 0; i--) {
if (array[i].status == 1) {
array.splice(i, 1);
}
}
@changs1986
changs1986 / 计算两个坐标之间的距离
Created July 24, 2017 09:15
计算两个坐标之间的距离
/**
* 计算两个坐标之间的距离(米)
* @param float $fP1Lat 起点(纬度)
* @param float $fP1Lon 起点(经度)
* @param float $fP2Lat 终点(纬度)
* @param float $fP2Lon 终点(经度)
* @return int
*/
function distanceBetween($fP1Lat, $fP1Lon, $fP2Lat, $fP2Lon){
@changs1986
changs1986 / gmail.php
Created October 25, 2018 05:18 — forked from tonivj5/gmail.php
Send email using a PHP Generator and cURL
class Gmail {
private $mail;
private $email;
private $pass;
public function __construct($email, $pass){
$this->email = $email;
$this->pass = $pass;
}