Skip to content

Instantly share code, notes, and snippets.

View luckylittle's full-sized avatar
:octocat:
Working for @RedHatOfficial

Lucian Maly luckylittle

:octocat:
Working for @RedHatOfficial
View GitHub Profile
@luckylittle
luckylittle / cloudformation-yaml-to-json.py
Created October 26, 2017 09:15 — forked from kesor/cloudformation-yaml-to-json.py
Convert CloudFormation YAML format to JSON format
#!/usr/bin/env python
import sys, yaml, json
def funcparse(loader, node):
node.value = {
yaml.constructor.ScalarNode: loader.construct_scalar,
yaml.constructor.SequenceNode: loader.construct_sequence,
yaml.constructor.MappingNode: loader.construct_mapping,
}[type(node)](node)
node.tag = node.tag.replace(u'!Ref', 'Ref').replace(u'!', u'Fn::')
@luckylittle
luckylittle / converter.py
Created October 26, 2017 09:17 — forked from kj187/converter.py
Converting a CloudFormation Template from JSON to YAML
#!/usr/bin/env python
## Converting a CloudFormation Template from JSON to YAML
## Script copyright: http://blog.flux7.com/how-to-convert-a-cloudformation-template-from-json-to-yaml
##
## Example:
## $ python converter.py --json my-stack.template --yaml my-stack.yaml
import yaml
import json
@luckylittle
luckylittle / delete_default_vpcs.py
Created January 3, 2018 23:56
Delete Default VPCs in AWS account
#!/usr/bin/env python
#
# Python Version: 2.7
# Boto Version 2.38
#
# Remove those pesky default VPCs
#
# Warning: Deleting the default VPC is a permanent action.
# You must contact AWS Support if you want to create a new default VPC.
#
@luckylittle
luckylittle / gist:27b9b36ea7f5c362a925d8f7b649659d
Created January 11, 2018 06:22
AWS CLI CloudFormation inject AMI ID to the Parameters file
# 1. Find the latest ID of the AMI:
NEW_AMI_ID=$(aws ec2 describe-images \
--filters Name=name,Values=*WHATEVER AMI NAME YOU ARE LOOKING FOR* \
--query 'Images[*].[ImageId,CreationDate]' \
--output text | sort -k2 -r | head -n1 | awk {'print $1'})
# 2. Modify a PARAMETERS.vars.json that is being used by AWS CLI in step 3.:
tmp=$(mktemp)
jq -r '[ .[] | select(.ParameterKey=="AmiId").ParameterValue |= '\"$NEW_AMI_ID\"' ]' \
PARAMETERS.vars.json > "$tmp" && mv "$tmp" PARAMETERS.vars.json
@luckylittle
luckylittle / safari2go.sh
Last active April 28, 2018 02:41
Epub extractor for Android application "Safari To Go" data files
#!/bin/bash
bookid=$(find . -maxdepth 1 -regextype sed -regex ".*/[0-9]\+" | tr -d './')
echo "Fix the font's URL of ${bookid}..."
sed -i -e 's#\/getfile#http:\/\/my.safaribooksonline.com\/getfile#g' publisher-style.css
echo "Download the fonts for ${bookid}..."
mkdir -p fonts
mkdir -p css
@luckylittle
luckylittle / unrar-incl-subfolders.sh
Created May 4, 2018 23:09
Recursively, UnRar all files
#!/bin/bash
# UNRAR 5.00 freeware https://www.rarlab.com/rar/unrar-5.0-RHEL5x64.tar.gz
find . -name '*.rar' -type f -execdir unrar e -o- {} \;
@luckylittle
luckylittle / insertion_sort.py
Last active May 12, 2018 09:55
Insertion sort algorithm in Python
def insertion_sort(list):
"""
Insertion sort algorithm by @luckylittle
"""
for i in range(1, len(list)):
current = list[i]
while (i > 0) and (list[i-1] > current):
list[i] = list[i - 1]
i -= 1
@luckylittle
luckylittle / irssi.service
Created October 9, 2018 23:35
SystemD IRSSI service inside GNU screen (/etc/systemd/system/irssi.service)
[Unit]
Description=IRSSI service
[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/screen -S irssi -dm irssi
ExecStop=/usr/bin/screen -S irssi -X quit
User=lmaly
[Install]
@luckylittle
luckylittle / proftpd.conf
Last active October 10, 2018 10:58
ProFTPd Configuration file (/etc/proftpd.conf)
ServerName "ProFTPD server"
ServerIdent on "FTP Server ready."
ServerAdmin root@localhost
DefaultServer on
DefaultRoot ~/Downloads
PassivePorts 49181 49189
Port 54320
DefaultAddress 0.0.0.0
AuthPAMConfig proftpd
AuthOrder mod_auth_pam.c* mod_auth_unix.c
@luckylittle
luckylittle / gist:5c38579f1ce23ca2ffe811b396e510be
Created October 11, 2018 04:51
Permanently disable automatic comment insertion in vim
echo '" Disable automatic comment insertion\nautocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o' | sudo tee --append /etc/vimrc