Skip to content

Instantly share code, notes, and snippets.

View saratrajput's full-sized avatar

Suraj Pattar saratrajput

View GitHub Profile
@saratrajput
saratrajput / launch_executable_from_anywhere_ubuntu.md
Created March 3, 2023 05:25
Create executable for AppImage or executable to launch from any directory in Ubuntu
  • Move the directory or AppImage to a desired location.
sudo mkdir -p /<example_dir>/
sudo mv <my_executable_dir> /<example_dir>/
  • Create a symlink in a directory which is in the PATH.
sudo ln -s /<example_dir>/<my_example_dir>/<executable> /usr/local/bin/<executable_name>
@saratrajput
saratrajput / check_gpu_availability.py
Created March 3, 2023 05:23
Small script to check the availability of GPU
import subprocess
def check_gpu_availability(threshold=50):
# Run the nvidia-smi command to get GPU information
cmd = "nvidia-smi --query-gpu=index,memory.used,memory.total --format=csv,noheader"
gpu_info = subprocess.check_output(cmd, shell=True).decode().strip().split("\n")
# Parse the GPU information into a list of dictionaries
gpu_list = []
for gpu in gpu_info:
@saratrajput
saratrajput / opencv_code_snippets.py
Created September 7, 2022 00:28
OpenCV Code Snippets
import cv2
import numpy as np
import matplotlib.pyplot as plt
# To add a colored mask over a image
def add_colored_mask(image, mask):
color = (0, 0, 255) # Red.
image_colored = np.zeros(image.shape, image.dtype)
image_colored[:,:] = color
@saratrajput
saratrajput / automatic_print_removal_instruction.md
Created August 4, 2022 23:45
Automatic Print Removal GCODES

Automatic Print Removal GCODES

These instructions are to remove the printed at the end of the print. The printed model is assumed to be placed at the center of the platform. Printer: Anycubic Mega.

  • Original End Code
M104 S0 ; turn off extruder
M140 S0 ; turn off bed
M84 ; disable motors
M107
@saratrajput
saratrajput / instructions_to_activate_opencv_cpp_intellisense.md
Created August 2, 2022 07:17
OpenCV C++ Intellisense for VSCode on Ubuntu 20
  • First locate OpenCV files on your machine.

If locate is not installed, install it with: sudo apt install mlocate. You might get results like:

locate opencv.hpp                                                                                                                                                                             (py37_test) 
/usr/include/boost/compute/interop/opencv.hpp
/usr/include/opencv4/opencv2/opencv.hpp
  • In VSCode, Press Ctrl+Shift+P.
# Single underscore
class Example():
_private_variable = 10
def __init__(self):
self._private_variable = 20
example_object = Example()
print(example_object._private_variable)
# Double underscores
"""
Module Docstring.
author:name
date:date
"""
import argparse
import logging
@saratrajput
saratrajput / mujoco_py_install_instructions.md
Created January 27, 2022 08:26
Mujoco and Mujoco-py Installation Instructions

Mujoco and Mujoco-py Installation Instructions

The steps are taken from this video and document with some small changes.

Steps

  1. Install Anaconda. Download it from this link.
cd Downloads/
sudo chmod +x Anaconda3-2021.11-Linux-x86_64.sh
./Anaconda3-2021.11-Linux-x86_64.sh