Skip to content

Instantly share code, notes, and snippets.

View pejantantangguh's full-sized avatar
🎯

Herman Ng pejantantangguh

🎯
View GitHub Profile
name = input("Your name please?")
age = int(input("Please enter your age?")) + 100
print("Your name is "+name+ " and in 100 years you will be "+str(age))
num = int(input("Please enter first number"))
check = int(input("Please enter second number"))
result = check/num
if(result % 4 == 0):
print ( str(result)+ "\nYour number is a number multiple of 4")
elif(result % 2 == 1):
print ( str(result)+ "\nYour result is an odd number")
else:
print ( str(result)+ "\nYour result is an even number")
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
num = int(input("Please enter number"))
x = []
for element in a:
if element < num :
x.append(element)
print (x)
num = int(input("Please put a number to divide"))
divisorList = []
listRange = list(range(1,num+1))
for number in listRange:
if num % number == 0:
divisorList.append(number)
print (divisorList)
@pejantantangguh
pejantantangguh / 05. List Overlap
Created November 15, 2017 04:51
To generate random number and put it in list, cross check the value of each list and only print number that are exist in list[a] and list[b]
import random
a = random.sample(range(50),20) #Sample won't have any duplicate value
b = random.sample(range(50),20)
#See number that are generated by a
print (a)
#See number that are generated by b
print (b)
c = []
@pejantantangguh
pejantantangguh / 06. String List.py
Created November 15, 2017 05:27
If statement if input words is palindrom or not
# Strings are list
words = str(input("Type in words that you think is palindrome : "))
palindrome = words[::-1]
print (words+" "+palindrome)
if words == palindrome:
print("Your words is palindrome")
else :
print("Unfortunately this is not palindrome")
import random
number = random.sample(range(50),20)
evenNumber = []
print (number
)
for even in number:
if even % 2 == 0:
evenNumber.append(even)
@pejantantangguh
pejantantangguh / delete-all-woocommerce-products.php
Last active December 13, 2021 15:16 — forked from mikaelz/delete-all-woocommerce-products.php
Remove all WooCommerce products from database via SQL
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%')");
$wpdb->query("DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'");
$wpdb->query("DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)");
$wpdb->query("DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_posts WHERE post_type IN ('product','product_variation')");
@pejantantangguh
pejantantangguh / Bacs default to pending Payment.php
Last active November 6, 2020 14:44
Plugins to overide Bank Transfer from on Hold to Pending Payment WooCommerce
<?php
/*
Plugin Name: bacs-to-pending-payment
Description: Change bank transfer default order status from on Hold to pending payment
Version: 1.0.0
Contributors: Suherman Ng
Author: Suherman NG
Author URI:
License: GPLv2 or later
Text Domain: CAF website
@pejantantangguh
pejantantangguh / singleproductview.php
Created July 25, 2018 20:56
WooCommerce - Show products from current product category (when viewing a single product)
<?php
if ( is_singular('product') ) {
global $post;
// get categories
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $cats_array[] = $term->term_id;
$query_args = array( 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',