Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
sp3c73r2038 / time.date.convertion.php
Created January 13, 2011 04:22
php time and date convertion
<?php
/* from unix timestamp to date */
$time = time();
echo date("Y-m-d H:i:s", $time),"\n";
/* from date string to timestamp */
$date = '2011-01-01 00:00:00';
echo strtotime($date),"\n";
<?php
/* input the year and week you want, then get the date! */
function getFirstDayOfWeek($year, $weeknr, $date_format="Y-m-d"){
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
$date = strtotime('+' . ($weeknr - 1) . ' weeks', $monday);
return date($date_format,$date);
}
@sp3c73r2038
sp3c73r2038 / placeholder.js
Created January 27, 2011 04:11
for browsers not supporting HTML5 placeholder attribute
function activatePlaceholders() {
var detect = navigator.userAgent.toLowerCase();
if (detect.indexOf('safari') > 0) {
return false;
}
var inputs = document.getElementsByTagName('input');
for (var i=0;i<inputs.length;i++) {
if (inputs[i].getAttribute('type') == 'text') {
if (inputs[i].getAttribute('placeholder') && inputs[i].getAttribute('placeholder').length > 0) {
var className = inputs[i].getAttribute('class');
function getFirstDayOfWeek(date) {
if (!date) {
date = new Date();
}
var firstDay = new Date(date - (date.getDay() - 1) * 86400000);
return firstDay;
}
function getLastDayOfWeek(date) {
if (!date) {
date = new Date();
@sp3c73r2038
sp3c73r2038 / recur_mkdir.php
Created March 11, 2011 03:03
mkdir if not exists recursively
<?php
function recur_mkdir($path, $seperator = "/"){
if($path){
$folders = explode($seperator, $path);
if($folders){
$current_path = '';
foreach($folders as $folder){
$current_path .= $folder.$seperator;
if(!file_exists($current_path) && $current_path){
@sp3c73r2038
sp3c73r2038 / file.transfer.php
Created March 11, 2011 09:44
transfer file to page
<?
$expire=180;
$showname = "testfile.tgz";
$file = '/var/www/snippet/index.html';
$length = filesize($file);
/* the file type is accroding to the mime type, not concern on file name */
header('Content-Description: File Transfer');
header('Content-Type: text/html');
<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.7.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/date.format.js"></script>
<script type="text/javascript" src="js/browser.detection.js"></script>
<link type="text/css" href="css/custom-theme/jquery-ui-1.8.7.custom.css" rel="stylesheet" />
<link type="text/css" href="css/demo_page.css" rel="stylesheet" />
@sp3c73r2038
sp3c73r2038 / poi.md
Created November 9, 2011 08:13
Points of Interest Spec

Points of Interest

通过给出的地点或者坐标信息,查询周边区域的地理信息。

功能

  • 地理信息搜索,通过给定的关键字给出地理的标准名字和坐标。还提供给予坐标信息返回附近的地点等等。

  • 未来可能加入更多功能

@sp3c73r2038
sp3c73r2038 / uri_mapping.php
Created January 11, 2012 04:16
simple RoR style uri mapping snippet
<?php
$str = "/parent/:dbname/:collname/:id";
function uri2regex ($str, &$params_keys) {
$word = "([0-9a-zA-Z_-]+)";
$flag = preg_match_all("/:\w+/",$str, $matches);
$params = $matches[0];
array_walk($params, 'uriNormalize');
$ret = preg_replace("/:\w+/", $word, $str);
@sp3c73r2038
sp3c73r2038 / polipo
Created April 8, 2012 09:43
polipo runscript for gentoo, supporting symlink name detected multiple service
#!/sbin/runscript
# Copyright 1999-2011 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-proxy/polipo/files/polipo.initd,v 1.6 2011/12/31 21:11:37 idl0r Exp $
POLIPO=${SVCNAME#*.}
POLIPOCONF="/etc/polipo/${POLIPO}.conf"
if [ -n "$POLIPO" ] && [ $SVCNAME != "polipo" ]; then
PIDFILE="/var/run/polipo.${POLIPO}.pid"
else