Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wardi
wardi / urlsafe3.py
Created February 19, 2020 17:32
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
wardi / inventory_dl.py
Created May 10, 2017 18:46
Download and strip newlines and double quotes from OD inventory dataset
#!/usr/bin/env python2
import requests
import csv
URL = 'http://open.canada.ca/data/dataset/4ed351cf-95d8-4c10-97ac-6b3511f359b7/resource/d0df95a8-31a9-46c9-853b-6952819ec7b4/download/inventory.csv'
OUTPUT = 'inventory-stripped.csv'
r = requests.get(URL, stream=True)
out = csv.writer(open(OUTPUT, 'wb'))
for row in csv.reader(r.raw):
diff --git a/ckan/plugins/toolkit.py b/ckan/plugins/toolkit.py
index a072b1e..2763b98 100644
--- a/ckan/plugins/toolkit.py
+++ b/ckan/plugins/toolkit.py
@@ -20,7 +20,7 @@ class _Toolkit(object):
'_', # i18n translation
'ungettext', # i18n translation (plural forms)
'c', # template context
- 'h', # template helpers
+ #'h', # template helpers
@wardi
wardi / gist:744d3bb721b0009df9b5
Created July 9, 2015 22:40
drop shadow in urwid
#!/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(' ')),
urwid.SolidFill('X')])
bottom_shadow = urwid.Columns([
>>> dis.dis(lambda: 10000/2 + 1)
1 0 LOAD_CONST 1 (10000)
3 LOAD_CONST 2 (2)
6 BINARY_DIVIDE
7 LOAD_CONST 3 (1)
10 BINARY_ADD
>>> timeit.timeit("np.array([42]*10000, dtype=float)", "import numpy as np", number=15000)
14.971487045288086
>>> timeit.timeit("np.ones(10000, dtype=float) * 42", "import numpy as np", number=15000)
0.5964510440826416
>>> timeit.timeit("np.multiply(np.ones(10000, dtype=float), 42)", "import numpy as np", number=15000)
0.5582938194274902
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
<!--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 attr.name="url" attr.type="string" for="node" id="d4"/>
<key attr.name="description" attr.type="string" for="node" id="d5"/>
<key for="node" id="d6" yfiles.type="nodegraphics"/>
@wardi
wardi / gist:8337153
Created January 9, 2014 16:30
urwid text layout that fills with underscores on the right (works with wide and combining characters too!)
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: