Skip to content

Instantly share code, notes, and snippets.

@safecat
safecat / latlng2xy.php
Last active August 29, 2015 14:01
PHP Mercator Projection
<?php
//based on http://www.cnblogs.com/enjoyeclipse/archive/2013/01/18/2865700.html
function latlng2xy($lat, $lng, $zoom){
if (abs($lat) > 85.0511287798066){
return false;
}
$sin_phi = sin($lat * M_PI / 180);
$norm_x = $lng / 180;
$norm_y = (0.5 * log((1 + $sin_phi) / (1 - $sin_phi))) / M_PI;
$tileRow = pow(2, $zoom) * ((1 - $norm_y) / 2);
@safecat
safecat / gist:256832539df27d2144e1
Created May 10, 2014 09:19
Trim image with Imagemagick
# based on http://stackoverflow.com/questions/23577931/get-offset-from-imagemagick-trim/23578928?noredirect=1#23578928
convert -debug Coder longyan_1.png -trim longyan_1.trimed.png 2>&1 | sed -n '/Setting up oFFs chunk/ s/.*x=/x=/p'
# x=181, y=118, units=0
@safecat
safecat / gist:e3764e1eb670a05f3f0e
Last active May 10, 2016 16:00
Nginx log rotate
# 日志切割时间
vi /etc/crontab
# 把cron.daily的时间改为0 0
# 日志切割文件存储格式
vi /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 52
@safecat
safecat / uniqid2datetime.php
Last active August 29, 2015 14:01
Uniqid to datetime
<?php
//based on http://jason.pureconcepts.net/2013/09/php-convert-uniqid-to-timestamp/
echo echo date('Y-m-d H:i:s', hexdec(substr('53796ed677000', 0, -5)));
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@safecat
safecat / gist:7542a43ed845a4e121c7
Created June 27, 2014 09:49
Enable php5-mcrypt in Ubuntu 14.04
cd /etc/php5/mods-available
sudo ln -s ../conf.d/mcrypt.so
sudo php5enmod mcrypt
sudo /etc/init.d/apache2 restart
sudo apt-get remove php5-snmp
@safecat
safecat / gist:52274d8ffcedc07ccff3
Last active August 29, 2015 14:04
Laravel in Subfolder (rename public to subfolder name)
Laravel in Subfolder (rename public to subfolder name)
===INTRO===
Assume we need http://localhost/miao/ instead of http://localhost/laravel_app/public/
===FILES===
|laravel_app
|-app
|-bootstrap
|-miao(rename from public)
|-vendor
|-server.php
@safecat
safecat / gist:d1099c16aa4903fa41b1
Created July 25, 2014 08:56
Install php5 5.4 on ubuntu 12.04
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5 php5-fpm php5-curl php5-gd php5-intl php5-imagick php5-imap php5-mcrypt php5-memcached php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-mysqlnd php5-xcache
@safecat
safecat / gist:ecf5ea254ef4d15f97f0
Created September 2, 2014 06:00
uetime 个性化日期显示
<?php
/**
* 个性化日期显示
* @static
* @access public
* @param datetime $times 日期
* @return string 返回大致日期
* @example 示例 ueTime('')
* @author http://segmentfault.com/q/1010000000650101
*/