Skip to content

Instantly share code, notes, and snippets.

@khornberg
khornberg / example.py
Created October 27, 2022 17:57
Reading a CSV file
"""
More documenation about the csv moodule at https://docs.python.org/3/library/csv.html
"""
import csv
# the path to the file is relative to where you execute the python command
# both this file and the test.csv file should be in the same directory/folder
# you should run the command `python example.py` (without the backticks `) from the directory that contains example.py
with open('test.csv') as csvfile:
import graphlib
def ts_sort(topological_sorter):
topological_sorter.prepare()
spaces = 0
while topological_sorter:
nodes = topological_sorter.get_ready()
print(" "*spaces, nodes)
for node in nodes:
@khornberg
khornberg / index.html
Created December 10, 2020 19:40
Knockout and Vue - it's "just" JavaScript :)
<html>
<head>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/knockout/3.5.0/knockout-min.js'></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<p>
Demonstrates that knockout and vue and communicate data between the two frameworks
<br>
The data and shared functions are shown as pure javascript objects or functions
@khornberg
khornberg / jsonapi.json
Created August 7, 2020 13:50
JSON:API general OpenSpec
{"openapi": "3.0.2", "info": {"version": "1.0.0", "title": "{json:api} Specification", "description": "An include file to define the [{json:api} 1.0 specification](http://jsonapi.org/format). N.B. I've got some confusion going on between a validating a jsonapi schema and defining one!\n\nThis file also provides a limited demonstration of jsonapi with path items for collections, items and their methods. You should be able to open in a modern version of [swagger-editor](https://github.com/swagger-api/swagger-editor) or [swagger-ui-watcher](https://github.com/moon0326/swagger-ui-watcher).\n\nThis file was created by downloading the [schema definition](http://jsonapi.org/schema) and then editing as needed to make it useful with the Open API Specification. It is subject to the `CC0 1.0 Universal` license as it is derived from the {json:api} specification.\n\nSeveral changes had to be made to that schema since it is non-normative and primarily only documented the results of GET operations. See especially definition
def convert(text):
return "".join([x.capitalize() for x in text.split('-')])
@khornberg
khornberg / delete.sh
Created January 22, 2019 20:15
delete cloudformation stack on a filter
aws cloudformation list-stacks --stack-status-filter REVIEW_IN_PROGRESS | jq -c '.StackSummaries[] | .StackName' | xargs -L 1 aws cloudformation delete-stack --stack-name
@khornberg
khornberg / config.targets.js
Last active October 22, 2018 15:16
Watching router broken
'use strict';
const browsers = [
'ie 11',
'last 1 Chrome versions',
'last 1 Firefox versions',
'last 1 Safari versions'
];
const isCI = !!process.env.CI;
@khornberg
khornberg / circle-text.html
Created July 30, 2018 15:51
Circle with centered text via html canvas
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
@khornberg
khornberg / test.js
Created January 11, 2018 14:45
ember integration test with store
let store = (container) => {
const store = container.lookup('service:store');
Ember.run(() => {
store.createRecord('model', {
modelAttr: 'one'
});
store.createRecord('model', {
modelAttr: 'two'
});
});
@khornberg
khornberg / encode_decode_dictionary.py
Created August 25, 2017 12:39
python 3 base64 encode dict
"""
Given a dictionary, transform it to a string. Then byte encode that string. Then base64 encode it and since this will go
on a url, use the urlsafe version. Then decode the byte string so that it can be else where.
"""
data = base64.urlsafe_b64encode(json.dumps({'a': 123}).encode()).decode()
# And the decode is just as simple...
data = json.loads(base64.urlsafe_b64decode(query_param.encode()).decode())
# Byte encode the string, base64 decode that, then byte decode, finally transform it to a dictionary