Skip to content

Instantly share code, notes, and snippets.

View GoldenEra's full-sized avatar
🎯
Focusing

Richard GoldenEra

🎯
Focusing
View GitHub Profile
{"lastUpload":"2021-04-23T04:09:18.318Z","extensionVersion":"v3.4.3"}
@GoldenEra
GoldenEra / download.php
Created October 8, 2015 03:34
dowload pdf
ob_start();
$file = $_GET['doc'];
if(!file_exists($file))
$file = dirname(__FILE__).'/wp-content/plugins/flexpaper/pdf/'.$file;
if (file_exists($file))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
@GoldenEra
GoldenEra / javascript_cache.js
Created June 12, 2015 08:53
javascript cache
//reference:http://www.dustindiaz.com/javascript-cache-provider
function CacheProvider() {
// values will be stored here
this._cache = {};
}
if (CacheProvider.hasLocalStorage) {
Storage.prototype.setObject = function(key, value) {
this.setItem(key, JSON.stringify(value));
@GoldenEra
GoldenEra / functions.php
Created May 5, 2015 04:24
php:extract zip and rar file
/**
* extract rar or zip file
*
* @since [1.0]
* @author Richard
* @date 2015-05-05
*
* @param [string] $file_path ["D:\file\path\a.rar"]
* @param [string] $to_path ["D:\extract\to\path"]
* @return [boolean]
@GoldenEra
GoldenEra / functions.php
Created May 5, 2015 04:17
php: get suffix from a given file name
/**
* get suffix from a given file_name
*
* @since [1.0]
* @see [filetype()]
* @author Richard
* @date 2015-05-05
*
* @param [string] $file_name [a.txt]
* @return [sring] [txt]
@GoldenEra
GoldenEra / functions.php
Created May 5, 2015 03:43
php:read files
/**
* A simple function that find all files by extension an return it by an array.
*
* @since [1.0]
* @see [http://php.net/manual/en/function.glob.php]
* @date 2015-05-05
*
* @param [string] $directory
* @param array $extensions like "xml,zip,txt"
* @return [array] array("zip" => array( [0] => "D:\a.zip", [1] => "D:\b.zip"), "xml" => array( [0] => "D:\1.xml"))
@GoldenEra
GoldenEra / functions.php
Created May 5, 2015 01:57
php: wordpress
/**
* [get_posts_by_slug description]
* @param [int] $num [number of posts you want to get]
* @param [string] $slug_name [slug's name]
* @return [array] [List of WP_Post objects.]
*/
function get_by_slug($num, $slug_name, $post_type = array('featured', 'social_post')){
if (!is_string($slug_name)) {
return false;
@GoldenEra
GoldenEra / functions.php
Last active August 29, 2015 14:20
php:get the imag's src and alt from a html
/**
* get src of the first img tag from string
* @param [type] string
* @param [type] boolean if true get all the images' src
* @return [type] first src or none
*/
function get_img_src($str, $isAll = false){
preg_match('/\<img.*src=\"(.*?)\"/i',$str,$src);
preg_match('/alt\s*=\"(.*?)\"/i',$str,$alt);
if ($isAll) {
@GoldenEra
GoldenEra / functions.php
Created May 5, 2015 01:39
php:get description
/**
* [get_desc get a simple description of a long content]
* @param [str] $str
* @param integer $len [the length you want to cut,default 50]
* @return [string] [Result after cutting]
*/
function get_desc($str,$len = 50){
$str = strip_tags($str);
if (strlen($str) < $len) {
return $str;