Skip to content

Instantly share code, notes, and snippets.

View seanmcn's full-sized avatar
🐝

Seán McNamara seanmcn

🐝
View GitHub Profile
@seanmcn
seanmcn / MySQL Data to CSV.php
Last active August 29, 2015 14:10
Converts mySQL data to CSV data
<?php
/* Database Info */
$server = "localhost";
$username = "username";
$password = "password";
$databaseName = "databaseName";
/* Table we want to export */
$tableName = "tableName";
/* Optional WHERE Statement */
//$whereStatement = "WHERE field = value";
@seanmcn
seanmcn / Controller_addProject.php
Last active August 29, 2015 14:10
Using Codeigniter Form + Validation Libraries
/*
* Controller for Projects
*/
public function addProject() {
$this->load->helper('form');
$this->load->library('form_validation');
$config = array(
array(
'field' => 'client',
'label' => 'Client Name',
@seanmcn
seanmcn / Model_addProject.php
Last active August 29, 2015 14:10
Using Codeigniter's ActiveRecord
/*
* Model for Projects
*/
function addProject($client, $projectName, $price, $deadline, $notes) {
$project = array(
"client_id" => $client,
"user_id" => $this->session->userdata('user_id'),
"name" => $projectName,
"price" => $price,
"deadline" => $deadline,
@seanmcn
seanmcn / contestantPercentage.php
Last active August 29, 2015 14:10
Returning a contestants percentage of votes
<?php
/* Gets the count of all votes for a specific poll */
public function totalVoteCount($pollId) {
$this->db->select("*");
$this->db->where("poll_id", $pollId);
$count = $this->db->count_all_results('votes');
return $count;
}
/* Returns the percentage of votes a contestant has in a specific poll */
public function getContestantPercentage($pollId, $contestantId) {
<?php
public function uploadImage() {
$this->load->library('upload');
$imageFolder = 'assets/images/features';
if (!file_exists($imageFolder)) {
mkdir($imageFolder, DIR_WRITE_MODE, true);
}
$this->upload_config = array(
'upload_path' => $imageFolder,
'allowed_types' => '*',
@seanmcn
seanmcn / eduSessions.php
Last active August 29, 2015 14:10
Edusessions wordpress pluigin
<?php
/*
Plugin Name: Education Session Plugin
Plugin URI: http://coder.ie/
Description: Custom Plugin for IFAN
Version: 1.0
Author: Sean McNamara
Author URI: http://seanmcn.com/
*/
register_activation_hook(__FILE__,'edusession_plugin_install');
@seanmcn
seanmcn / timeDifference.php
Created December 3, 2014 05:35
Some legacy code from OTS
<?php
/*
* Author: Sean McNamara
* Some legacy code from OTS
*/
$tr_date = strtotime($options['tr_date']);
$fest_date = strtotime($options['fest_date']);
$games_date = strtotime($options['games_date']);
$now = strtotime("now");
@seanmcn
seanmcn / customiser.js
Created December 3, 2014 05:40
Product Customiser for
/*
* Product Customiser for Celtic Commemorations
* @Documentation: http://lmgtfy.com/?q=jquery+documentationl=1
*/
var popupStatus = 0; //0 means disabled; 1 means enabled;
var page = 0;
var text = 0;
var textAreaStatus = 0;
var currentTextAreas = 0;
var maxTextAreas = 3;

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

(function(global) {
var silpUrl = '//s3-eu-west-1.amazonaws.com/silp.shootitlive.com/js/silp.min.js';
// Globals
if(!global.Silp) { global.Silp = {}; };
var Silp = global.Silp;
// To keep track of which embeds we have already processed
if(!Silp.foundEls) Silp.foundEls = [];