Skip to content

Instantly share code, notes, and snippets.

View dangayle's full-sized avatar

Dan Gayle dangayle

View GitHub Profile
@dangayle
dangayle / app.js
Created January 2, 2017 22:28
Loading Tachyons using Webpack and React
import React from 'react';
import Tachyons from 'tachyons/css/tachyons.min.css'
const App = () => (
<div className="mw9 center">
<h2 className="red sans-serif tc">Hello, world</h2>
</div>
);
export default App;
@dangayle
dangayle / methodology.md
Last active August 23, 2016 19:47
Calculate the population of an area affected by active wildfires

Create estimate of population affected by active fires

The goal is to estimate the amount of people affected by active fires in a given area, using VIIRS satellite data and US Census data

  1. Cluster fire data points from VIIRS data into groups, representing active fire areas
  2. For each group, create a polygon that contains all points (a convex hull), this represents the boundaries of a given fire area
@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),