Skip to content

Instantly share code, notes, and snippets.

Otto Kruse ottokruse

  • AWS
Block or report user

Report or block ottokruse

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ottokruse / index.ts
Last active Aug 23, 2019
NodeJs crypto secure random choice from string or Array
View index.ts
import { randomBytes } from 'crypto';
let bitsNeeded: number, bytesNeeded: number, chunks: number, tooBig: number, randomNumber: number, index: number;
export function randomChoiceFromIndexable(indexable: string | any[]) {
bitsNeeded = Math.log2(indexable.length);
bytesNeeded = Math.ceil(bitsNeeded / 8);
chunks = Math.floor(256 / indexable.length) || 1;
tooBig = indexable.length * chunks;
do {
randomNumber = randomBytes(bytesNeeded).readUIntBE(0, bytesNeeded);
ottokruse /
Last active Apr 18, 2019
SQS worker written in Bash
log() {
echo $(date -u +"%Y-%m-%dT%H:%M:%SZ") $@ # >> output.log
convert_single () {
cd /mnt/
time wine /home/ubuntu/bin/Dat2Cvw_1.4.7.1.A/DAT2CVW.exe -i $FULL_PATH >/dev/null 2>&1
ottokruse / lambda-execute-appsync-mutation.js
Last active Jul 23, 2019
Example AWS Lambda function that executes AWS AppSync GraphQL Mutation using AWS Amplify
View lambda-execute-appsync-mutation.js
const Amplify = require('aws-amplify');
aws_appsync_graphqlEndpoint: '',
aws_appsync_region: 'eu-west-1',
aws_appsync_authenticationType: 'API_KEY',
aws_appsync_apiKey: 'yourkey'
const mutation = `mutation CreatePerson($firstName: String!, $lastName: String!, bankAccountBalance: Float!) {
You can’t perform that action at this time.