Skip to content

Instantly share code, notes, and snippets.

View bm2ilabs's full-sized avatar
🎯
Focusing

Boukraa Mohamed bm2ilabs

🎯
Focusing
View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@bm2ilabs
bm2ilabs / assert.php
Created March 21, 2013 10:08 — forked from joemay/assert.php
assert.php
<?php
/**
* Simple wrapper around the
* PHPUnit assertion library.
*
* Assert::equals(21, $age);
* Assert::greaterThan(20, $age);
* Assert::has('Joe', ['John', 'Joe']);
*/
@bm2ilabs
bm2ilabs / backbone.js
Created March 21, 2013 10:10 — forked from JeffreyWay/backbone.js
backbone.js
// In Backbone, when passing a collection around, do you prefer to inject the
// collection into the view, or store it on a global namespace?
// Injection
var SomeCollectionView = Backbone.View.extend({
initialize: function() {
// this.collection
}
});
new SomeCollectionView({ collection: App.myCollection });
<?php
class EloquenFooRepository
{
/**
* The base eloquent model
* @var Eloquent
*/
protected $model;
@bm2ilabs
bm2ilabs / after.sh
Last active August 29, 2015 14:18 — forked from cluppi/after.sh
#!/bin/sh
# Config for SSL.
echo "--- Making SSL Directory ---"
mkdir /etc/nginx/ssl
echo "--- Copying $i SSL crt and key ---"
openssl req -nodes -new -x509 -keyout /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.crt -subj "/C=US/ST=NY/L=NYC/O=Dis/CN=www.example.com"
echo "--- Turning SSL on in nginx.conf. ---"

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

Custom Sharing Buttons for Social Media

These files contain a basic template for creating customized social media share buttons on a web page. The CSS styles are arbitrary, and easily changes. The HTML and JavaScript works as follows.

HTML Structure

The buttons are simply a elements with no href value. Font Awesome is used to add icons. The IDs are used by the JavaScript to modify these a elements.

JavaScript Structure

This file uses jQuery.

Three functions are defined to find share counts for Facebook, Twitter and LinkedIn. Google+ is currently excluded.

The web page address is grabbed by window.location.href and encoded. The page title is pulled from whatever HTML element has id="title". The share count functions are called, and the results appended to the inner text of the share buttons. The the href of each button is changed to the appropriate URL for sharing the webpage.

@bm2ilabs
bm2ilabs / v-cloak.md
Created April 10, 2018 14:39 — forked from adamwathan/v-cloak.md
Useful CSS utilities for Vue.js cloaking

Handy helpers for controlling visibility of elements until Vue has compiled.

Use like:

<div v-cloak>
  <h1>
    <span class="v-cloak--inline">Loading...</span> <!-- Only displayed before compiling -->
    <span class="v-cloak--hidden">{{ post.title }}</span> <!-- Hidden until compiling is finished -->
 
@bm2ilabs
bm2ilabs / string-utils.js
Created February 14, 2019 19:21 — forked from jonlabelle/string-utils.js
Useful collection of JavaScript string utilities.
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str){
return str.toLowerCase();