Skip to content

Instantly share code, notes, and snippets.

View melvinstanly's full-sized avatar
🌪️
Fast and Furious

Melvin Stanly melvinstanly

🌪️
Fast and Furious
View GitHub Profile
@melvinstanly
melvinstanly / dir-listings.txt
Created August 16, 2023 13:01
Command to list all files in a folder as well as sub-folders in windows
1. Open cmd
2. Go to the directory for which you need the listings
3. Run tree /a /f > output.txt
A file will be created in the directory with the name output.txt
@melvinstanly
melvinstanly / woo-checkout-order-review.php
Created September 12, 2018 06:52
Add custom field or html to review order table in WooCommerce Checkout
<?php
/* To add custom field in order review table in checkout page, you will have to use some of the hooks listed below.
do_action( 'woocommerce_review_order_before_cart_contents' );
do_action( 'woocommerce_review_order_after_cart_contents' );
do_action( 'woocommerce_review_order_before_shipping' );
do_action( 'woocommerce_review_order_after_shipping' );
do_action( 'woocommerce_review_order_before_order_total' );
do_action( 'woocommerce_review_order_after_order_total' );
@melvinstanly
melvinstanly / gist:0056d780eaedb0b3d4a7905f8a1d8f94
Created October 4, 2021 09:24
Remove a part of a string, but only when it is at the end of the string
<?php
$cleaned = preg_replace('/'. preg_quote($remove, '/') . '$/', '', $cleaned);
//$remove -> The string to be removed which is input by the user
// Or you can use a regular expression as shown below
$cleaned = preg_replace('/\[\]$/', '', $cleaned); // => Removes square brackets at the end of the string.
@melvinstanly
melvinstanly / css-specificity.txt
Last active September 30, 2021 10:06
CSS Specificity
CSS rules have weight, and you should leverage those rules to correctly cascade styles.
element = 1 pt
class = 10 pt
id = 100 pt
inline = 1000 pt
An ID has a relatively high specificity of 100. A class has a specificity of 10.
#idname.classname - Now this selector has a specificity of 110.
@melvinstanly
melvinstanly / hide-wp-sidebar.php
Created July 29, 2021 08:36
Hide WordPress admin sidebar in wordpress pages
<?php
// Fold / unfold the WordPress admin sidebar in certain pages. Set `mfold` to `f`(fold) to close it and `o`(open) to open the sidebar.
add_action('admin_init', 'collapse_admin_sidebar');
function collapse_admin_sidebar(){
$page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : false;
if( $page === "required_page_slug" ){
if( get_user_setting('mfold') != 'f' ){
set_user_setting('mfold', 'f');
}
@melvinstanly
melvinstanly / npm-troubleshooting.txt
Created July 28, 2021 05:39
Troubleshoot issues in npm package installing.
If you see the command screen get stuck for minutes after running "npm install" then check if package-lock.json is still in the folder.
Remove the package-lock.json file before running "npm install".
If issue still persists, please follow the guide below.
http://www.jonahnisenson.com/running-npm-install-hangs-and-hangs-and-hangs/
@melvinstanly
melvinstanly / target-type.js
Created July 26, 2021 14:52
Check the event target is a particular html element
<script>
if(event.target.tagName.toLowerCase() === 'div'){
}
</script>
@melvinstanly
melvinstanly / flex.txt
Last active July 26, 2021 10:57
CSS Flex issues
If wrapper has flex applied and children is in the following structure
col1 col2 col3
And you want to break col3 to a new line, then apply flex-wrap:wrap to the wrapper and flex-basis:100% to the child who
should igonre the parent flex style (Here col3).
If still the childs are arranged as rows, then add width to other childs except which should ignore the flex style ( Here Col1 and Col 2)
//Choose first two and last two childs
p:nth-child(-n + 2) {
color: orange;
}
p:nth-last-child(-n + 2) {
color: orange;
}
@melvinstanly
melvinstanly / json-stringfy.js
Created May 3, 2021 07:39
JSON.stringify returns []
function json_encode(){
var content = [];
content.field1 = { width: "100px", height: "400px", label : "Width"};
content.field2 = { width: "200px", height: "500px", label : "Height"};
console.log(JSON.stringify(content));
}
// The above function return [] because the key used here is a string.
//The array key should be integer for JSON.stringify to return proper value