Skip to content

Instantly share code, notes, and snippets.

View yllus's full-sized avatar

Sully Syed yllus

View GitHub Profile
@yllus
yllus / gist:0c944d1803f7c25cdfde
Created August 7, 2015 00:39
Macleans.ca debate in other media
Huffington Post Canada bingo Facebook post:
<div id="fb-root"></div><script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3"; fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class="fb-post" data-href="https://www.facebook.com/HuffPostCanada/posts/978107295542783:0" data-width="500"><div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/HuffPostCanada/posts/978107295542783:0"><p>Play along at home if you&#039;re watching tonight&#039;s Maclean&#039;s debate</p>Posted by <a href="https://www.facebook.com/HuffPostCanada">The Huffington Post Canada</a> on&nbsp;<a href="https://www.facebook.com/HuffPostCanada/posts/978107295542783:0">Thursday, August 6, 2015</a></blockquote></div></div>
Vox.com's explainer on the 2015 Canadian election:
http://www.vox.com/2015/8/6/9109669/2015-canada-fed
@yllus
yllus / Apple's iMac scrolling effect.markdown
Created July 6, 2015 18:24
Apple's iMac scrolling effect
<?php
define('FOLDER_CLEANUP', '/Users/rdmdev/Downloads/temp');
$files = scandir(FOLDER_CLEANUP);
foreach ($files as $file) {
$wanted = explode("_", $file);
if (strpos($files[array_search($file, $files) + 6], $wanted[1]))
{
//unlink(FOLDER_CLEANUP . "/" . $file);
echo "Deleting: " . FOLDER_CLEANUP . "/" . $file . "\n";
<?php if ( is_home() ): ?>
<div id="ad_sliver" class="sliver">
<script> adUtility.insertAd("ad_sliver", { type: adUtility._AD_SLIVER }); </script>
</div>
<?php else: ?>
<div id="ad_sliver" class="sliver">
<script>if ( window.snBreakpointWatcher.breakPoint() >= 1024 ) { adUtility.insertAd("ad_sliver", { type: adUtility._AD_SLIVER }); }</script>
</div>
<?php endif; ?>
@yllus
yllus / gist:f933f83303f689a13d90
Last active August 29, 2015 14:19
Only display the loyalty mobile warning once every 2 days (setting a cookie)
<!-- Loyalty mobile warning -->
<script>
$(document).ready(function() {
var isMobile = window.matchMedia("only screen and (max-width: 760px)");
var isCookieSet = getCookie('loyalty_mobile_warning');
if (isMobile.matches && isCookieSet === false) {
setCookie('loyalty_mobile_warning', '1', 2);
alert("The 680 NEWS Insider Club is optimized to work best on a computer or tablet. Please log in using one of those devices. If you are on a smartphone, rotate it to landscape mode.")
}
});
@yllus
yllus / gist:ebb21174e273efa4083a
Created January 19, 2015 19:30
Display a custom page template/view if a "rssa" GET parameter is placed in a post's URL
// If the query parameter is passed, use a different article template than the usual
// (this one has no header/footer).
function rssa_content_mobile_view() {
if ( isset( $_GET['rssa'] ) && is_singular() ) {
require '/some-path/article/view.article.mobile-view.php';
exit;
}
}
add_action( 'template_redirect', 'rssa_content_mobile_view' );
@yllus
yllus / gist:af420d24cbeab71aa4b7
Last active August 29, 2015 14:12
Adding an AJAX function/URL to WordPress (a three-step process)
// Put this function in your theme's functions.php (or even better, in an ajax.php file in the
// theme that is require'd in):
/* The function ajax_read_more() will be called when the following URL is requested
* from WordPress:
*
* http://www.yoursite.com/wp-admin/admin-ajax.php?action=read_more&limit=5
*/
function ajax_read_more() {
// Take in a few input parameters from $_GET or $_POST (depending on how you're passing the values) about
@yllus
yllus / gist:9e179c589ff2179ab4c3
Created December 10, 2014 22:28
Permalink structure changing code
// Make the permalink structure for the Video post type match that of regular /YYYY/MM/DD/slug/ posts.
function bc_post_type_link( $url, $post ) {
if ( 'bc-video' == get_post_type( $post ) ) {
$url = home_url() . '/%year%/%monthnum%/%day%/%postname%/';
$post_date = strtotime( $post->post_date );
$url = str_replace(
array(
'%year%',

SQL String Escaping

Here's an example of using grep to find all instances of the word "insert" (ignoring case):

ssyed@server:~$ cd /var/www/ 
ssyed@server:/var/www$ grep -Ri insert . 
... a whole bunch of results ...
./folder_button/jsinclude_server_com_ccare.php:$query = "INSERT INTO log VALUES(NULL, '$ip', '$hostname', '". $_SERVER['HTTP_REFERER'] ."', '". $data['queue_id'] ."', '". $data['status_id'] ."','". $_SERVER['HTTP_USER_AGENT'] ."');";	
... a whole bunch more results ...
// Get term ID for the video category.
$video_category_term = get_term_by('slug', 'video-landing-page', 'video-categories');
$video_category_term_id = $video_category_term->term_id;
// Find the bc-video-strip post associated to that video category.
$strip_query = new WP_Query(
array(
'post_type' => 'bc-video-strip',
'tax_query' => array(
array(