Skip to content

Instantly share code, notes, and snippets.

@sgouda0412
sgouda0412 / debugging_decorators.py
Created October 22, 2025 05:03 — forked from chadgh/debugging_decorators.py
python decorators for; debugging, threading
def timeit(function):
'''Decorator used for debugging. Prints the call and how long it took.'''
def timed(*args, **kwargs):
ts = time.time()
result = function(*args, **kwargs)
te = time.time()
print("{0} ({1}, {2}) {3:.2} sec"
.format(function.__name__, args, kwargs, te - ts))
@sgouda0412
sgouda0412 / regex-demo.py
Created October 22, 2025 05:00 — forked from ChillarAnand/regex-demo.py
BangPypers talk - Using Regular Expressions by Arvind Padmanabhan
import re
print(re.match(r'bc', 'abc'))
print(re.match(r'abc', 'abc'))
print(re.search(r'bc', 'abc'))
print(re.search(r'^bc', 'abc'))
print(re.search(r'^ab$', 'abc'))
print(re.search(r'^abc$', 'abc'))
print(re.search(r'a?bc', 'bc'))
print(re.search(r'a?bc', 'abc'))
print(re.search(r'a?bc', 'aabc'))
@sgouda0412
sgouda0412 / retry.sh
Created October 22, 2025 04:20 — forked from holysky5/retry.sh
#!/bin/bash
# Retries a command on failure.
# $1 - the max number of attempts
# $2... - the command to run
retry() {
local -r -i max_attempts="$1"; shift
local -r cmd="$@"
local -i attempt_num=1
@sgouda0412
sgouda0412 / python_exceptions.py
Created October 22, 2025 04:20 — forked from TanAlex/python_exceptions.py
[python exception]Python exceptions gists #exception
# https://github.com/kennethreitz/requests/blob/master/requests/exceptions.py
class RequestException(IOError):
"""There was an ambiguous exception that occurred while handling your
request.
"""
def __init__(self, *args, **kwargs):
"""Initialize RequestException with `request` and `response` objects."""
response = kwargs.pop('response', None)
self.response = response
@sgouda0412
sgouda0412 / bash_aws_jq_cheatsheet.sh
Created October 22, 2025 04:19 — forked from TanAlex/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
@sgouda0412
sgouda0412 / cheatsheet-git.sh
Created October 22, 2025 04:19 — forked from TanAlex/cheatsheet-git.sh
Cheatsheet: git commands
# adding and committing
git add -A # stages All
git add . # stages new and modified, without deleted
git add -u # stages modified and deleted, without new
git commit --amend # Add staged changes to previous commit. Do not use if commit has been pushed.
git commit --amend --no-edit # Do so without having to edit the commit message.
# remotes - pushing, pulling, and tracking
git fetch # gets remote objects and refs. Needed if new branches were added on the remote.
git remote -v # Lists all remotes (verbose)
@sgouda0412
sgouda0412 / python.py
Created October 22, 2025 04:02 — forked from nicklasos/python.py
python
# Full path to file
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'backups', 'file.zip')
def full_path(*args):
""" full_path('dir', 'folder', 'file.txt') """
return os.path.join(os.path.dirname(os.path.realpath(__file__)), *args)
def full_path(filepath, *args):
@sgouda0412
sgouda0412 / Python - Fundamentals.py
Created October 22, 2025 04:02 — forked from duonghominhhuy/Python - Fundamentals.py
[Python - Fundamentals] Python Basic Notes & Syntax #python #basic
/*
1. Using unicode symbol in string characters
Use “\u” followed by the hexadecimal (base 16) code for the character in the Unicode tables.
Unicode tables: http://www.unicode.org/charts/
2. You can get the number corresponding to any character by using the ord() function and you can get the character corresponding to any number with the chr() function.
>>> '\u011f' -> 'ğ' // 16-bit hex ('\uxxxx')
>>> "\U00016FE1" -> '𖿡' // 32-bit hex ('\Uxxxxxxxx')
>>> ord('ğ') -> 287
>>> chr(287) -> 'ğ'