Skip to content

Instantly share code, notes, and snippets.

View t27's full-sized avatar

Tarang Shah t27

View GitHub Profile
@t27
t27 / linux-oom-killer-fixes.md
Last active November 6, 2024 21:09
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.

@t27
t27 / hide-amazon.com-cart-sidebar.txt
Last active November 3, 2024 11:00
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 / render_json_jupyter_collapsible.py
Last active February 5, 2024 18:40
Render JSON as a collapsible field in jupyter notebooks - Updated - Also includes instructions for interleaving with print statements
## Add this to the first block in your note book
import uuid
from IPython.core.display import display, HTML
import json
class RenderJSON(object):
def __init__(self, json_data):
if isinstance(json_data, dict):
self.json_str = json.dumps(json_data)
@t27
t27 / .zprezto
Last active July 14, 2021 04:13
zprezto backup
#
# Sets Prezto options.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
#
# General
#
@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 / OpenCV-Tesseract.md
Last active March 9, 2021 21:42
Converting OpenCV Mat to Tesseract Compatible formats

I was primarily using the JavaCPP presets for OpenCV(JavaCV) and Tesseract

But I also found some references for C++

Here's what works for C++

#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>    
#include 
@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 / 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