Skip to content

Instantly share code, notes, and snippets.

View rxnlabs's full-sized avatar

De'Yonte W. rxnlabs

View GitHub Profile
@rxnlabs
rxnlabs / ps-import-mysql-database
Created June 18, 2014 14:24
PowerShell - import mysql file using mysql-cli using PowerShell
& cmd.exe /c "mysql -u root -p -h localhost < myql_database.sql"
@rxnlabs
rxnlabs / htaccess-site-root-subfolder
Created June 18, 2014 14:18
htaccess - change site root to subfolder. Useful if you're on host (using cPanel) and you want to move your main site to a folder.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/mydomain.com/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mydomain.com/public/index.php
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC]
RewriteRule ^(/)?$ mydomain.com/public/index.php [L]
RewriteEngine on
@rxnlabs
rxnlabs / js-youtube-ga-event-tracking-code-html.html
Last active August 29, 2015 14:02
Javascript - Add Google Analytics event tracking to youtube player
<script src="/link-to-youtube-ga-event-tracking-javascript-code.js"></script>
<!--IFRAME CODE FOR YOUTUBE PLAYLIST PLAYER-->
<div id="oil_gas_training">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
<script type="text/javascript">
var tag=document.createElement("script");
tag.src="//www.youtube.com/iframe_api";
var firstScriptTag=document.getElementsByTagName("script")[0];
@rxnlabs
rxnlabs / php-array-get-all-possibilities-associative.php
Last active July 22, 2019 10:38
PHP - Generate all possible combinations from multidimensional array
// http://www.devnetwork.net/viewtopic.php?f=1&t=133156
function array_cartesian_utm($arrays){
//returned array...
$cartesic = array();
//calculate expected size of cartesian array...
$size=(sizeof($arrays)>0)?1:0;
foreach($arrays as $array){
$size= $size*sizeof($array);
@rxnlabs
rxnlabs / php-wp-list-hooks.php
Last active June 15, 2023 17:07
WordPress - list all action hooks registered
<?php
// http://www.wprecipes.com/list-all-hooked-wordpress-functions
function list_hooked_functions($tag=false){
global $wp_filter;
if ($tag) {
$hook[$tag]=$wp_filter[$tag];
if (!is_array($hook[$tag])) {
trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
return;
}
@rxnlabs
rxnlabs / php-wp-enqueue-conditional-scriptload-before-dependent.php
Last active January 21, 2025 08:44
WordPress - enqueue javascript data based on WordPress conditions and other scripts. Load scripts tags before and after dependent script loads
<?php
function load_scripts(){
global $wp_scripts;
wp_register_script( 'theme-scripts', get_bloginfo('template_url').'/js/scripts.js', array('jquery'), '1.0', true );
//if we're on the woocommerce checkout page
if( is_checkout() ){
$wp_scripts->add_data('theme-scripts','data','<!--START SCRIPT STRING-->
// script to load before name-of-enqueued-script loads
@rxnlabs
rxnlabs / htaccess-cache-static-files
Created April 30, 2014 18:37
htaccess - cache static files for one month and add gzip for performance
#add caching headers for static files. tell browser to cache for one month
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
ExpiresActive On
ExpiresDefault A2592000
</FilesMatch>
#add gzip to site
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/plain text/html application/x-httpd-php-source
@rxnlabs
rxnlabs / php-wp-add-upload-mime.php
Last active August 29, 2015 14:00
WordPress: upload new file types media manager
<?php
#add epub,mobi file upload ability
add_filter('upload_mimes', 'addUploadMimes');
function addUploadMimes($mimes) {
$mimes = array_merge($mimes, array(
'epub|mobi' => 'application/octet-stream'
));
return $mimes;
}
@rxnlabs
rxnlabs / php-wp-woocommerce-paypal-redirect.php
Last active August 29, 2015 14:00
WooCommerce/WordPress: redirect to checkout page after successful PayPal purchase
<?php
#encode the return URL for PayPal so user's are redirected back to site after completing payment
add_filter( 'woocommerce_paypal_args','woocommerce_paypal_args_repair');
function woocommerce_paypal_args_repair( $paypal_args ) {
global $woocommerce;
if (!array_key_exists(‘cbt’,$paypal_args))
$paypal_args['cbt'] = $woocommerce->cart->get_checkout_url();
return $paypal_args;
}
@rxnlabs
rxnlabs / htaccess-non-www-to-www-subdomains
Created April 14, 2014 12:11
htaccess - redirect non-www to www and stop subdomains from redirecting to folder
#redirect non-www to www and stop subdomains from redirecting to folder
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]