Skip to content

Instantly share code, notes, and snippets.

Christian Klotz christianklotz

View GitHub Profile
@christianklotz
christianklotz / sketch-load-json.js
Created Mar 19, 2019
Load JSON file into Sketch
View sketch-load-json.js
let readBinaryFile = (filepath) => {
return NSData.alloc().initWithContentsOfFile(filepath);
};
let path = "path/to/file.json"
let data = readBinaryFile(path)
let contents = NSString.alloc().initWithData_encoding(data, NSUTF8StringEncoding)
console.log(JSON.parse(contents))
@christianklotz
christianklotz / aws-cloudformation-resource-name-limit.md
Last active Jul 18, 2018
AWS CloudFormation resource name character limit
View aws-cloudformation-resource-name-limit.md

Using custom resource names in CloudFormation can potentially cause resources' physical ids to exceed the allowed limit of 64 characters. Especially with nested stacks, as AWS::CloudFormation::Stack does not support custom names causing nested stacks to always be named automatically in the format <logical-id>-XXXXXXXXXXXX, with XXXXXXXXXXXX being a autogenerated identifier.

Below is an example of AWS::Lambda::Function within a nested CloudFormation stack.

With functionName

Physical resource id is generated using the following format.

<root-stack-name>-XXXXXXXXXXXX-<lambda-function-name>

Quickly exceeds max length 64 characters.

@christianklotz
christianklotz / aws-template-bucket-custom-acl.yaml
Created Jun 19, 2018
CloudFormation template to create S3 bucket resource with custom role
View aws-template-bucket-custom-acl.yaml
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
BucketPrefix:
Type: String
Description: "The prefix used for all S3 buckets."
AllowedPattern: "[a-z-]+"
Resources:
@christianklotz
christianklotz / gcp-template-bucket-custom.jinji
Created Jun 19, 2018
Google Cloud Deployment Manager template creating bucket with custom service account
View gcp-template-bucket-custom.jinji
resources:
# Bucket to hold all asset
- name: {{ properties['bucket-prefix'] }}-assets
type: storage.v1.bucket
accessControl:
gcpIamPolicy:
bindings:
- role: roles/storage.objectAdmin
members:
View dedup_pipeline.go
package main
import (
"fmt"
"math/rand"
"time"
)
func generate(nums ...int) chan int {
out := make(chan int)
View keybase.md

Keybase proof

I hereby claim:

  • I am christianklotz on github.
  • I am christianklotz (https://keybase.io/christianklotz) on keybase.
  • I have a public key whose fingerprint is C379 1DED 2328 2727 E094 4D67 E8B9 609E 233F D8AC

To claim this, I am signing this object:

@christianklotz
christianklotz / circle.yml
Created May 9, 2017
Circle CI configuration with deployment stages
View circle.yml
general:
artifacts:
- "coverage/lcov-report"
machine:
node:
version: 7.6.0
# environment:
# set the following variables in CircleCI project settings
# AWS_ACCESS_KEY_ID
# AWS_SECRET_ACCESS_KEY
@christianklotz
christianklotz / package-ortools-app.sh
Created Oct 17, 2016
Create Python app package for Amazon AWS Lambda including Google's ortools dependencies
View package-ortools-app.sh
#!/bin/bash
DEST_DIR=$(dirname $(realpath -s $0));
echo "Copy all native libraries...";
mkdir -p ./lib && find $directory -type f -name "*.so" | xargs cp -t ./lib;
echo "Create package...";
zip -r dist.zip your-python-script.py lib;
rm -r ./lib;
@christianklotz
christianklotz / install-ortools.sh
Created Oct 17, 2016
Shell script to install Google's OR tools
View install-ortools.sh
#!/bin/bash
echo "Dowloading Google's Operations Research tools...";
ORTOOLS_TAR=or-tools.python.examples_v4.4.3842.tar.gz;
ORTOOLS_TAR_URL=https://github.com/google/or-tools/releases/download/v4.4/${ORTOOLS_TAR};
curl -O -L ${ORTOOLS_TAR_URL};
tar -xzf ${ORTOOLS_TAR}; cd ortools_examples; python setup.py install;
@christianklotz
christianklotz / food-request-validation-failed.json
Last active Sep 9, 2016
Error response for a food request resulting in a validation error
View food-request-validation-failed.json
{
"message": "validation failed",
"code": 1234,
"errors": [{
"code": 5678,
"message": "not so healthy",
"field": "food",
"suggested_value": "🍎"
}]
}
You can’t perform that action at this time.