Skip to content

Instantly share code, notes, and snippets.

@simongcc
simongcc / common_regex.txt
Created January 23, 2014 18:37
Regular expression
Reference: http://www.regular-expressions.info/
Email validation
^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$
/*
Edit Page Customization
Customizable:
Column Head (filter: manage_posts_columns => manage_{$post_type}_columns )
Column Contents (filter: manage_posts_custom_column => manage_{$post_type}_custom_column)
Function link (called $views)
Version Tested: 3.8
*/
@simongcc
simongcc / gist:8632996
Last active August 10, 2021 01:07
PHP useful techniques
// foreach by default is using value after "as"
foreach( $num_posts as $value ):
// echo $value."<br>";
endforeach;
// using foreach with key instead of value
foreach( array_keys( $num_posts ) as $key ):
@simongcc
simongcc / wp_post_object_note.php
Last active August 29, 2015 13:55
Wordpress Post Object Notes
// valid outside the loop
$page_object = get_queried_object();
$page_id = get_queried_object_id();
$ID = get_the_ID(); //get the post ID
$post = get_post( $ID )->post_content; // default is post object
// var_dump( get_post( $post->post_content ) );
@simongcc
simongcc / wp_image_fallback_algorithm.php
Created February 1, 2014 23:08
Wordpress image fall back algorithm
/*
fallback order:
use post thumbnail(featured post) if available, otherwise
use first attachment image if available, otherwise
use first image link if available, otherwise
stay blank...
*/
// inside a loop
@simongcc
simongcc / url_manipulation.php
Last active August 29, 2015 13:55
PHP URL Manipulations
// redirect to somewhere else if calling path is not valid(as expected)
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
DEFINE('HTTP_ROOT', $_SERVER['HTTP_HOST']);
$path_arr = explode("/", $_SERVER['REQUEST_URI']);
$url_chk = in_array("path-name", $path_arr);
$location = $protocol . HTTP_ROOT . '/somewhere-to-redirect/';
if( !$url_chk ) header("Location: $location");
@simongcc
simongcc / designer.html
Created September 19, 2014 05:26
designer
<link rel="import" href="../topeka-elements/category-images.html">
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../core-icons/av-icons.html">
<link rel="import" href="../paper-fab/paper-fab.html">
<link rel="import" href="../paper-calculator/paper-calculator.html">
<polymer-element name="my-element">
<template>
/*
Last updated: 2016/Sep/08
step to fetch data from instagram api
1. Register account in instagram
2. Go to API section (since the footer is not fixed at the bottom, one must go to Edit Profile and go to API link at the bottom.
3. Manage Clients > Register a New Client
4. Go to Security Tab inside the New Client
5. add URIs for redirect, only allowed URIs can fetch the access token (URIs can include .html)
6. use this url to get access token:
https://www.instagram.com/oauth/authorize/?client_id=CLIENT_ID&redirect_uri=ALLOWED_URIs&response_type=token&scope=public_content
/*
1. use Apps like Sim Manager to verify if there is any message or contact in the sim cards
*remember Android can only read Sim Card other than Airplane mode
2. if there is message -> go to Messaging -> Settings -> Manage Sim Card Messages, copy to device for backup later
if there is contact -> go to Contact -> Settings -> Contact to display to display Sim Card only contacts
3. Install tools like https://www.wandoujia.com/###
4. Connect the device
5. Go to contact -> select Sim Card only in the top right selection -> Select All -> Export -> Select Format -> Save
6. Since message is in device, can be exported together if there is no need to split them to backup separately.
@echo off
rem for Windows environment
rem after installing imageMagick in windows
rem convert interlace *.jpg to progressive *.jpg in current folder
rem for /r %%i in (*) do magick convert -interlace Plane %%i %%~na
rem for /r %%a in (*.jpg) do echo "%%~na.jpg"
for /r %%a in (*.jpg) do magick convert -interlace Plane "%%~na.jpg" "%%~na.jpg"