Skip to content

Instantly share code, notes, and snippets.

View t27's full-sized avatar

Tarang Shah t27

View GitHub Profile
@t27
t27 / aws_terminator.py
Created May 6, 2021 04:01
Regularly Terminate AWS instances that are idle(<5% CPU Utilization) for the past 10 minutes
import json
import subprocess
import pendulum # pip install pendulum
# Note: This is a hacky, quick solution prototyped in less than an hour, the ideal solution would involve using boto3 and other best practices auth
# ensure that your AWS CLI is configured and has the keys and default region set up. This script works in the default region
instance_cmd = """
aws ec2 describe-instances \
@t27
t27 / videos_on_exported_notionhtml.txt
Created April 14, 2021 02:51
Videos on HTML export not properly exported fix : Notion (from Reddit)
Thanks to u/IAmBeardPerson on https://www.reddit.com/r/Notion/comments/elh20k/videos_on_html_export_not_properly_exported_fix/
<script>
var videos = document.getElementsByClassName("source");
for (var i = 0; i < videos.length; i++) {
var source = videos[i].getElementsByTagName("a");
if (source[0].href.includes("youtube")) {
var videoObject = document.createElement('iframe');
videoObject.src = source[0].href.replace("watch?v=", "embed/");
videos[i].style.padding = "0";
@t27
t27 / command.txt
Created December 14, 2020 08:23
Batch FFMpeg command for windows cmd
for /f "tokens=1 delims=." %a in ('dir /B *.webm') do ffmpeg -i "%a.webm" -c:v copy -crf 0 "%a.mp4"
# here "ffmpeg -i "%a.webm" -c:v copy -crf 0 "%a.mp4" is the command to repeat
@t27
t27 / bouncingball.js
Created November 24, 2020 02:19
p5 js Bouncing ball with squash and stretch for Graphics animation assignment
// Code for a bouncing ball animation in p5 Js
function setup() {
createCanvas(400, 400);
// frameRate(12)
}
u = 0
x = 200
y = 100
y_top = 100
last_ch = 60
@t27
t27 / hide-amazon.com-cart-sidebar.txt
Last active April 28, 2023 20:15
Ublock Origin rules to hide the Amazon.com Cart sidebar that can't be hidden via any setting/config on the website
! Ublock Origin rules to hide the Amazon.com Cart sidebar that can't be officially hidden
! hide the sidebar
www.amazon.com###nav-flyout-ewc
www.amazon.com###nav-flyout-anchor
! ensure the rest of the site covers full width
www.amazon.com##body:style(padding-right: 0px !important)
@t27
t27 / create_jupyter_kernel.sh
Created September 12, 2020 05:42
Create a Jupyter kernel from inside a Python environment
# ensure you have activated the environment
python -m ipykernel install --user --name my_env --display-name "Python (my_env)"
# this will create a Jupyter kernel called my_env that will use the python binary and the packages from the current project
@t27
t27 / idx_to_one_hot.py
Created April 23, 2020 21:31
A simple way to convert a list of indices to a one-hot encoded vector using numpy
import numpy as np
q_word_idx = [1,2,4,7,6,2]
a_idx = [1,1,5,6,4,2]
q_word_idx = np.array(q_word_idx)
a_idx = np.array(a_idx)
q_vector_size = 8
a_vector_size = 8
# Got this from https://linuxhint.com/crop_videos_linux/
ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
# Where:
# “in.mp4” refers to the input file to be converted
# “out.mp4” is the name of the output file to be saved after conversion
# out_w is the width of your desired output rectangle to which the original video’s width will be reduced
# out_h is the height of your output rectangle to which the original video’s height will be reduced
# x and y are the position coordinates for the top left corner of your desired output rectangle
@t27
t27 / vidToImg.sh
Created March 26, 2020 06:18
Convert Video to Images using FFMPEG
# https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
ffmpeg -i input.flv -vf fps=1 out%d.png
# fps is number of images per second
@t27
t27 / linux-oom-killer-fixes.md
Last active June 14, 2024 12:39
Dealing with the Linux OOM Killer

Dealing with the Linux OOM Killer at the program level

Do this in cases when you dont want to change the os-level settings, but only want to disable the OOM killer for a single process. This is useful when youre on a shared machine/server.

The OOM killer uses the process level metric called oom_score_adj to decide if/when to kill a process. This file is present in /proc/$pid/oom_score_adj. The oom_score_adj can vary from -1000 to 1000, by default it is 0.

You can add a large negative score to this file to reduce the probability of your process getting picked and terminated by OOM killer. When you set it to -1000, it can use 100% memory and still avoid getting terminated by OOM killer.