Skip to content

Instantly share code, notes, and snippets.

@khornberg
khornberg / controllers.application.js
Last active May 30, 2017 13:54
multiple changesets per page
import Ember from 'ember';
import { schema } from '../models/user';
import Validations from '../validations/user';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
Validations,
changesets: {},
allValid(changeArray) {
import Ember from 'ember';
import { schema } from '../models/user';
import Validations from '../validations/user';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
Validations,
changesets: {},
allValid(changeArray) {
@khornberg
khornberg / lexer.py
Last active December 19, 2018 20:52
Boolean expression matching
from ply import lex
class BooleanMatchError(Exception):
pass
reserved = {'AND': 'AND', 'OR': 'OR'}
math_tokens = [
@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
@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 / 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 / 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 / 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
def convert(text):
return "".join([x.capitalize() for x in text.split('-')])
@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