Skip to content

Instantly share code, notes, and snippets.

View christianklotz's full-sized avatar

Christian Klotz christianklotz

View GitHub Profile
@christianklotz
christianklotz / sketch-comic-assistant.ts
Last active July 21, 2020 16:29
Create Sketch Assistant writing a custom rule
/**
Simple Assistant setting exactly one rule that ensures text layers are only using
specific fonts, in this case set to Comic Sans and Cochin.
1. Use Assistant Template from https://github.com/sketch-hq/sketch-assistant-template/
2. Find and replace all `sketch-assistant-template` with `sketch-comic-assistant`
3. Install dependencies
npm install
@christianklotz
christianklotz / sketch-organisation-assistant.ts
Created July 21, 2020 16:00
Create Sketch Assistant using existing rules
/**
Simple Assistant setting exactly one rule, limiting the number of layers that should be
allowed per group. The rule is provided by the Sketch Core Assistant.
1. Use Assistant Template from https://github.com/sketch-hq/sketch-assistant-template/
2. Find and replace all `sketch-assistant-template` with `sketch-organisation-assistant`
3. Install dependencies and add Core Assistant
npm install
@christianklotz
christianklotz / sketch-load-json.js
Created March 19, 2019 15:59
Load JSON file into Sketch
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 July 18, 2018 19:04
AWS CloudFormation resource name character limit

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 June 19, 2018 17:30
CloudFormation template to create S3 bucket resource with custom role
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 June 19, 2018 17:16
Google Cloud Deployment Manager template creating bucket with custom service account
resources:
# Bucket to hold all asset
- name: {{ properties['bucket-prefix'] }}-assets
type: storage.v1.bucket
accessControl:
gcpIamPolicy:
bindings:
- role: roles/storage.objectAdmin
members:
package main
import (
"fmt"
"math/rand"
"time"
)
func generate(nums ...int) chan int {
out := make(chan int)

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 12:06
Circle CI configuration with deployment stages
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 October 17, 2016 09:31
Create Python app package for Amazon AWS Lambda including Google's ortools dependencies
#!/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;