Skip to content

Instantly share code, notes, and snippets.

View ucheng's full-sized avatar
💭
😄

Yu-Cheng Wang ucheng

💭
😄
View GitHub Profile
@ucheng
ucheng / gmap.html
Last active March 8, 2023 06:51
Get current location and show marker on Google Map
<!DOCTYPE html>
<html lang="en">
<head>
<!--https://developers.google.com/maps/documentation/javascript/tutorial?hl=zh-tw#HelloWorld-->
<meta charset="UTF-8">
<title>Google Map</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#location-map { height: 300px; }
@ucheng
ucheng / php-pdf.php
Last active June 23, 2022 08:43
Display pdf content in browser
<?php
$response = wp_remote_post($url, $args = array());
$header_content = (array) wp_remote_retrieve_headers( $response );
$header = current($header_content);
$data = wp_remote_retrieve_body( $response );
if ( array_key_exists('content-type', $header) ) {
if ( $header['content-type'] === 'application/pdf') {
header("Content-type: application/pdf");
header('Content-Length: '.strlen( $data ));
@ucheng
ucheng / mobilecheck.js
Created September 17, 2015 03:13
mobile check
// http://coveroverflow.com/a/11381730/989439
function mobilecheck() {
var check = false;
(function(a) {
if (/(android|ipad|playbook|silk|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)
@ucheng
ucheng / ReadStringToJsonNodeAndUpdateIt.java
Created July 18, 2012 06:14
Add or Update Json field value
package com.stanley;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
public class ReadStringToJsonNodeAndUpdateIt {
@ucheng
ucheng / edd-ecpay.php
Created May 28, 2021 00:46
EDD x ECPay Payment Gateway
<?php
// registers the gateway
function pw_edd_register_gateway($gateways) {
$gateways['ecpay_credit'] = array( 'admin_label' => '綠界-信用卡', 'checkout_label' => __('綠界-信用卡', 'your_textdomain'));
return $gateways;
}
add_filter('edd_payment_gateways', 'pw_edd_register_gateway');
// process the payment
@ucheng
ucheng / customer_ip.php
Created May 22, 2021 15:15
get customer ip
/**
* Get customer ip
*
* @return string
*/
private function get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
// check ip from share internet
@ucheng
ucheng / show_customer_linked_affiliate.php
Created April 28, 2020 08:09
show customer linked affiliate
<?php
add_action('show_user_profile', 'mys_additional_profile_fields', 9);
add_action('edit_user_profile', 'mys_additional_profile_fields', 9);
function mys_additional_profile_fields($user)
{
echo '<h2>連結的推薦人</h2>';
$customer = affwp_get_customer($user->user_email);
@ucheng
ucheng / build_custom_shipping_address.php
Created April 22, 2021 14:28
build custom shipping address
<?php
// $raw_address = Array (
// [first_name] => YU CHENG
// [last_name] => WANG
// [company] =>
// [address_1] => 新北路
// [address_2] =>
// [city] => 板橋區
// [state] => NEW TAIPEI CITY
// [postcode] => 100
@ucheng
ucheng / git-create-a-repos
Last active February 7, 2021 13:13
Push fresh code to a GitHub repository
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/ucheng/your-repos.git
git push -u origin master
@ucheng
ucheng / remove_marketing_hub
Created June 7, 2020 06:08
Remove Marketing Hub in WooCommerce Admin
<?php
add_filter( 'woocommerce_marketing_menu_items', '__return_empty_array' );