Skip to content

Instantly share code, notes, and snippets.

View samjco's full-sized avatar

Sam C. samjco

View GitHub Profile
@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@ziadoz
ziadoz / scrape.php
Created August 13, 2012 21:54
Scraping Google using PHP and Goutte:
<?php
/**
* Todo: Send a random user agent string and sleep a random amount between requests.
*/
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Extract and sanatize input:
$domain = filter_input(INPUT_POST, 'domain', FILTER_SANITIZE_URL);
$terms = filter_input(INPUT_POST, 'terms', FILTER_SANITIZE_STRING);
// Setup Goutte (which also includes Guzzle):
@dtbaker
dtbaker / dtbaker.wiki-mode.php
Created April 4, 2013 15:41
hacking WordPress to support nested custom post types.
<?php
// get_page_by_path called in query.php 2119 !
//remove_action('template_redirect', 'redirect_canonical');
// Turns all textareas into medium-editors
// requires:
// - Medium-Editor
// - jQuery (can be easily rewritten without)
// - find_with_mutations: https://gist.github.com/hampei/7620643
// - sync_node_html_to_form_field: https://gist.github.com/hampei/7620825
window.textareas_to_medium_editor = function() {
find_with_mutations('form', 'textarea', function(el) {
el.style.display = 'none'; // hide the textarea
editor = $('<div />'); // create editor element
@stormwarning
stormwarning / __wordpress.php
Last active February 29, 2024 03:03
WordPress PROTIPs
/**
* A selection of handy code snippets, plugins, and best practices for WordPress development.
*
*/
@JProffitt71
JProffitt71 / s3cmdclearfiles
Created February 17, 2014 04:29
Uses s3cmd to manually remove files older than specified date (##d|m|y) in a specified bucket
#!/bin/bash
# Usage: ./s3cmdclearfiles "bucketname" "30d"
s3cmd ls s3://$1 | grep " DIR " -v | while read -r line;
do
createDate=`echo $line|awk {'print $1" "$2'}`
createDate=`date -j -f "%Y-%m-%d %H:%M" "$createDate" +%s`
olderThan=`date -j -v-$2 +%s`
if [[ $createDate -lt $olderThan ]]
@scottopolis
scottopolis / gist:07c555b9dd0581497f0b
Last active March 16, 2019 20:51
Styling for Display Posts Shortcode
/* Author: Scott Bolinger
* Author URI: http://apppresser.com
*
* Styling for Display Posts Shortcode plugin for use with the AppTheme. Add this code to a child theme style.css file.
* Plugin information: http://www.billerickson.net/shortcode-to-display-posts/
*
*/
ul.display-posts-listing {
list-style-type: none;
@danielpataki
danielpataki / author-removal.php
Last active December 18, 2018 23:10
Modifying Twenty Fifteen
<?php
// Author bio.
if ( is_single() && get_the_author_meta( 'description' ) ) :
get_template_part( 'author-bio' );
endif;
?>
@kcpt-steven-kohlmeyer
kcpt-steven-kohlmeyer / redirect-subscriber.php
Created February 9, 2015 21:25
Wordpress: Redirect subscribers from accessing admin.
<?php
global $current_user; // Use global
get_currentuserinfo(); // Make sure global is set, if not set it.
if ( user_can( $current_user, "subscriber" ) ) {
// Disable admin bar for subscribers
show_admin_bar(false);
@kcpt-steven-kohlmeyer
kcpt-steven-kohlmeyer / query-hooks.php
Created February 9, 2015 22:51
Virtual URLs to modify query
<?php
function add_custom_query_vars($vars) {
$vars[] = "past_events";
return $vars;
}
// hook add_query_vars function into query_vars
add_filter('query_vars', 'add_custom_query_vars');