Skip to content

Instantly share code, notes, and snippets.

View dangayle's full-sized avatar

Dan Gayle dangayle

View GitHub Profile
@dangayle
dangayle / unique.py
Created October 29, 2014 03:56
unique list
from collections import OrderedDict
from itertools import repeat, izip
alist = ["a", "b", "c", "a"]
n = repeat(None)
print(list(OrderedDict(izip(alist,n))))
import datetime
import random
import Twython
from twisted.internet import task
from twisted.internet import reactor
TIMEOUT = datetime.timedelta(hours=1).seconds
twitter = Twython("YOUR API KEY",
"YOUR API SECRET",
"""
I need to create a "most active" or "hottest" stories list, the main variables
being number of comments, number of views, and pubdate.
How do I take the three variables and create sort of weighted score, then sort on the score?
"""
stories = [
{ # 2 days old
"id": 1,
Verifying that +dangayle is my Bitcoin username. You can send me #bitcoin here: https://onename.io/dangayle
from django.db.models import Max
from blogs.models import Blog, BlogPost
def get_recent_posts():
"""Get latest blogpost for each blog."""
posts = []
blogs = Blog.objects.annotate(
most_recent=Max('blogpost__pubdate')
).order_by('-most_recent')[:Blog.objects.count()]

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@dangayle
dangayle / seq_range.py
Last active August 29, 2015 14:03
Paging function
def seq_range(page=1, prange=10):
"""Get a range of numbers for paging"""
start = page * prange - prange
end = start + prange - 1
print start, end
@dangayle
dangayle / twitterbot.py
Last active September 9, 2021 03:06
Twitter bot that tweets a random line from a file. Uses Twisted to periodically select a random line from an input file, and Twython to post it to Twitter using your credentials. Usage: python twitterbot.py file.txt, where each line in file.txt is a single sentence terminated by a newline ('\n').
"""Twitter bot that tweets a random line from a file.
Uses Twisted to periodically select a random line from an input file,
and Twython to post it to Twitter using your credentials.
Usage: python twitterbot.py file.txt, where each line in file.txt is
a single sentence terminated by a newline ('\n').
"""
import sys
test_string = '''<!--[youtube id="vlmGknvr_Pg"]-->'''
def youtube(id):
return "https://www.youtube.com/watch?v={id}".format(id=id)
# >> https://www.youtube.com/watch?v=vlmGknvr_Pg
@dangayle
dangayle / hello_world.py
Created May 28, 2014 16:59
Basic html/css/python
def hello_world(name=None):
if name is None:
name = "world"
print("Hello {name}".format(name=name))
hello_world("Dan")