Skip to content

Instantly share code, notes, and snippets.

Avatar

Skanda Kaashyap kaashmonee

View GitHub Profile
@kaashmonee
kaashmonee / create_user.sh
Created Sep 19, 2018
Creates a user on a linux system using the first command line arg, sets a temporary password, and adds them to the root and Docker groups.
View create_user.sh
#!/bin/bash
# Ensure that script is being run as root.
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root!"
exit 1
fi
# Getting username from cmd line
@kaashmonee
kaashmonee / gcd.py
Created Apr 12, 2018
finding gcd with the euclidean algorithm
View gcd.py
def gcd(a, b):
if (a == 1 or b == 1):
return 1
elif (a == 0): return b
elif (b == 0): return a
else:
# print(a, b)
return gcd(b, a % b)
@kaashmonee
kaashmonee / leafofthetreepicoCTF.py
Created Dec 23, 2017
Solution to Leaf of the Tree challenge in PicoCTF. Traverses all directories in path and retrieves flag file.
View leafofthetreepicoCTF.py
# picoCTF leaf of the tree
import os
path = "/problems/5da315e9c7f1c9886ea371abee5ae8d0"
def getPath(path):
if not os.path.isdir(path):
return path
else:
for dir in listdir_fullpath(path):
@kaashmonee
kaashmonee / codecopy.py
Created Dec 17, 2017
Copies and shortens code from one file to another
View codecopy.py
import argparse
def cp(inp, out):
with open(out, "w") as output, open(inp, "r") as inp:
lines = []
for line in inp:
# ignores new lines
if line == "\n":
@kaashmonee
kaashmonee / 3body.py
Last active May 4, 2020
3 body problem simulation in Python
View 3body.py
from visual import *
scene = display(title="Earth's Orbit", width=500, height=500, range=3.e11)
#
scene.autoscale = 0 # Turn off auto scaling of display.
#
# Define the Sun and the Earth objects.
#
sun = sphere(color=color.yellow)
View helloworld.rb
$i = 100
$n = 3
while $n < $i do
puts("inside the loop i = #$n")
$n += 1
end
View is-prime-one-line.py
#checks to see if n is prime in one line
def oneLineIsPrime(n): return False if (n % 2 == 0 and n > 2) or n < 2 or 0 in [n%factor for factor in range(3, round(n ** 0.5))] else True
@kaashmonee
kaashmonee / binary-carry-count.py
Created Oct 16, 2017
Counts the number of times you have to carry when you add 1 to a binary number.
View binary-carry-count.py
def countCarries(number):
number+=1
number = str(number)
number = list(number)
carries = 0
for x in range(len(number)-1, -1, -1):
if int(number[x])==2:
carries+=1
if number[x-1]:
@kaashmonee
kaashmonee / gearing-up-for-destruction.py
Created Jul 11, 2017
Google foobar challenge -- gearing up for destruction recursive implementation
View gearing-up-for-destruction.py
from fractions import Fraction
def answer(pegs):
def find_rn(num):
if num == 1:
return 0
else:
return pegs[num-1]-pegs[num-2]-find_rn(num-1)
ans = find_rn(len(pegs))
if len(pegs)%2 == 0: #if it's even
You can’t perform that action at this time.