Skip to content

Instantly share code, notes, and snippets.

View dangayle's full-sized avatar

Dan Gayle dangayle

View GitHub Profile

Requirements

  • Docker Machine + Docker
  • curl
  • A Virtualbox-driven Docker Machine called "default" docker-machine create --driver virtualbox default (this is the default with Docker toolkit).

Usage

The git.io URL (http://git.io/vsk46) is a shortened form of the raw url of the plist.

@dangayle
dangayle / subreddit_latest.py
Created February 24, 2016 00:58
Get all available submissions within a subreddit newer than x
import sys
from datetime import datetime, timedelta
import praw
user_agent = "hot test 1.0 by /u/dangayle"
r = praw.Reddit(user_agent=user_agent)
class SubredditLatest(object):
"""Get all available submissions within a subreddit newer than x."""
@dangayle
dangayle / celery_janitor.py
Created December 10, 2015 21:46 — forked from jonhuber/celery_janitor.py
This is a script to clean up deadlocked Celery workers. I typically run it on servers every 15 minutes via cron.
from celery.app.control import Control
import datetime
import psutil
import socket
def main():
control = Control()
inspect = control.inspect()
hostname = socket.gethostname()
@dangayle
dangayle / mixin.py
Created December 1, 2015 18:42 — forked from cyberdelia/mixin.py
Django class based view mixins
# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import login_required
from django.utils.cache import patch_response_headers
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page, never_cache
from django.views.decorators.csrf import csrf_exempt
class NeverCacheMixin(object):
@method_decorator(never_cache)
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
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),
def leaders(text, delimiter):
text = text.split(delimiter)
return "{0}{1:.>30}".format(*text)
@dangayle
dangayle / golden_ratio.scss
Last active June 24, 2021 22:56
The only css grid you need, based on the golden ratio.
$grid-gutter-width: 30px;
.l-1{
// larger portion of golden ratio
width: calc(#{percentage(1/1.618)} - #{$grid-gutter-width / 2});
}
.l-2{
// Smaller portion of golden ratio
width: calc(#{percentage(1-1/1.618)} - #{$grid-gutter-width / 2});
}

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

@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