Skip to content

Instantly share code, notes, and snippets.

View lene's full-sized avatar

Lene Preuss lene

View GitHub Profile

does this work without publishing a lot of information too?

Keybase proof

I hereby claim:

  • I am lene on github.
  • I am lilacashes (https://keybase.io/lilacashes) on keybase.
  • I have a public key whose fingerprint is 8B6C 0B76 06AD ABA0 90FC 1E81 B3CA C532 4421 818C

To claim this, I am signing this object:

@lene
lene / decorator_method.py
Last active January 30, 2018 14:37
Python decorator (class method)
from functools import wraps
def method_decorator(method):
@wraps(method)
def method_wrapper(self, *args, **kwargs):
return do_stuff(method(self, *args, **kwargs))
return method_wrapper
@lene
lene / decorator_function.py
Last active January 30, 2018 14:37
Python decorators (free function)
from functools import wraps
def decorator(func):
@wraps(func)
def func_wrapper(*args, **kwargs):
return do_stuff_to_func(func(*args, **kwargs))
return func_wrapper
@lene
lene / HSTORE_keys.sql
Last active January 30, 2018 14:40
Select a list of all keys in an HSTORE field across the entire table
CREATE TABLE my_hstore_table (
id SERIAL NOT NULL,
attributes HSTORE NOT NULL
);
SELECT DISTINCT UNNEST(AKEYS(attributes)) AS key FROM my_hstore_table ORDER BY key;
@lene
lene / find.py
Last active January 30, 2018 14:41
Emulating UNIX command find(1) in Python
def find_files(base_path, condition):
return [
os.path.join(root, file)
for root, _, files in os.walk(base_path)
for file in files
if os.path.exists(os.path.join(root, file)) # probably redundant, just making sure
if condition(os.path.join(root, file))
]
# e.g. find -f -ctime -N
@lene
lene / demo.html
Created March 8, 2018 11:27
HTML page including all JavaScript for HERE Intermodal Routing API blog
<html>
<head>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script src="http://taser-dev.rnd.transit.api.here.com:8008/static/js/jquery.min.js"></script>
<script src="tools.js"></script>
</head>
@lene
lene / here.js
Created March 8, 2018 11:29
Creating a map using the HERE Maps Javascript API
var platform = new H.service.Platform({
useCIT: true,
app_id: '{YOUR_APP_ID}', // // <-- ENTER YOUR APP ID HERE
app_code: '{YOUR_APP_CODE}', // <-- ENTER YOUR APP CODE HERE
});
var maptypes = platform.createDefaultLayers();
var map = new H.Map(document.getElementById('map'), maptypes.terrain.map, {
zoom: 9,
center: { lat: 41.884238, lng: -87.638862 }
@lene
lene / tools.js
Last active March 19, 2018 13:15
Requesting and rendering a route from the HERE Intermodal Routing API
(function(NS) {
var APP_ID = '{YOUR_APP_ID}', // // <-- ENTER YOUR APP ID HERE
APP_CODE = '{YOUR_APP_CODE}'; // <-- ENTER YOUR APP CODE HERE
function Mobility(options) {
this.map = options.map;
}
Mobility.prototype = {
@lene
lene / here.js
Last active March 20, 2018 14:26
Add this at the end of here.js to request and display a Park and Ride route
var mobility = new H.Mobility({
map: map,
app_id: '{YOUR_APP_ID}', // <-- ENTER YOUR APP ID HERE
app_code: '{YOUR_APP_CODE}', // <-- ENTER YOUR APP CODE HERE
});
var ui = mobility.createDefaultUI();
mobility.route({
dep: {YOUR_START_POINT}, // <-- ENTER YOUR START POINT HERE