Skip to content

Instantly share code, notes, and snippets.

aleiphoenix

Block or report user

Report or block aleiphoenix

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aleiphoenix
aleiphoenix / time.date.convertion.php
Created Jan 13, 2011
php time and date convertion
View time.date.convertion.php
<?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";
View get.first.day.of.week.php
<?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);
}
@aleiphoenix
aleiphoenix / placeholder.js
Created Jan 27, 2011
for browsers not supporting HTML5 placeholder attribute
View placeholder.js
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');
View get.first.day.of.week.js
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();
@aleiphoenix
aleiphoenix / recur_mkdir.php
Created Mar 11, 2011
mkdir if not exists recursively
View recur_mkdir.php
<?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){
@aleiphoenix
aleiphoenix / file.transfer.php
Created Mar 11, 2011
transfer file to page
View file.transfer.php
<?
$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');
View demo.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" />
@aleiphoenix
aleiphoenix / poi.md
Created Nov 9, 2011
Points of Interest Spec
View poi.md

Points of Interest

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

功能

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

  • 未来可能加入更多功能

@aleiphoenix
aleiphoenix / uri_mapping.php
Created Jan 11, 2012
simple RoR style uri mapping snippet
View uri_mapping.php
<?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);
@aleiphoenix
aleiphoenix / polipo
Created Apr 8, 2012
polipo runscript for gentoo, supporting symlink name detected multiple service
View polipo
#!/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
You can’t perform that action at this time.