Skip to content

Instantly share code, notes, and snippets.

View martinzuern's full-sized avatar

Martin Zürn martinzuern

  • GEMA
  • Munich
View GitHub Profile
@martinzuern
martinzuern / useStateWithLocalStorage.ts
Last active May 14, 2020 21:30
React useState paired with Window.localStorage
import React, { Dispatch, SetStateAction } from 'react';
import Log from './Log';
const isPlainObject = (obj: any) => Object.prototype.toString.call(obj) === '[object Object]';
const keyStr = (obj: any) => Object.keys(obj).sort().toString();
export function useStateWithLocalStorage<S = undefined>(
localStorageKey: string,
initialState: S | (() => S)
): [S, Dispatch<SetStateAction<S>>] {
@martinzuern
martinzuern / big_json.json
Last active August 18, 2017 16:40
Load_Test
This file has been truncated, but you can view the full file.
[{"DATA_INDEX":0,"ACCTOUNT_NUMBER":"1234567890","CUSTOMER_NAME":"ACME Products and Services, Inc.","ADDRESS":"123 Main Street","CITY":"Albuquerque","STATE":"NM","ZIP":"87101-1234"},{"DATA_INDEX":1,"ACCTOUNT_NUMBER":"1234567890","CUSTOMER_NAME":"ACME Products and Services, Inc.","ADDRESS":"123 Main Street","CITY":"Albuquerque","STATE":"NM","ZIP":"87101-1234"},{"DATA_INDEX":2,"ACCTOUNT_NUMBER":"1234567890","CUSTOMER_NAME":"ACME Products and Services, Inc.","ADDRESS":"123 Main Street","CITY":"Albuquerque","STATE":"NM","ZIP":"87101-1234"},{"DATA_INDEX":3,"ACCTOUNT_NUMBER":"1234567890","CUSTOMER_NAME":"ACME Products and Services, Inc.","ADDRESS":"123 Main Street","CITY":"Albuquerque","STATE":"NM","ZIP":"87101-1234"},{"DATA_INDEX":4,"ACCTOUNT_NUMBER":"1234567890","CUSTOMER_NAME":"ACME Products and Services, Inc.","ADDRESS":"123 Main Street","CITY":"Albuquerque","STATE":"NM","ZIP":"87101-1234"},{"DATA_INDEX":5,"ACCTOUNT_NUMBER":"1234567890","CUSTOMER_NAME":"ACME Products and Services, Inc.","ADDRESS":"123 Main Stree
@martinzuern
martinzuern / Test.json
Created August 10, 2017 08:28
API Test
{
"page": 1,
"per_page": 3,
"total": 12,
"total_pages": 4,
"data": [{
"id": 1,
"first_name": "george",
"last_name": "bluth",
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg"

Keybase proof

I hereby claim:

  • I am martinzuern on github.
  • I am martinzuern (https://keybase.io/martinzuern) on keybase.
  • I have a public key ASC0c0x2BnMUy6HCcK-iXYw9szHeUa9iAV5GDQMlnEWdpwo

To claim this, I am signing this object:

@martinzuern
martinzuern / UserData script for setup CloudWatch
Last active February 2, 2022 12:06 — forked from yuta-imai/UserData script for setup CloudWatch
With this user data script, you can set up cron job to put some custom metrics for CloudWatch at instance initiation.
#!/bin/sh
yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA unzip
cd /home/ec2-user
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm -rf CloudWatchMonitoringScripts-1.2.1.zip
chown ec2-user:ec2-user aws-scripts-mon
echo "* * * * * ec2-user /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --swap-util --aggregated --auto-scaling --from-cron" >> /var/spool/cron/ec2-user
echo "0 * * * * ec2-user /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --disk-space-used --disk-space-avail --disk-space-util --disk-path=/ --aggregated --auto-scaling --from-cron" >> /var/spool/cron/ec2-user
@martinzuern
martinzuern / backup-mongodb-to-s3.sh
Created April 5, 2017 15:26 — forked from caraboides/backup-mongodb-to-s3.sh
Simple script to backup MongoDB to S3, without waste diskspace for temp files. And a way to restore from the latest snapshot.
#!/bin/sh
set -e
HOST=localhost
DB=test-entd-products
COL=asimproducts
S3PATH="s3://mongodb-backups-test1-entd/$DB/$COL/"
S3BACKUP=$S3PATH`date +"%Y%m%d_%H%M%S"`.dump.gz
S3LATEST=$S3PATH"latest".dump.gz
/usr/bin/aws s3 mb $S3PATH