Skip to content

Instantly share code, notes, and snippets.

View mariomelchor's full-sized avatar

Mario Melchor | Senior Web Developer mariomelchor

View GitHub Profile
@mikowl
mikowl / oneliners.js
Last active March 28, 2024 20:52
👑 Awesome one-liners you might find useful while coding.
// Inspired by https://twitter.com/coderitual/status/1112297299307384833 and https://tapajyoti-bose.medium.com/7-killer-one-liners-in-javascript-33db6798f5bf
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// or
const sleep = util.promisify(setTimeout);
@pavankjadda
pavankjadda / How to fix gitignore not working issue.md
Last active June 20, 2024 15:28
How to fix "gitignore not working" issue

FYI: Created blog post with more details

How to fix ".gitignore not working" issue?

Sometimes git does not exclude files/folders added .gitignore especially if you had commited them before. Here is how to fix it. I am ignoring node_modules from Angular project as an example

  1. Update .gitignore with the folder/file name you want to ignore. You can use anyone of the formats mentioned below (prefer format1)
### Format1  ###
node_modules/
@cliffordp
cliffordp / functions.php
Last active April 10, 2022 17:06
Event Tickets & Plus: Attach a file from Media Library to all ticket emails.
<?php
/**
* Event Tickets & Plus: Attach a file from Media Library to all ticket emails.
*
* Does not work for emails for declined RSVPs or for moved tickets, but it
* could if you want it to; just add those additional hooks.
*
* @link https://gist.github.com/cliffordp/fc7f1687b26c7292672ead9f26c4d568
* @link https://theeventscalendar.com/support/forums/topic/pdf-attachment-file-to-ticket-email/
@raewrites
raewrites / first-post-image
Created November 9, 2017 07:10
Use First Post Image
//function to call first uploaded image in functions file
function main_image() {
$files = get_children('post_parent='.get_the_ID().'&amp;post_type=attachment
&amp;post_mime_type=image&amp;order=desc');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', true);
$imagepieces = explode('"', $image);
@fblanton
fblanton / Env Variables for NodeJS Apps.md
Last active February 28, 2024 19:31
Hiding NodeJS Secret Keys in .bash_profile

Hiding Secret Keys for your NodeJS app with Bash

GitHub is a great place to pubslish your code; and it is often required to post code there when learning to code. If you are writing a NodeJS app and being required to publish code to GitHub you should be careful of pushing any code that contains secret API keys. These keys could be scraped and used to write apps with your keys.

tl;dr

Don't have time to read all the stuff below. I get it. Add:

export KEY=value
export ANOTHER_KEY=anothervalue
@claudiosanches
claudiosanches / functions.php
Last active June 4, 2022 07:52
WooCommerce - Add Order Again button to My Orders actions
<?php
/**
* Add order again button in my orders actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
@ericakfranz
ericakfranz / envira-hide-from-search-results.php
Created May 8, 2015 00:17
Exclude Envira Galleries from search results.
add_filter( 'envira_gallery_post_type_args', 'filter_envira_search' );
function filter_envira_search( $args ) {
$args['exclude_from_search'] = true;
return $args;
}
@yoren
yoren / functions.php
Last active February 17, 2019 20:03
Return the right previous_post_link / next_post_link when change posts order
<?php
function my_previous_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
add_filter( 'get_previous_post_where', 'my_previous_post_where' );
@paulallies
paulallies / gist:0052fab554b14bbfa3ef
Last active November 12, 2023 23:00
Remove node_modules from git repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin <branch-name>