Skip to content

Instantly share code, notes, and snippets.

View Jason-cqtan's full-sized avatar
🎯
Focusing

niL Jason-cqtan

🎯
Focusing
View GitHub Profile
@Jason-cqtan
Jason-cqtan / transEmoji.php
Last active June 4, 2020 06:47
编码、解码文本中带有的emoji
<?php
/**
* 编码
*/
function userTextEncode($str){
if(!is_string($str))return $str;
if(!$str || $str=='undefined')return '';
$text = json_encode($str); //暴露出unicode
@Jason-cqtan
Jason-cqtan / list2Tree.php
Created May 25, 2020 06:14
父子关系列表转树形结构
/**
* 创建树形结构
* @param [type] $data [description]
* @param [type] $parent_id [description]
* @return [type] [description]
*/
public function getTree($data,$parent_id){
$result= array();//结果数组
$len = 0;
for($i=0;$i<count($data);$i++){
@Jason-cqtan
Jason-cqtan / fibonacii.go
Created January 21, 2020 08:22
斐波那契数列go版
package main
import (
"fmt"
"math"
)
func main() {
//返回10个斐波那契数列,todo 使用int,结果数字会越界
fibonacciIndex(10)
@Jason-cqtan
Jason-cqtan / base64.php
Created November 7, 2019 07:03
php图片base64编码解码
/**
* 图片编码
* @param string $img
* @param bool $imgHtmlCode
* @return string
*/
function imgBase64Encode($img = '', $imgHtmlCode = true)
{
//如果是本地文件
if(strpos($img,'http') === false && !file_exists($img)){
@Jason-cqtan
Jason-cqtan / randonum.go
Last active October 17, 2019 09:49
生成随机数
package main
import (
"fmt"
"math/rand"
"time"
)
@Jason-cqtan
Jason-cqtan / getsegmentMonth.php
Created September 29, 2019 08:40
获取指定月份列表时间
/**
* 获取指定月份列表时间
* @param $year int 哪年
* @param $start_month int 起止月份
* @param $end_month int 截止月份
* @return array
*/
protected function getMonths($year, $start_month, $end_month)
{
$month = [];
@Jason-cqtan
Jason-cqtan / bin_sch.php
Created September 17, 2019 04:29
php二分查找
function bin_sch($array, $low, $high, $k){
if ($low <= $high){
$mid = intval(($low+$high)/2);
if ($array[$mid] == $k){
return $mid;
}elseif ($k < $array[$mid]){
return bin_sch($array, $low, $mid-1, $k);
}else{
return bin_sch($array, $mid+1, $high, $k);
}
@Jason-cqtan
Jason-cqtan / selectSort.php
Created September 17, 2019 04:26
php选择排序
function findSmall($arr){
$small = $arr[0];
$small_index = 0;
for ($i=0; $i < count($arr); $i++) {
if($arr[$i] < $small){
$small_index = $i;
$small = $arr[$i];
}
}
return $small_index;
@Jason-cqtan
Jason-cqtan / quickSort.php
Created September 17, 2019 04:25
php快速排序
function quickSort($array)
{
if(!isset($array[1])) return $array;
$base = $array[0]; //获取一个用于分割的关键字,一般是首个元素
$leftArray = [];
$rightArray = [];
for($i=1; $i<count($array); $i++)
{
if($array[$i] > $base)
@Jason-cqtan
Jason-cqtan / bubble_sort.php
Created September 17, 2019 04:16
php冒泡排序算法
/**
* 冒泡排序算法
* @param array $arr
* @return array
*/
function bubble_sort($arr) {
// 判断参数是否为数组,且不为空
if (!is_array($arr) || empty($arr)) {
return $arr;
}