Skip to content

Instantly share code, notes, and snippets.

View Leask's full-sized avatar
🏠
Working from home

Sixia "Leask" Huang Leask

🏠
Working from home
View GitHub Profile
@Leask
Leask / libfilesystem.php
Created July 19, 2013 07:52
A lightweight file system lib in php
<?php
# A lightweight file system lib in php
# by @leaskh
class libFileSystem {
public function checkPath($path) {
return $path === '/' || $path === '~';
}
@Leask
Leask / build
Last active December 19, 2015 23:59
Build script for php projects
#!/usr/bin/env php
<?php
// by @leaskh
// config
error_reporting(E_ALL ^ E_NOTICE);
$binFolder = 'bin';
@Leask
Leask / gravatar.php
Created July 19, 2013 10:57
Get either a Gravatar URL or complete image tag for a specified email address.
<?php
/**
* Get either a Gravatar URL or complete image tag for a specified email address.
*
* @param string $email The email address
* @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
* @param boole $img True to return a complete IMG tag False for just the URL
@Leask
Leask / imessage.php
Created July 19, 2013 11:00
Make a link for "iMessage me" on the web
<a href="<?php echo preg_match('/Macintosh/', $_SERVER['HTTP_USER_AGENT']) ? 'imessage' : 'sms'; ?>:[email protected]">iMessage me!</a>
@Leask
Leask / replaceurl.php
Created July 19, 2013 11:04
Replacing URLs
<?php
/**
* Replacing URLs
* @param: string.
* @return: string.
*/
function ParseURL($str) {
return preg_replace([
"/(?<=[^\]A-Za-z0-9-=\"'\\/])(https?|ftp|gopher|news|telnet|mms){1}:\/\/([A-Za-z0-9\/\-_+=.~!%@?#%&;:$\\()|]+)/is",
@Leask
Leask / TraversingFileSystems.php
Created July 19, 2013 11:06
Traversing File Systems in php
<?php
/**
* 常规遍历方法
* 常规遍历方法是指从PHP4开始就可以使用的方法,它是结合使用opendir()函数和readdir()函数,通过打开目录,读取目录和关闭目录,逐一判断列出所有的文件。
* @param string $dir 路径名
* @return array 所有文件的路径数组
*/
function get_files1($dir) {
$files = array();
@Leask
Leask / viewsource.applescript
Created July 19, 2013 11:10
View Safari's web page source in TextMate
(*
* Safari View Source in TextMate - v1.0 - 2/21/2010
* http://benalman.com/projects/safari-view-source-in-textmate/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*)
tell application "Safari"
@Leask
Leask / solar2Lunar.php
Created July 19, 2013 11:14
Solar to Lunar
<?php
/*
@ PHP阳历到农历转换的一个类
@ Cal函数 将阳历日期转换成阴历日期
@ returnInput 返回输入的日期
@ Recoded By Androidyue
*/
class Calendar
{
#农历每月的天数
@Leask
Leask / happybirthday.applescript
Created July 19, 2013 15:47
Sing Happy Birthday in AppleScript
set currentUser to long user name of (get system info)
set firstName to first word of currentUser
set lastName to last word of currentUser
set noteValues to {56, 56, 58, 56, 61, 60, 50, 56, 56, 58, 56, 63, 61, 50, 56, 56, 68, 65, 61, 60, 58, 50, 66, 66, 65, 61, 63, 61} -- F
-- set noteValues to {65, 65, 67, 65, 70, 69, 60, 65, 65, 67, 65, 72, 70, 60, 65, 65, 77, 74, 70, 69, 67, 60, 75, 75, 74, 70, 72, 70} -- D
-- set noteValues to {55, 55, 57, 55, 60, 59, 50, 55, 55, 57, 55, 62, 60, 50, 55, 55, 67, 64, 60, 59, 57, 50, 65, 65, 64, 60, 62, 60} -- E
set syllables to {"hap", "p", "birth", "day", "to", "you", "[[slnc 500]]", "hap", "p", "birth", "day", "to", "you", "[[slnc 500]]", "hap", "p", "birth", "day", "dear", firstName, lastName, "[[slnc 500]]", "hap", "p", "birth", "day", "to", "you"}
@Leask
Leask / suffixtreecreation.cpp
Created July 19, 2013 16:38
Suffix tree creation
//
// Suffix tree creation
//
// Mark Nelson, updated December, 2006
//
// This code has been tested with Borland C++ and
// Microsoft Visual C++.
//
// This program asks you for a line of input, then
// creates the suffix tree corresponding to the given