Skip to content

Instantly share code, notes, and snippets.

View cwurld's full-sized avatar

Chuck Martin cwurld

View GitHub Profile
@cwurld
cwurld / ccm_python-flckr.py
Created April 29, 2013 18:18
How to POST a photo to Flickr using Python The Flickr api docs are OK, but lacking in detail about how to post a photo once you complete the oauth process. Matt Kelsey has a nice blog post about basic oauth process with Flickr: http://mkelsey.com/2011/07/03/Flickr-oAuth-Python-Example/. Read his blog first. I should mention that I tried using Py…
import time
import oauth2 as oauth
import requests # From: http://docs.python-requests.org/en/latest/
# oauth_token and oauth_token_secret are the tokens produced at the end of the Flickr oauth process
token = oauth.Token(oauth_token, oauth_token_secret)
photo_url = 'http://api.flickr.com/services/upload'
@cwurld
cwurld / finale_api.py
Last active March 9, 2022 17:16
Python for Accessing Finale Inventory REST API
import requests
import json
import base64
import pprint
import unittest
import time
import datetime
# Put this in contactMechList
ADDRESS_TEMPLATE = {
@cwurld
cwurld / fix_chosen.js
Created December 4, 2014 23:22
For Fixing Chosen Selects Created by Django Dynamic Formsets
/**
* Created by Chuck Martin on 12/4/14.
*
* When django-dynamic-formset creates a new formset and that formset used the "Chosen" widget
* (http://harvesthq.github.io/chosen/), the newly created Chosen widget does not work right.
*
* This code solves that problem by replacing the select (along with the chosen code) that was cloned with a new
* select created from scratch.
*
* This function returns a function for creating a new select that can be associated with Chosen.
@cwurld
cwurld / convert_template.py
Last active August 29, 2015 14:11
Converts a Django page template into a page template for a Django project template
from __future__ import absolute_import
__author__ = 'Chuck Martin'
import os
import Tkinter
import tkFileDialog
def convert_template(file_path=None, out_dir=None):
@cwurld
cwurld / selenium_for_chosen.py
Last active January 1, 2016 17:16
Python code for handling the jquery Chosen plugin when testing using selenium.
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
class Chosen(object):
"""
For selenium testing of the jquery Chosen widget (v1.1.0 https://harvesthq.github.io/chosen/).
@cwurld
cwurld / django_testcase_cheatsheet.py
Last active June 23, 2022 23:51
Django TestCase Cheatsheet
__author__ = 'chuck'
from urlparse import urlparse
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from django.conf import settings
from django.contrib.auth.models import User, Group
from django.core.cache import cache
@cwurld
cwurld / quickstart.py
Created January 11, 2016 14:50
Google Calendar Python API with Freebusy
"""
Mostly the Google quickstart.py code with the "freebusy" service running.
Also shows how to make datetimes using pytz.
Follow these instructions to get access credentials:
https://developers.google.com/google-apps/calendar/quickstart/python
"""
@cwurld
cwurld / gist:7db1a642c32ff548c184
Last active January 16, 2017 23:51
django selenium cheatsheet
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.support.select import Select
# DOES NOT WORK WITH selenium 2.5 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@cwurld
cwurld / django_select2_mixin.py
Last active April 21, 2016 14:30
django and select2
'''
I have a model for customer intake. One of the fields is for tracking how the customer heard about us. I do
not want an endless proliferation of values, so I would like to use a multi-select. The problem is I also want the
user to add new choices as needed. It turns out this is possible with the Select2 widget:
https://select2.github.io/examples.html#tokenizer - check out this link to see how to setup your javascript.
It turns out this is a little tricky to implement. Below is a mixin you can use with a form to handle the field.
Also, if you are using bootstrap, you will want: https://fk.github.io/select2-bootstrap-css/
@cwurld
cwurld / gist:bbd138c953b416644ed66901d1e9196b
Last active July 18, 2017 10:07
Example of Python Dedupe Gazetteer
# Gazetteer ---------------------------------------------------------------------------------------------------------
def load_deduped_output_for_gazetteer(filename):
"""
Parse data from dedupe into:
1. Canonical dataset (no dupes)
2. messy data - all the dupes
3. markPairs.
:return: