Skip to content

Instantly share code, notes, and snippets.

View tomislacker's full-sized avatar

Ben Tomasik tomislacker

View GitHub Profile
param (
[ValidateNotNullOrEmpty()]
[string] $ScriptPath,
[ValidateNotNullOrEmpty()]
[string] $TaskName
# Pass in as many arguments as you want....
)
# Setup error handling.
Trap
@tomislacker
tomislacker / download_huzheng.org.sh
Created February 17, 2021 21:20
Quick hack to download and extract all dictionaries from huzheng.org for `sdcv`
#!/bin/bash
set -exo pipefail
HOST=http://download.huzheng.org/dict.org/
if [ -z "$STARDICT_DATA_DIR" ]
then
echo >&2 "Error: STARDICT_DATA_DIR not set!"
exit 1
@tomislacker
tomislacker / stack.yml
Created October 30, 2019 14:48
2019-10-30 Dynamic Reference Test
---
AWSTemplateFormatVersion: 2010-09-09
Description: |
testing dynamic references
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html
Parameters:
AMIParameterName:
#Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
Type: String
@tomislacker
tomislacker / example.yml
Last active September 12, 2019 14:41
CloudFormation - Search & Replace Custom Resource
---
AWSTemplateFormatVersion: 2010-09-09
Description: Testing something
Resources:
R1:
Type: Custom::StringReplacement
Properties:
ServiceToken: !ImportValue cfn-helpers:Replace
Find: '-test'
@tomislacker
tomislacker / rateLimitDecorator.py
Created July 17, 2019 12:51 — forked from gregburek/rateLimitDecorator.py
Rate limiting function calls with Python Decorators
import time
def RateLimited(maxPerSecond):
minInterval = 1.0 / float(maxPerSecond)
def decorate(func):
lastTimeCalled = [0.0]
def rateLimitedFunction(*args,**kargs):
elapsed = time.clock() - lastTimeCalled[0]
leftToWait = minInterval - elapsed
if leftToWait>0:
@tomislacker
tomislacker / output.md
Last active July 15, 2019 13:48
Python Nested Generators with `yield from` Syntax (>=Python.3.3)

TIL about the yield from syntax introduced in >=Python-3.3

In [6]: def f1(p): 
   ...:     yield f'{p}1' 
   ...:     yield f'{p}2' 
   ...:      
   ...:                                                                         

In [7]: def f2(): 
@tomislacker
tomislacker / es_test.py
Last active January 31, 2020 14:16
Test ElasticSearch Connectivity
"""
Simple test for checking if an EC2 instance or ECS task can access an
ElasticSearch domain. This was mainly lifted from the AWS documentation:
https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-request-signing.html#es-request-signing-python
To use this, first the requisite libraries must be available:
$ pip install -U \
boto3 \
elasticsearch \
requests \
@tomislacker
tomislacker / about.md
Last active April 4, 2019 13:59
Python logging Module Not Showing All Levels
  • Inspired by this gist.
  • Supporting documentation
  • I made a new gist because I wanted to have a more complete example that compared what happens without using that solution versus using it.
@tomislacker
tomislacker / aws_route53_delete.sh
Created January 15, 2019 16:32 — forked from earljon/aws_route53_delete.sh
Delete a Route 53 Record Set in AWS CLI
#!/bin/sh
# NOTE:
# Make sure that the value of Name, Type, TTL are the same with your DNS Record Set
HOSTED_ZONE_ID=<YOUR_HOSTED_ZONE_ID>
RESOURCE_VALUE=<YOUR_DNS_RESOURCE_VALUE-ex:IP or dns>
DNS_NAME=<YOUR_DNS_NAME-ex: subdomain.domain.com>
RECORD_TYPE=<DNS_RECORD_TYPE-ex: A, CNAME>
TTL=<TTL_VALUE>
@tomislacker
tomislacker / all_aws_lambda_modules.txt
Created October 22, 2018 18:44 — forked from gene1wood/all_aws_lambda_modules_python.md
AWS Lambda function to list all available Python modules and post the list to Pastebin
# module list (generated by listmodules.py)
#
# timestamp='20160226T200954Z'
# sys.version='2.7.10 (default, Dec 8 2015, 18:25:23) \n[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]'
# sys.platform='linux2'
# platform='Linux-4.1.13-19.31.amzn1.x86_64-x86_64-with-glibc2.2.5'
#
BaseHTTPServer
Bastion
CDROM