Skip to content

Instantly share code, notes, and snippets.

View dangayle's full-sized avatar

Dan Gayle dangayle

View GitHub Profile
@dangayle
dangayle / switch.py
Last active August 29, 2015 14:10 — forked from Lucretiel/switch.py
from contextlib import contextmanager
class SwitchError(RuntimeError):
pass
@contextmanager
def switch(switch_value, *, ignore_nomatch=True):
blocks = {}
blocks.default = None

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

def leaders(text, delimiter):
text = text.split(delimiter)
return "{0}{1:.>30}".format(*text)
@dangayle
dangayle / sasscolormixins.scss
Created April 27, 2011 22:57
sass color mixins?
$mid:#66CCFF;
@mixin colors($mid){
$lightest:lighten($mid, 50%);
$lighter:lighten($mid, 29%);
$light:lighten($mid, 25%);
$midder:darken($mid, 25%);
$dark:darken($mid, 40%);
$darkest:darken($mid, 60%);
$select:complement($dark);
@dangayle
dangayle / sassvariablescope.scss
Created April 27, 2011 22:29
Override SASS variable scope?
$mid:#66CCFF;
$dark:darken($mid, 40%);
a{
color:$mid;
&:hover{color:dark;}
}
@media only screen and (max-width: 767px) {
$mid:#22CCFF;
@dangayle
dangayle / gist:1903175
Created February 24, 2012 19:33
Python Bottle SQLite Version
from bottle import route, run, install
from bottle_sqlite import SQLitePlugin
install(SQLitePlugin(dbfile='bottle.db'))
@route('/db/')
def database(db):
data = db.execute('SELECT SQLITE_VERSION()').fetchone()
print "SQLite version: %s" % data
@dangayle
dangayle / gist:2040573
Created March 15, 2012 00:06
jquery slider loop thing
//Originally from http://trendmedia.com/news/infinite-rotating-images-using-jquery-javascript/
var InfiniteRotator =
{
init: function()
{
//set values
var initialFadeIn = 1000;
var itemInterval = 3000;
var fadeTime = 2500;
@dangayle
dangayle / gist:2912166
Created June 11, 2012 19:33
NGINX + PHP-FPM
Tasks: 84 total, 6 running, 78 sleeping, 0 stopped, 0 zombie
Cpu(s): 93.5%us, 4.3%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 0.9%si, 1.0%st
Mem: 506876k total, 316792k used, 190084k free, 42752k buffers
Swap: 262140k total, 7640k used, 254500k free, 185948k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19506 www-data 20 0 65868 24m 16m R 78 5.0 0:09.23 php5-fpm
19507 www-data 20 0 65100 25m 17m R 78 5.1 0:08.96 php5-fpm
19509 www-data 20 0 65356 24m 16m R 75 4.9 0:04.06 php5-fpm
19510 www-data 20 0 65100 24m 16m R 75 4.9 0:04.15 php5-fpm
def get_date_tree():
"""
Get all dates with stories, store in Redis. Cached for 1 day.
Returns an OrderedDict, with datetime objects as keys.
OrderedDict([(
datetime.date(1963, 1, 1), OrderedDict([(
datetime.date(1963, 11, 1), [
datetime.date(1963, 11, 22),
@dangayle
dangayle / gist:4027095
Created November 6, 2012 19:58
Incorrect way to import RSS feeds
<?php
include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://feeds.feedburner.com/wprecipes', 3);
?>