Skip to content

Instantly share code, notes, and snippets.

View 2aces's full-sized avatar

2ACES 2aces

View GitHub Profile
@cjkoepke
cjkoepke / logging_errors.js
Created August 10, 2017 18:20
Debugging tips and tricks.
// Great for getting values, outputting context strings, and so on.
console.log(variable)
// Same as console.log(), but prints in yellow as a warning. Useful to show a non-breaking error in a dev env.
console.warn('It is a good idea to use .map instead of a for-loop.')
// Same as console.log(), but prints in red as an error. Useful to show a breaking error in a dev env.
console.error(`The value must be an integer. You provided a ${typeof variable}.`)
// Group console data together for better viewing. Nice to group console logs together.
@jawinn
jawinn / primary_category.php
Last active December 8, 2022 21:42
Display Primary Category (Yoast's WordPress SEO)
<?php
/**
* Get the Yoast primary category from its post meta value, and displays it, with HTML markup.
* If there is no primary category set, it displays the first assigned category.
*
* @param boolean $useCatLink Whether to link the category, if it exists
* @return void
*/
function yourtheme_display_yoast_primary_category( $useCatLink = true ) {
@salcode
salcode / .gitignore
Last active April 3, 2024 18:38
Please see https://salferrarello.com/wordpress-gitignore/ for the canonical version of this WordPress .gitignore file. Note: I do not receive notifications for comments here (because GitHub does not send notifications on Gists)
# -----------------------------------------------------------------
# .gitignore for WordPress @salcode
# ver 20180808
#
# From the root of your project run
# curl -O https://gist.githubusercontent.com/salcode/b515f520d3f8207ecd04/raw/.gitignore
# to download this file
#
# By default all files are ignored. You'll need to whitelist
# any mu-plugins, plugins, or themes you want to include in the repo.
@vitorbritto
vitorbritto / rm_mysql.md
Last active April 18, 2024 19:00
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

    brew remove mysql
    
@jjmu15
jjmu15 / in_viewport.js
Created January 27, 2014 10:19
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"