Skip to content

Instantly share code, notes, and snippets.

View pydanny's full-sized avatar

Daniel Roy Greenfeld pydanny

View GitHub Profile
@pydanny
pydanny / getlinks.py
Last active August 29, 2015 13:55
This is the script used to get the links out of Two Scoops of Django 1.6 LaTeX files. It's been modified to generate HTML instead of a new appendix. It currently has a minor problem with duplicates, but as the rendered content is not going into the book, I'm not worrying about it.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import codecs
import json
from jinja2 import Template
import requests
# online
$ (awesomenv) pip install docopt
Downloading/unpacking docopt
Downloading docopt-0.6.1.tar.gz
Running setup.py egg_info for package docopt
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: invalid command 'egg_info'
# -*- coding: utf-8 -*-
import functools
# Broken implementation
class ClassDecoratorOptionalArguments(object): #rename
def __init__(self, value=None):
# set the 'value' argument as an attribute
self.value = value
@pydanny
pydanny / shortcut.go
Last active August 29, 2015 14:01
Does anyone else do this? Or is this a bad thing?
package main
import (
"fmt"
)
func main() {
var p = fmt.Println
p("I don't want to type fmt.Println.")
from djwebhooks.decorators import hook
from django_rq import job
# This assumes the project update was committed by user 'audreyr'
@job
@hook(event="project.update")
def send_project_update(project, owner, identifier):
""" The following help in identifying the webhook
:event: i.e. GitHub commit.push. Not unique!
from djwebhooks.decorators import hook
# This assumes the project update was committed by user 'audreyr'
@hook(event="project.update")
def send_project_update(project, owner, identifier):
""" The following help in identifying the webhook
:event: i.e. GitHub commit.push. Not unique!
:owner: Who created a webhook. I.E. pydanny
:identifier: A owner or system defined key. Unique amongst pydanny's webhooks'
>>> from webhooks import webhook
>>> from webhooks.senders import targeted
>>> @webhook(sender_callable=targeted.sender)
>>> def basic(url, wife, husband):
>>> return {"husband": husband, "wife": wife}
>>> r = basic(url="http://httpbin.org/post", husband="Danny", wife="Audrey")
>>> import pprint
>>> pprint.pprint(r)
@pydanny
pydanny / code.py
Last active August 29, 2015 14:01
This is the code that Prince Robinhood Crown is trying to resolve. Please put answers in the comments.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
For Python 2.7
Prince's comments:
To be able to access systems through Facebook, I just want the code to be able to recieve the three cookies e.g
def swap(a, x, y):
"""Swap two position values in a list"""
a[x],a[y] = a[y], a[x]