Skip to content

Instantly share code, notes, and snippets.

@dreadjr
dreadjr / ShortenNumbers.js
Created March 14, 2016 18:02 — forked from etaubman/ShortenNumbers.js
Shorten Numbers Using Javascript
function shortenNumber(n, d) {
if (n < 1) return "<1";
var k = n = Math.floor(n);
if (n < 1000) return (n.toString().split("."))[0];
if (d !== 0) d = d || 1;
function shorten(a, b, c) {
var d = a.toString().split(".");
if (!d[1] || b === 0) {
return d[0] + c
@dreadjr
dreadjr / bytesToSize.js
Created February 8, 2016 18:00 — forked from lanqy/bytesToSize.js
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@dreadjr
dreadjr / facebook_leads.md
Created January 29, 2016 23:33 — forked from tixastronauta/facebook_leads.md
Receiving Facebook Leads on a Webhook

Receiving Facebook Leads on a Webhook

1 - Create an App

Head over to developer.facebook.com and create an App

2 - Setup the webhook

On your server, create a facebook webhook that will handle facebook calls. Then create a "leadgen" webhook on you App: https://developers.facebook.com/docs/graph-api/webhooks/v2.5

@dreadjr
dreadjr / gist:dbd975676848f2d3ec49
Created November 5, 2015 21:03 — forked from jason-engage/gist:e072cc300fd789e8841e
Ionic Register Push Function Example with Payload and ionicPopup for Android and IOS
//Here is the curl commands I use to test - make sure you update the CAPSVARS. You can add an item ID Payload or not.
//For example if your app displays items, it can navigate to a specific item.
//If you want to add more state names, instead of only going to specific items:
//add another payload property called 'stateName'
//create a goState() function to accept a stateName as a parameter
//and modify the registerPush() to find the stateName property and pass into your goState().
//Android
curl -u YOURAPIKEY: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: APPID" https://push.ionic.io/api/v1/push -d '{"tokens":["ANDROIDTOKEN"],"notification":{"alert":"I come from planet Ion.", "android":{"title":"This is a title2", "payload":{"sound":"notification.mp3","itemId":"7TF00hJI78Y"}}}}'
@dreadjr
dreadjr / ui-router-logger.js
Last active September 28, 2015 17:00 — forked from stevermeister/ui-router-logger.js
AngualrJS ui-router logger snippet (helps for debug)
// Credits: Adam's answer in http://stackoverflow.com/a/20786262/69362
var $rootScope = null;
if (!$rootScope) $rootScope = angular.element(document).scope();
if (!$rootScope) $rootScope = angular.element(document.querySelectorAll("[ui-view]")[0]).injector().get('$rootScope');
$rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
console.log('$stateChangeStart to '+toState.to+'- fired when the transition begins. toState,toParams : \n',toState, toParams);
});
$rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams){
@dreadjr
dreadjr / push_notifications.js
Created September 25, 2015 17:35 — forked from katowulf/push_notifications.js
Push notifications from Firebase to Twilio.
//require the Twilio module and create a REST client
var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN');
var Firebase = require('firebase');
var fb = new Firebase('FIREBASE_URL');
fb.auth('FIREBASE_SECRET', function(err) {
if( err ) { throw err; }
listenForEvents();
})
@dreadjr
dreadjr / advanced.js
Created September 25, 2015 17:34 — forked from katowulf/advanced.js
Override $FirebaseArray.prototype.$$added in AngularFire (compatible with 0.9.x and above)
// create a class that we will use in place of the pojo (plain old javascript object)
// that is normally created in $FirebaseArray
function Person(snap) {
this.$id = snap.name();
this.updated(snap);
}
Person.prototype = {
updated: function(snap) {
this.data = snap.val();
@dreadjr
dreadjr / FirebaseService.js
Last active September 3, 2015 20:07
oloo tries
var FirebaseService = {
init: function(fb) {
this.fb = fb;
},
pathRef: function(args) {
for (var i = 0; i < args.length; i++) {
if (angular.isArray(args[i])) {
args[i] = this.pathRef(args[i]);
}
else if (typeof args[i] !== 'string') {
@dreadjr
dreadjr / app.js
Last active August 29, 2015 14:24 — forked from katowulf/app.js
var app = angular.module('app', ['firebase']);
app.controller('ctrl', function($scope, $pageArray) {
$scope.pageItems = $pageArray(ref, 'number');
});
app.factory('$pageArray', function($firebaseArray) {
return function(ref, field) {
// create a Paginate reference
var pageRef = new Firebase.util.Paginate(ref, field, {maxCacheSize: 250});

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