Skip to content

Instantly share code, notes, and snippets.

View deven96's full-sized avatar
:shipit:
Too much to learn... so little time

Diretnan Domnan deven96

:shipit:
Too much to learn... so little time
View GitHub Profile
@deven96
deven96 / example3.py
Created March 24, 2022 12:26
Using itertools and generators
import itertools
from memory_profiler import profile
@profile
def my_func():
a = [1] * (10 ** 6)
# A generator adds nothing to memory as each index is loaded
# on the fly
b = (2 for _ in range(2 * 10 ** 7))
# we discard the first 199999 from the generator using itertools
@deven96
deven96 / example1.go
Created March 23, 2022 12:40
profile me in golang
package main
import (
"math"
"github.com/pkg/profile"
)
func makeArray(num int, size float64) []int {
arr := make([]int, int(size))
for ind := range arr {
@deven96
deven96 / example2.py
Last active March 24, 2022 11:30
Deleting large array
from memory_profiler import profile
@profile
def my_func():
a = [1] * (10 ** 6)
b = [2] * (2 * 10 ** 7)
c = b[200000]
del b
return a.append(c)
@deven96
deven96 / example1.py
Last active March 23, 2022 12:14
Simple example description
from memory_profiler import profile
@profile
def my_func():
a = [1] * (10 ** 6)
b = [2] * (2 * 10 ** 7)
return a.append(b[200000])
if __name__ == '__main__':
my_func()
@deven96
deven96 / good.Dockerfile
Created August 10, 2021 03:32
A better Dockerfile
# pull official base image
FROM node:13.12.0-alpine
# set working directory to /app
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# copy package files to /app and install
@deven96
deven96 / bad.Dockerfile
Created August 10, 2021 03:27
A bad dockerfile
# pull official base image
FROM node:13.12.0-alpine
# set working directory to /app
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# copy project to /app
@deven96
deven96 / fileHandling.bash
Last active March 19, 2021 18:48
File handling utilities
#!/bin/bash
# replaces the $x variable
# e.g replaceVariable first_locked 7777 ~/.bashrc
# will replace any export first_locked=* with export first_locked=7777 directly in ~/.bashrc
# and then proceed to source the script if it is an rc file
function replaceVariableInFile {
sed -i -e "s/^export\ $1=.*/export\ $1=$2/g" $3
# matches .bashrc and .zshrc files
if [[ "$3" =~ .*"rc" ]]; then
@deven96
deven96 / slackUtility.bash
Created March 19, 2021 12:54
Slack related utilities
#!/bin/bash
# check if slack.sh exists else download it
# using curl
function checkSlackUtilityExists {
if [ -f "./slack.sh" ]; then
chmod +x ./slack.sh
else
echo -e "Downloading slack utility..." &&
curl -o ./slack.sh https://gist.githubusercontent.com/andkirby/67a774513215d7ba06384186dd441d9e/raw/c8a47aec0f08ca6dc64201ba40f09ff8c79f735e/slack.sh -s && chmod +x ./slack.sh &&
@deven96
deven96 / selectRandomExcuse.bash
Last active March 19, 2021 12:47
select a random excuse
#!/bin/bash
# Generate a random number using date
RANDOM=$(date +%s)
EXCUSESARRAY=(
"to visit Nosarobumeh in the hospital"
"for some away screen time"
"as I have a slight headache"
"to take a rest"
"for the next one hour"
"for a bit to run some errands"
@deven96
deven96 / runIfWorkPeriod.bash
Last active March 19, 2021 12:56
Run command only if in work period
#!/bin/bash
# run function passed to this if we are in work period
# e.g runIfWorkPeriod echo "Hello there" will only
# output "Hello there" if currenttime is within work period
function runIfWorkPeriod {
start_time="09:00"
end_time="17:00"
currenttime=$(date +%H:%M)
if [[ "$currenttime" > "$start_time" ]] && [[ "$currenttime" < "$end_time" ]]; then