Skip to content

Instantly share code, notes, and snippets.

View rxnlabs's full-sized avatar

De'Yonte W. rxnlabs

View GitHub Profile
@rxnlabs
rxnlabs / js-todays-date.js
Last active August 29, 2015 13:56
Javascript - Show Today's Date
//http://stackoverflow.com/questions/1531093/how-to-get-current-date-in-javascript
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} today = mm+'/'+dd+'/'+yyyy;
document.write(today);
@rxnlabs
rxnlabs / js-optimizely-luckyorange.js
Last active August 29, 2015 13:58
Grab the Optimizely experiment information uisng javasacript and tag experiments in LuckyOrange
var experimentID = window['optimizely'].data.state.activeExperiments[0];
var variationIndex = window['optimizely'].data.state.variationMap[experimentID];
var variationName = window['optimizely'].data.state.variationNamesMap[experimentID];
var variationID = window['optimizely'].data.state.variationIdsMap[experimentID];
var experiment_name = window['optimizely'].data.experiments[experimentID].name;
if (optimizely_experiment_id === "optimizely_experiment_id_i_wanna_track"){
var _loq = window._loq || []; // ensure queue available
_loq.push(["tag_recording", window['optimizely'].data.experiments[experimentID].name +"-"+window['optimizely'].data.state.variationIdsMap[experimentID]]); // this will tag, won't star, and will append the tag
@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]
@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 / 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 / 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 / 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 / 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 / php-curl-get-headers.php
Last active August 29, 2015 14:04
PHP - get headers from cURL request
<?php
function get_headers_curl($response){
$headers = array();
$header_text = substr($response, 0, strpos($response, "\r\n\r\n"));
foreach (explode("\r\n", $header_text) as $i => $line){
if ($i === 0)
$headers['http_code'] = $line;
@rxnlabs
rxnlabs / sublime-text-example-project-file-1920.json
Last active August 29, 2015 14:04
Sublime Text - SublimeText 3 example project file. One I personally use
{
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
],
"settings":
{