Skip to content

Instantly share code, notes, and snippets.

View slav123's full-sized avatar

Slawomir Jasinski slav123

View GitHub Profile
@slav123
slav123 / gist:4404088
Last active December 10, 2015 07:58 — forked from anonymous/gist:4404086
<?php
$xml_body = simplexml_load_string('text.xml', NULL, LIBXML_NOERROR+LIBXML_ERR_FATAL+LIBXML_ERR_NONE);
var_dump($xml_body);
@slav123
slav123 / gist:4434141
Created January 2, 2013 12:11
amazon read only policy
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
@slav123
slav123 / fallback.js
Created January 14, 2013 06:27
console.log fallback
var alertFallback = true;
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = {};
if (alertFallback) {
console.log = function (msg) {
alert(msg);
};
} else {
console.log = function () {
};
@slav123
slav123 / gist:4528153
Created January 14, 2013 06:30
CSS3 transitions recognition
function supportsTransitions() {
var b = document.body || document.documentElement;
var s = b.style;
var p = 'transition';
if (typeof s[p] == 'string') {
return true;
}
// Tests for vendor specific prop
v = ['Moz', 'Webkit', 'Khtml', 'O', 'ms'],
@slav123
slav123 / .htaccess
Created February 16, 2013 01:44
htaccess - non WWW to WWW redirect
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ https%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
or
RewriteCond %{HTTP_HOST} ^snapupaholiday.com.au
RewriteRule (.*) https://www.snapupaholiday.com.au/$1 [R=301,L]
@slav123
slav123 / .htaccess
Last active December 11, 2017 08:16
apache SSL
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
@slav123
slav123 / .htaccess
Created February 21, 2013 01:07
vary accept encoding
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
@slav123
slav123 / .htaccess
Created February 21, 2013 01:07
enable gzip compression on assetss
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
@slav123
slav123 / gist:5069995
Created March 2, 2013 07:00
S3 AWS read policy
{
"Version":"2008-10-17",
"Statement":[{
"Sid":"PublicReadGetObject",
"Effect":"Allow",
"Principal": {
"AWS": "*"
},
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::example-bucket/*"

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