Skip to content

Instantly share code, notes, and snippets.

View djm's full-sized avatar

Darian Moody djm

View GitHub Profile
from scrapeMeta import scrapeMeta
import os
import json
from bs4 import BeautifulSoup
import urllib
def getHTML(url):
html = urllib.urlopen(url).read()
return BeautifulSoup(html)
@codeinthehole
codeinthehole / private_repos.py
Created February 12, 2014 11:54
Dirty script for finding repos to archive
import requests
import datetime
import sys
# Pass your OAuth token
token = sys.argv[1]
# Fetch all private repos (lazy - assumes only two pages)
headers = {'Authorization': 'token %s' % token}
response = requests.get(
@coordt
coordt / fabfile.py
Created December 1, 2010 12:51
A Fabric fabfile that allows you to check which packages are not like the others on a set of servers.
from __future__ import with_statement
from fabric.api import env, run, settings, hide
from fabric.decorators import hosts, runs_once
venv = "/home/websites/.virtualenvs/twtv3/"
env.user = 'webdev'
env.hosts = [
'192.168.1.10',
'192.168.1.11',
alias gs='git status'
alias gai='git add --interactive'
alias gsvn='git svn'
alias gsup='gsvn fetch && gsvn rebase'
alias gsp='gsup && gsvn dcommit'
alias gf='git fetch'
alias gr='git rebase'
alias gp='gup && git push'
alias gff='git flow feature'
alias gfr='git flow release'
@codeinthehole
codeinthehole / curried_subclass.py
Created September 9, 2011 08:38
Lightweight subclassing using curry
def curry(f, *args, **kwargs):
def curried(*more_args, **more_kwargs):
return f(*(args+more_args), **dict(kwargs, **more_kwargs))
return curried
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
@AndrewIngram
AndrewIngram / gist:3231297
Created August 1, 2012 22:33
supervisor script
;[program:andrewingram-gunicorn]
;command=/var/www/andrewingram.net/bin/gunicorn_django /var/www/andrewingram.net/src/andrewingram/andrewingram/settings.py
;directory=/var/www/andrewingram.net
;logfile=/var/www/andrewingram.net/log/supervisor.log
;user=deployer
;autostart=true
;autorestart=true
;redirect_stderr=True
[program:andrewingram-uwsgi]
@gausby
gausby / gravatar.ex
Last active November 11, 2015 17:40
An Elixir port of the node.js module 'gravatar-url'. People often ask «where are the packages for Elixir?» Often the answer is «they are baked in; for anything else try out Hex.pm»
defmodule Gravatar do
@base_url "https://secure.gravatar.com/avatar/"
@doc """
Will get the corresponding gravatar url for a given email address. Options
can be passed in using a keyword list or a map.
iex> Gravatar.url("martin@gausby.dk", size: 200)
https://secure.gravatar.com/avatar/0e6a9f19e77fa18bf6f185258f2507d6?size=200
from django.forms.models import model_to_dict
class ModelDiffMixin(object):
"""
A model mixin that tracks model fields' values and provide some useful api
to know what fields have been changed.
"""
def __init__(self, *args, **kwargs):
@knewter
knewter / contact_test.exs
Created October 8, 2015 12:24
ecto many to many query
# -*- c-basic-offset: 2; indent-tabs-mode: nil -*-
defmodule Score.ContactTest do
use Score.TestCase
@joe %{name: "joe", email: "joe@vipaar.com", sign_in_count: 0}
@joe_changeset User.changeset(%User{}, :create, @joe)
@bob %{name: "bob", email: "bob@vipaar.com", sign_in_count: 0}
@bob_changeset User.changeset(%User{}, :create, @bob)
setup do
@djm
djm / bulk.py
Created June 29, 2018 14:57 — forked from danfairs/bulk.py
Bulk utilities
"""
Utilities for working with bulk data and batches.
"""
import itertools
def batches(items, batch_size=500):
"""
Given an iterable of items and a batch size, yield individual lists
of items of maximum length `batch_size`.