Skip to content

Instantly share code, notes, and snippets.

@Kaundur
Kaundur / aws_sms_notification.py
Last active January 26, 2021 12:12
Example script for the generation for AWS SMS notifications
import boto3
# Generated through IAM
aws_access_key_id = ''
aws_secret_access_key = ''
region_name = 'us-west-2'
sns = boto3.client('sns', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=region_name)
# Number including region code e.g. +44 for UK numbers
@Kaundur
Kaundur / decorator_with_function_registration.py
Created March 5, 2020 12:17
Python decorator with function registration
def make_registrar():
registry = {}
def registrar(func):
registry[func.__name__] = func
def wrapper(*args, **kwargs):
# Note - Modify function here
return func(*args, **kwargs)
return wrapper
@Kaundur
Kaundur / unitySimpleCrosshair.cs
Created June 11, 2018 15:00
Unity Simple Crosshair
void OnGUI()
{
const int crossHairWidth = 10;
const int crossHairHeight = 10;
GUI.Box(new Rect(Screen.width/2 - crossHairWidth/2, Screen.height/2 - crossHairHeight/2, crossHairWidth, crossHairHeight), "");
}
@Kaundur
Kaundur / Monty_Hall_problem.py
Created September 13, 2017 07:25
Simple simulation of the Monty Hall problem
import random
switch_choice = 0
stay_choice = 0
samples = 100000
for i in range(samples):
selected_door = random.randint(0, 2)
correct_door = random.randint(0, 2)
if selected_door == correct_door:
@Kaundur
Kaundur / openpyxl_simple_read.py
Created September 4, 2017 07:53
Simple read of an xlsx file using openpyxl
from openpyxl import load_workbook
workbook = load_workbook('data.xlsx')
sheets = workbook.get_sheet_names()
# Read first sheet
worksheet = workbook.get_sheet_by_name(sheets[0])
for row in worksheet.iter_rows():
for cell in row:
# Print out all values that belong to the cell object
@Kaundur
Kaundur / canvasDownload.js
Created June 8, 2017 07:25
JS to automatically download canvas as a png
// This code will automatically save the current canvas as a .png file.
// Its useful as it can be placed in a loop to grab multiple canvas frames, I use it to create thumbnail gifs for my blog
// Only seems to work with Chrome
// Get the canvas
var canvas = document.getElementById("canvas");
// Convert the canvas to data
var image = canvas.toDataURL();
// Create a link
var aDownloadLink = document.createElement('a');
@Kaundur
Kaundur / pi_monte_carlo.py
Last active June 9, 2017 06:57
Monte Carlo estimation of pi
import math
import random
count = 0
n = 100000
for i in range(n):
x_pos = random.uniform(0, 1)
y_pos = random.uniform(0, 1)
if x_pos**2 + y_pos**2 <= 1.0: