Skip to content

Instantly share code, notes, and snippets.

View dangayle's full-sized avatar

Dan Gayle dangayle

View GitHub Profile
@dangayle
dangayle / srcset_resize.html
Created July 29, 2016 23:37
Using lazysizes in Django
{% load static mogrify %}
<img
class="lazyload {{ class }}"
src="{% static 'sv3/img/spokesman-logo.png' %}"
data-sizes="auto"
data-srcset="
{% mogrify img_url resize '300x169' %} 300w,
{% mogrify img_url resize '530x298' %} 530w,
{% mogrify img_url resize '720x408' %} 720w,
{% mogrify img_url resize '1170x658' %} 1170w,"
@dangayle
dangayle / vanilla-not-jquery.js
Created July 27, 2016 18:55 — forked from TexRx/vanilla-not-jquery.js
Pure JS alternatives to common CSS class jQuery functions
function hasClass(elem, className) {
return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
}
function addClass(elem, className) {
if (!hasClass(elem, className)) {
elem.className += ' ' + className;
}
}

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});
}