Skip to content

Instantly share code, notes, and snippets.

View davidkarim's full-sized avatar

David Karim davidkarim

View GitHub Profile
@davidkarim
davidkarim / gist:ac9dc6906ac918dc43d27bf070f1247d
Created March 28, 2024 20:58
Show all EC2 instance ids, state, and tags (key = Name)
aws ec2 describe-instances --region us-east-1 | jq -r '.Reservations[].Instances[] | .InstanceId + " " + .State.Name + " " + .PublicIpAddress + " " + .Placement.AvailabilityZone + " " + .KeyName + " " + (.Tags[] | select(.Key == "Name") | .Value)'
@davidkarim
davidkarim / check_versions.sh
Created November 28, 2023 19:27
Iterate through subdirectories checking terraform versions
#!/bin/bash
# Function to compare version numbers
version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
# Check if the current directory is a git repository
if git rev-parse --git-dir > /dev/null 2>&1; then
echo "Current directory is a git repository."
# Find all subdirectories
for dir in */ ; do
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x389E80",false],"id":1}' -H "Content-Type: application/json" http://localhost:8545
{"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":"0x73","difficulty":"0x0","extraData":"0x","gasLimit":"0x17d7840","gasUsed":"0x167820","hash":"0x6b46b1ada3465df628b382b74c22295eeb069ae5d7d5fed2297f1f44285f4ce6","logsBloom":"0x00040000200000000000080080000000000000042000000000002008100103800000000000000000000000000820004400000000000020000000100000200000000000402028000002010008060002000080040000040000020000000000000000040000020000028000004000000a100400100000084100000000100000001000000100004000000000000800000000000000000040044800000000204000000a0080000000400000000000000004000014008000000000000008000040000000200002200010010200000000020000004000000000101200005000000060000010200000000000080000000000000000010000000040000000800000000000","miner":"0x4200000000000000000000000000000000000011","mixHash":"0x3b1033a5d1e576afca1eee93524532756390dd41954cb3f746

Guessing game

Ask the gamer his name (store it in a varialbe).

The program needs to generate a random number between 1 and 20.

Ask the user to guess the number (user their name whenever you ask something; like: ok David, guess a number)

After each guess, say if the answer is higher or lower than what they guessed.

@davidkarim
davidkarim / README.md
Last active February 24, 2022 14:46
reverse_shell.py

Reverse Shell on Raspberry Pi

Place the reverse_shell.py script in /home/pi/

Got to /etc/systemd/system and place the reverse_shell.service file there.

# Start the service
systemctl start reverse_shell.service
# Enalbe the service, to make sure it restarts when rebooting
@davidkarim
davidkarim / README.txt
Created December 6, 2021 05:47
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
REMIX EXAMPLE PROJECT
Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer.
It contains 3 directories:
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name.
2. 'scripts': Holds two scripts to deploy a contract. It is explained below.
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity.
SCRIPTS
array=("167.71.98.4" "159.89.41.47" "157.245.10.243" "64.225.3.62" "167.172.17.254")
#array=("159.89.41.47" "157.245.10.243")
username='test'
for i in ${array[@]}
do
echo $i
ssh -i ./ssh root@$i "adduser --disabled-password --gecos \"\" $username"
ssh -i ./ssh root@$i "mkdir /home/$username/.ssh"
scp -i ./ssh ./authorized_keys root@$i:/home/$username/.ssh/authorized_keys
done
@davidkarim
davidkarim / Dockerfile
Created March 7, 2020 05:30
ssh-proxy on kubernetes
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN chmod 0755 /var/run/sshd
COPY startup.sh /startup.sh
CMD /startup.sh
### Keybase proof
I hereby claim:
* I am davidkarim on github.
* I am davidkarim (https://keybase.io/davidkarim) on keybase.
* I have a public key ASAIKuJMocub512vJJZ-KNTufkHm200JPyxVH3TRdmYaJgo
To claim this, I am signing this object:
@davidkarim
davidkarim / bashvars.sh
Last active November 6, 2019 15:13
Example bash script of passing arguments
# create bashvars.sh, chmod +x bashvars.sh
# call it with one or two arguments (i.e. ./bashvars.sh hi dude)
echo "The value you passed was $1"
if [ $1 = "hi" ]
then
echo "Hi !"
elif [ $1 = "bye" ]
then
echo "Goodbye !"
fi