Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
Too much to learn... so little time

Deven96 deven96

:shipit:
Too much to learn... so little time
View GitHub Profile
@deven96
deven96 / good.Dockerfile
Created Aug 10, 2021
A better Dockerfile
View good.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
View 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 Mar 19, 2021
File handling utilities
View fileHandling.bash
#!/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 Mar 19, 2021
Slack related utilities
View slackUtility.bash
#!/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 Mar 19, 2021
select a random excuse
View selectRandomExcuse.bash
#!/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 Mar 19, 2021
Run command only if in work period
View runIfWorkPeriod.bash
#!/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
@deven96
deven96 / screenActiveMac.bash
Last active Mar 19, 2021
Checking screen is active on Mac
View screenActiveMac.bash
#!/bin/bash
# $screenActive=1 means the screen is active and O is inactive
# View the explanation of the CGSession dictionary at
# https://stackoverflow.com/questions/11505255/osx-check-if-the-screen-is-locked
function checkScreenActiveMac {
python -c 'import sys,Quartz;\
d=Quartz.CGSessionCopyCurrentDictionary();\
sys.exit(d and \
d.get("CGSSessionScreenIsLocked", 0) == 0 and \
View checkOS.bash
#!/bin/bash
function checkOS {
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
*) echo "Cannot run on unsupported machine ${unameOut}" && exit 1;
esac
@deven96
deven96 / addOneHour.bash
Last active Mar 19, 2021
Excuses with Bash
View addOneHour.bash
#!/bin/bash
function checkOS {
...
}
function addOneHourLinux {
date -d '+1 hour'
}
@deven96
deven96 / check_convex.py
Created Dec 23, 2019 — forked from mblondel/check_convex.py
A small script to get numerical evidence that a function is convex
View check_convex.py
# Authors: Mathieu Blondel, Vlad Niculae
# License: BSD 3 clause
import numpy as np
def _gen_pairs(gen, max_iter, max_inner, random_state, verbose):
rng = np.random.RandomState(random_state)
# if tuple, interpret as randn