Skip to content

Instantly share code, notes, and snippets.

@nemoTyrant
nemoTyrant / server.php
Created November 2, 2017 08:17
resumable.js server side code
<?php
// check if file chunk is already uploaded
Route::get('resumable', function () {
// Array
// (
// [_token] => xLPuoAptQyWm0FfyAXJSAY1Gxr3lTzJkL9ECt81c
// [resumableChunkNumber] => 1
// [resumableChunkSize] => 2097152
// [resumableCurrentChunkSize] => 90482
@nemoTyrant
nemoTyrant / geohash.php
Created November 17, 2016 04:16
geohash
<?php
class Geohash
{
private $coding = "0123456789bcdefghjkmnpqrstuvwxyz";
private $codingMap = array();
public function __construct()
{
//build map from encoding char to 0 padded bitfield
for ($i = 0; $i < 32; $i++) {
@nemoTyrant
nemoTyrant / removeAds.js
Created September 28, 2016 09:18
去除百度搜索页面Adblocke Plus无法去除的广告
// ==UserScript==
// @name remove Baidu ads
// @namespace http://sosonemo.me/
// @version 0.1
// @description remove Baidu ads
// @author NemoTyrant
// @include *www.baidu.com*
// @grant none
// ==/UserScript==
@nemoTyrant
nemoTyrant / gen.php
Created May 25, 2016 05:58
nginx secure link
<?php
$ts = '1463646983';
$hash = str_replace('=', '',strtr(base64_encode(md5('1463646983 secret', TRUE)), '+/', '-_')); // base64url
echo $hash;
?>
@nemoTyrant
nemoTyrant / download.php
Last active November 17, 2016 04:32
download large file through php with rate limitation
<?php
$local_file = 'test.mp4';
$download_file = 'name.zip';
$file = fopen($local_file, "r");
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 1000;
$chunk_size = 468;
if (file_exists($local_file) && is_file($local_file)) {
@nemoTyrant
nemoTyrant / table.php
Last active May 5, 2018 15:32
等额本息还款计划表
<?php
$P = 490000; // 本金
$R = 0.0539 / 12; // 月利率
$N = 120; // 还款期数
$startDate = "2016-2-7";
$timestamp = strtotime($startDate);
$M = round($P * ($R * pow(1 + $R, $N)) / (pow(1 + $R, $N) - 1), 2);
echo "每月还款为 " . $M . " 元\n";