Skip to content

Instantly share code, notes, and snippets.

wardi /
Created Feb 19, 2020
url-safe string functions
# -*- coding: utf-8 -*-
import re
def url_part_escape(orig):
simple encoding for url-parts where all non-alphanumerics are
wrapped in e.g. _xxyyzz_ blocks w/hex UTF-8 xx, yy, zz values
used for safely including arbitrary unicode as part of a url path

Retrieve Records

Access this data through the CKAN Datastore API with resource_id="b076ced6-ef48-45b8-8db2-dd7d27c11fe2"

The CKAN API uses a JSON-RPC style, where you post a JSON object and receive another JSON object in response.

Retrieving records requires an API key. Your API key is shown on your profile page.

Do not include your API key in any code shared with other people. Use a configuration file or environment variable to let each user input their own key when they use your tool. Your API key is equivalent to your password and may be used to perform any action your user can on this site. All actions made with your API key will be logged as actions you performed. Example:

Answers to shopping list, generation, iteration, decoration exercises posted
def shopping_list():
Exercise: shopping list
using while True: and input() create a shopping list interface allowing a user to enter multiple items then type DONE to exit
wardi /
Created May 10, 2017
Download and strip newlines and double quotes from OD inventory dataset
#!/usr/bin/env python2
import requests
import csv
URL = ''
OUTPUT = 'inventory-stripped.csv'
r = requests.get(URL, stream=True)
out = csv.writer(open(OUTPUT, 'wb'))
for row in csv.reader(r.raw):
View toolkit-fix.patch
diff --git a/ckan/plugins/ b/ckan/plugins/
index a072b1e..2763b98 100644
--- a/ckan/plugins/
+++ b/ckan/plugins/
@@ -20,7 +20,7 @@ class _Toolkit(object):
'_', # i18n translation
'ungettext', # i18n translation (plural forms)
'c', # template context
- 'h', # template helpers
+ #'h', # template helpers
View gist:744d3bb721b0009df9b5
#!/usr/bin/env python
import urwid
thing_to_wrap = urwid.Text(' '.join(str(n) for n in range(1000, 1115)))
right_shadow = urwid.Pile([
(1, urwid.SolidFill(' ')),
bottom_shadow = urwid.Columns([
View gist:19bd4ecb17cdaa896c83
>>> dis.dis(lambda: 10000/2 + 1)
1 0 LOAD_CONST 1 (10000)
3 LOAD_CONST 2 (2)
7 LOAD_CONST 3 (1)
View gist:a22b65aeee409283c0b9
>>> timeit.timeit("np.array([42]*10000, dtype=float)", "import numpy as np", number=15000)
>>> timeit.timeit("np.ones(10000, dtype=float) * 42", "import numpy as np", number=15000)
>>> timeit.timeit("np.multiply(np.ones(10000, dtype=float), 42)", "import numpy as np", number=15000)
View CKAN data model
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml xmlns="" xmlns:xsi="" xmlns:y="" xmlns:yed="" xsi:schemaLocation="">
<!--Created by yEd 3.12.2-->
<key for="graphml" id="d0" yfiles.type="resources"/>
<key for="port" id="d1" yfiles.type="portgraphics"/>
<key for="port" id="d2" yfiles.type="portgeometry"/>
<key for="port" id="d3" yfiles.type="portuserdata"/>
<key"url" attr.type="string" for="node" id="d4"/>
<key"description" attr.type="string" for="node" id="d5"/>
<key for="node" id="d6" yfiles.type="nodegraphics"/>
wardi / gist:8337153
Created Jan 9, 2014
urwid text layout that fills with underscores on the right (works with wide and combining characters too!)
View gist:8337153
import urwid
class UnderscoreRight(urwid.StandardTextLayout):
def layout(self, text, width, align, wrap):
s = urwid.StandardTextLayout.layout(self, text, width, align, wrap)
out = []
last_offset = 0
for row in s:
used = 0
for seg in row: