Skip to content

Instantly share code, notes, and snippets.

View tonythomas01's full-sized avatar
🏠
Working from home

Tony Thomas tonythomas01

🏠
Working from home
View GitHub Profile
@tonythomas01
tonythomas01 / two_eggs_problem.py
Created May 27, 2020 14:37
Two eggs problem, find the total tries to get to how many drops needs to be executed.
"""
Some solution to the 2 eggs problem. Given N floors, you find the first
floor and find how many steps you have to go up.
"""
import math
def find_roots_of_quadratic_equation(a, b, c):
"""
(-b +_ sqrt(b2 - 4ac))/2a
@tonythomas01
tonythomas01 / testCasesWithLimits.js
Last active May 25, 2020 09:46
[Node.js] Kattis read test cases with limits
// Assume you have to read something like:
// 3 - number of test cases that follow
// 3 - limit in this test case.
// 1 2 3 - test case data
// 4
// 1 2 3 4
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
@tonythomas01
tonythomas01 / notify_telegram_bot_ip.sh
Last active January 22, 2024 08:23
Bash script to post to Telegram bot when your machine IP address change #telegram #ip #bot
#!/usr/bin/env bash
# Script stores the current IP in a tmp file and later checks if it changed when run. POSTS to a Telegram bot.
# Check how you can create a bot at https://core.telegram.org/bots
old_ip=`cat /tmp/currentip`
current_ip=`wget -qO- https://ipecho.net/plain`
if [ $current_ip != $old_ip ]; then
curl -s -X POST https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/sendMessage -d chat_id=<CHAT_ID> -d text="Machine changed IP from: ${old_ip} to ${current_ip}"
@tonythomas01
tonythomas01 / switch_to_branch.sh
Created May 21, 2019 08:32
Update all repos in your directory to a branch.
#!/usr/bin/env bash
# This will update all git repos in your present working directory to target: branch
# Inspired from: https://stackoverflow.com/a/31994428
read -p 'Branch to switch to: ' branch
for d in */; do cd $d; git stash; git checkout $branch; (git pull origin $branch); cd ..; done
@tonythomas01
tonythomas01 / gitcheats.txt
Created November 4, 2018 14:03 — forked from mkhairi/gitcheats.txt
git cheats
# shortform git commands
alias g='git'
# push changes to an empty git repository for the first time
git push --set-upstream origin master
# Remove + and - from start of diff lines
git diff --color | sed "s/^\([^-+ ]*\)[-+ ]/\\1/" | less -r
# clear out git hooks
@tonythomas01
tonythomas01 / get_node_ip.py
Last active July 11, 2018 08:29
[OpenStack] Fetch IPv4 address of a new VM through OpenStack-Python API
from openstack import connection
conn = connection.Connection(
auth_url=configs['auth']['OS_AUTH_URL'],
project_name=configs['auth']['OS_PROJECT_NAME'],
username=configs['auth']['OS_USERNAME'],
password=configs['auth']['OS_PASSWORD'],
project_domain_name=configs['auth']['OS_PROJECT_DOMAIN_NAME'],
user_domain_name=configs['auth']['OS_USER_DOMAIN_NAME']
)
[
{
"username":"test",
"pass":"testpass"
},
{
"username":"admin",
"pass": "adminpass"
},
]