Skip to content

Instantly share code, notes, and snippets.

View qborreda's full-sized avatar

Quique Borredá qborreda

View GitHub Profile
@qborreda
qborreda / ultimate-ut-cheat-sheet.md
Created June 19, 2017 16:54 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai and Sinon

The Ultimate Unit Testing Cheat-sheet

For Mocha, Chai and Sinon

using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies


@qborreda
qborreda / uniq.js
Created April 26, 2017 14:45 — forked from telekosmos/uniq.js
Remove duplicates from js array (ES5/ES6)
var uniqueArray = function(arrArg) {
return arrArg.filter(function(elem, pos,arr) {
return arr.indexOf(elem) == pos;
});
};
var uniqEs6 = (arrArg) => {
return arrArg.filter((elem, pos, arr) => {
return arr.indexOf(elem) == pos;
});
/*
* promiseSerial resolves Promises sequentially.
* @example
* const urls = ['/url1', '/url2', '/url3']
* const funcs = urls.map(url => () => $.ajax(url))
*
* promiseSerial(funcs)
* .then(console.log)
* .catch(console.error)
*/
@qborreda
qborreda / countCSSRules.js
Last active September 13, 2016 07:55 — forked from psebborn/countCSSRules.js
Count the number of rules and selectors for CSS files on the page.
/**
* Chrome Snippet
* Count the number of rules and selectors for CSS files on the page.
* Flags up the >4096 threshold that confuses IE.
*/
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
@qborreda
qborreda / DropZone.jsx
Created August 24, 2016 12:29 — forked from pizzarob/01_DropZone.jsx
HTML5 Drag and Drop File Upload React Component
import React, {PropTypes} from 'react';
import classNames from 'classnames';
const ANIMATION_DURATION = 1000;
class BatchDropZone extends React.Component {
static propTypes = {
// function that recieves an array of files
@qborreda
qborreda / css-triangle.scss
Created November 30, 2015 08:48 — forked from patocallaghan/css-triangle.scss
CSS Triangles SCSS Mixin #css #scss #triangle #mixin
//==== Simple SCSS mixin to create CSS triangles
//==== Example: @include css-triangle ("up", 10px, #fff);
@mixin css-triangle ($direction: "down", $size: 20px, $color: #000) {
width: 0;
height: 0;
border-left: $size solid #{setTriangleColor($direction, "left", $color)};
border-right: $size solid #{setTriangleColor($direction, "right", $color)};
border-bottom: $size solid #{setTriangleColor($direction, "bottom", $color)};
border-top: $size solid #{setTriangleColor($direction, "top", $color)};
}
// Alerts
@include alert-variant($background, $border, $text-color);
// Background Variant
@include bg-variant($parent, $color);
// Border Radius
@include border-top-radius($radius);
@include border-right-radius($radius);
@include border-bottom-radius($radius);
@qborreda
qborreda / FlexBox_Layout.scss
Created November 24, 2015 10:14 — forked from alisonailea/FlexBox_Layout.scss
Based on CSS Tricks: Using Flexbox - http://css-tricks.com/using-flexbox/ & Special Thanks to Hugo Giraudel- http://hugogiraudel.com/2013/07/15/understanding-sass-lists/ Flexbox with elegant depreciation. Works in IE10+, iOS 6-, Safari 3.1-6, Firefox 20-, Chrome, Opera 12.1 The advantage of this Mixin set is it is small and reusable. Use any cla…
@mixin setFlexBox($flexType){
//options are block level or inline
@if $flexType == 'block'{
display: -webkit-box;
display: -moz-box;
display: box;
display: -ms-flexbox;
display: flexbox;
display: -webkit-flex;
display: flex;
@qborreda
qborreda / data-action.js
Last active May 30, 2021 11:18 — forked from pbojinov/data-action.js
JavaScript event hooking with data-action
// Set up HTML hooks without id or extra classes
<button data-action="openLogin">Login</button>
<a href="javascript:;" data-action="openEditor">Link</a>
// Using [data-action=""] selectors instead of class selectors when binding events in JavaScript
var actions = {
openLogin: openLoginWindow,
openEditor: function() { ... }
//....
};

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