Skip to content

Instantly share code, notes, and snippets.

@wolf432
wolf432 / php
Created August 23, 2017 10:23
php写文件,带超时处理
/**
* 写入文件,超时则写入失败
*
* @param mixed $fileName 文件名
* @param mixed $text 要写入的内容
* @param int $timeOut 等待锁的超时时间
* @param string $mode 文件操作类型,同fopen的model参数一致
* @return boolean
*/
function swrite($fileName, $text, $timeOut = 1, $mode = 'a')
@wolf432
wolf432 / js
Created November 9, 2016 03:24
JS获取当前世界
function CurentTime()
{
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
@wolf432
wolf432 / php
Created September 28, 2016 07:57
根据一个批次id获取一批优惠券。根据优惠券获取批次id
<?php
$code = createCode(1,6);
echo code2Id($code[0]);
/**
* 根据id获取一组随机字符串
*
* @param mixed $batch_id
* @param mixed $num
* @access public
* @return void
@wolf432
wolf432 / PHP中奖概率算法
Last active June 28, 2022 08:41
PHP中奖概率算法
<?php
/*
* 经典的概率算法,
* $proArr是一个预先设置的数组,
* 假设数组为:array(100,200,300,400),
* 开始是从1,1000 这个概率范围内筛选第一个数是否在他的出现概率范围之内,
* 如果不在,则将概率空间,也就是k的值减去刚刚的那个数字的概率空间,
* 在本例当中就是减去100,也就是说第二个数是在1,900这个范围内筛选的。
* 这样 筛选到最终,总会有一个数满足要求。
* 就相当于去一个箱子里摸东西,