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 / 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 / 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 / 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 / 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 / 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 / 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