Skip to content

Instantly share code, notes, and snippets.

View chrisblakley's full-sized avatar
⚔️
Take that, entropy!

Chris Blakley chrisblakley

⚔️
Take that, entropy!
View GitHub Profile
@chrisblakley
chrisblakley / gearside_sickness_probability.php
Last active August 29, 2015 14:16
Visualize the probability of you being sick in Google Calendar by generating this .ics file.
<?php
// http://gearside.com/calendars/sick.php
$debug = 0; //Enable forced debug mode here
if ( $debug == 0 && !array_key_exists('debug', $_GET) ) {
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=sickness_probability.ics');
}
@chrisblakley
chrisblakley / gearside_url_components.php
Last active August 29, 2015 14:15
Easily pull the segment of a URL without constantly re-writing code. Documentation here: http://gearside.com/php-function-easily-return-url-components/
//Get the full URL. Not intended for secure use ($_SERVER var can be manipulated by client/server).
function gearside_requested_url($host="HTTP_HOST") { //Can use "SERVER_NAME" as an alternative to "HTTP_HOST".
$protocol = ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443 ) ? 'https' : 'http';
$full_url = $protocol . '://' . $_SERVER["$host"] . $_SERVER["REQUEST_URI"];
return $full_url;
}
//Separate a URL into it's components.
//See http://gearside.com/php-function-easily-return-url-components/ for documentation
@chrisblakley
chrisblakley / server-side-ga-events.php
Last active August 16, 2022 19:22
PHP functions to send data to Google Analytics
//Parse the GA Cookie
function gaParseCookie() {
if (isset($_COOKIE['_ga'])) {
list($version, $domainDepth, $cid1, $cid2) = explode('.', $_COOKIE["_ga"], 4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1 . '.' . $cid2);
$cid = $contents['cid'];
} else {
$cid = gaGenerateUUID();
}
return $cid;
@chrisblakley
chrisblakley / example_json.js
Last active April 18, 2016 02:03
Cache Twitter feeds using PHP and JSON
//This can go in main.js or where ever.
jQuery.getJSON('/includes/twitter_cache.php', function(data) { //If using Nebula, the path will be: nebula.site.directory.stylesheet.uri + '/includes/twitter_cache.php'
jQuery.each(data, function(i) {
console.log(data[i]);
});
//Example full implementation:
jQuery('#tweetlink').attr('href', 'https://twitter.com/' + data[0].user.screen_name).text('@' + data[0].user.screen_name);
var tweetTime = new Date(Date.parse(data[0].created_at));
jQuery('#tweet').html(tweetLinks(data[0].text)).append(" <span class='twitter-posted-on'><i class='fa fa-clock-o'></i> " + timeAgo(tweetTime) + "</span>");
@chrisblakley
chrisblakley / ooyala-bootstrap-modal.html
Last active August 29, 2015 14:12
Ooyala Player using Gumby and Bootstrap Modals. With Gumby, you're going to be fighting some default styles, so you'll want to use !important tags on the .video class for padding-bottom and height.
<style>
/* Responsive Ooyala Player */
.ooyalacon {position: relative; width: 100%; padding: 56.25% 0 0 0;} /* 56.25% = 16:9 ratio */
.ooyalacon .innerWrapper {position: absolute !important; top: 0; left: 0; width: 100%; height: 100%;}
.ooyalacon .video {position: absolute; top: 0; padding-bottom: 0 !important; height: 100% !important;}
</style>
<script src='http://player.ooyala.com/v3/MzZiMzc1ZDUzZGVlYmMxNzA3Y2MzNjBk'></script> <!-- Branding ID here -->
<script>
@chrisblakley
chrisblakley / .htaccess
Last active August 29, 2015 14:12
Spambot prevention snippets using .htaccess and PHP
SetEnvIfNoCase Referer semalt.com spambot=yes
SetEnvIfNoCase Referer econom.com spambot=yes
SetEnvIfNoCase Referer buttons-for-website.com spambot=yes
SetEnvIfNoCase Referer ilovevitaly.com spambot=yes
SetEnvIfNoCase Referer ilovevitaly.ru spambot=yes
SetEnvIfNoCase Referer darodar.com spambot=yes
SetEnvIfNoCase Referer 7makemoneyonline.com spambot=yes
SetEnvIfNoCase Referer myftpupload.com spambot=yes
SetEnvIfNoCase Referer priceg.com spambot=yes
Order allow,deny
@chrisblakley
chrisblakley / adblock_detect.html
Last active August 29, 2015 14:10
Detect if users are blocking your ads using jQuery
<style>
.hidden {display: none;} /* Just for reference. This should be in your stylesheet! */
</style>
<div class="extra_resources">
<!-- [AD_CODE_HERE] -->
</div>
<a class="blockdetection hidden" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VALMBPW4PWH8S" target="_blank"><img src="donate_image.png" alt="Donate via Paypal" /></a>
@chrisblakley
chrisblakley / shortcode1.php
Last active August 29, 2015 14:09
Example shortcode function
add_shortcode('yolo', 'gearside_yolo_shortcode');
function gearside_yolo_shortcode(){
//Code will go here...
}
@chrisblakley
chrisblakley / pagespeed_detect.php
Last active February 11, 2016 23:45
Google Page Speed tracking
function gaParseCookie() {
if (isset($_COOKIE['_ga'])) {
list($version,$domainDepth, $cid1, $cid2) = explode('.', $_COOKIE["_ga"], 4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1 . '.' . $cid2);
$cid = $contents['cid'];
} else {
$cid = gaGenerateUUID();
}
return $cid;
}
<noscript>
<iframe class="hidden" src="includes/no-js.php?h=HOME_URL&amp;p=PAGE_URI&amp;t=PAGE_TITLE" width="0" height="0" style="display:none;position:absolute;"></iframe>
</noscript>
<!-- Notes: Use server-side scripting to fill in the HOME_URL, CURRENT_PAGE_URI, and PAGE_TITLE. Be sure to encode the page title to avoid spaces! If you are using Wordpress, you can use the following snippet: -->
<noscript>
<iframe class="hidden" src="<?php echo get_template_directory_uri(); ?>/includes/no-js.php?h=<?php echo home_url('/'); ?>&amp;p=<?php echo get_page_uri(); ?>&amp;t=<?php urlencode(get_the_title()); ?>" width="0" height="0" style="display:none;position:absolute;"></iframe>
</noscript>