Skip to content

Instantly share code, notes, and snippets.

@dreadjr
dreadjr / setOps.js
Last active August 29, 2015 14:15 — forked from jabney/setOps.js
// setOps.js MIT License © 2014 James Abney http://github.com/jabney
// Set operations union, intersection, symmetric difference,
// relative complement, equals. Set operations are fast.
(function(so) {
'use strict';
var uidList = [], uid;
// Create and push the uid identity method.
var Firebase = require('firebase');
var async = require('async');
// Extract data from the kinesis event
exports.handler = function(event, context) {
// This function abstracts the expected structure of any Kinesis payload,
// which is a base64-encoded string of a JSON object, passing the data to
// a private function.
function handlePayload(record, callback) {
app.factory('NormalizedPosts', function($FirebaseArray, userCache) {
var PostsWithUsers = $FirebaseArray.$extendFactory({
// override $$added to include users
$$added: function(snap) {
// call the super method
var record = $FirebaseArray.prototype.$$added.call(this, snap);
userCache.$load( record.user ).$loaded(function( userData ) {
record.userData = userData;
});
function copyFbRecord(oldRef, newRef) {
oldRef.once('value', function(snap) {
newRef.set( snap.value(), function(error) {
if( error && typeof(console) !== 'undefined' && console.error ) { console.error(error); }
});
});
}
.pretty-buttons(@color, @background, @text-shadow: none) {
color: @color;
#gradient > .vertical(lighten(@background, 5%), darken(@background, 5%), 0%, 100%);
border-color: darken(@background, 10%);
border-bottom-color: darken(@background, 20%);
text-shadow: @text-shadow;
.box-shadow(inset 0 1px 0 rgba(255, 255, 255, .1));
&:hover,

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

@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});
@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 / 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 / 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){