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 / 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>
//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
@melvinstanly
melvinstanly / html-in-psudeo-content.txt
Created April 22, 2021 13:35
Using html in :before / :after psuedo content
The reason for not allowing html inside the content parameter is the fact that CSS is designed to work in a
single pass-through of the page. If there were html, that would need to be styled, which means the css would
need to come back and process itself all over again to style that HTML after it was done styling everything else.
This extra functionality would rarely be used by anyone but would still come with a speed cost to everyone
@melvinstanly
melvinstanly / wp-query-reset.txt
Created August 19, 2020 05:48
WordPress post reset query
<?php
//https://wordpress.stackexchange.com/questions/144343/wp-reset-postdata-or-wp-reset-query-after-a-custom-loop
The difference between the two is that
-> wp_reset_query() - ensure that the main query has been reset to the original main query
-> wp_reset_postdata() - ensures that the global $post has been restored to the current post in the main query.
wp_reset_query() calls wp_reset_postdata(). The only difference between the two then is this line: