Skip to content

Instantly share code, notes, and snippets.

@jet-logic
jet-logic / copy a directory while hardlinking the files in Linux.md
Created September 21, 2025 10:55
Several ways to copy a directory while hardlinking the files in Linux:

Method 1: Using cp with -l flag (simplest)

cp -rl source_directory destination_directory

Method 2: Using rsync (more control)

rsync -a --link-dest=/path/to/source_directory/ source_directory/ destination_directory/
@jet-logic
jet-logic / ren.sh
Created September 11, 2025 14:03
Unix-like equivalent of the classic Windows REN command
#!/bin/sh
# Windows REN equivalent
ren() {
local source="$1"
local target="$2"
# Basic validation
if [ ! -e "$source" ]; then
echo "The system cannot find the file specified: $source" >&2
@jet-logic
jet-logic / mkpsuhd.sh
Last active September 11, 2025 13:57
A Bash function that combines directory creation with directory stack navigation.
#!/bin/bash
mpushd ()
{
local newdir
if [ -d "$1" ]; then
echo "$1 exists..."
newdir="$1"
else
if [ -n "$2" ]; then
@jet-logic
jet-logic / merge uncommitted changes and the last two commits into a single commit.md
Created September 4, 2025 02:45
Here's how to merge uncommitted changes and the last two commits into a single commit

Method 1: Reset Soft + New Commit (Recommended)

# 1. First, stash any uncommitted changes if you have them
git stash

# 2. Reset the last two commits (but keep changes)
git reset --soft HEAD~2

# 3. Apply stashed changes (if any)
git stash pop
@jet-logic
jet-logic / Load a Python script and run a function.md
Created August 30, 2025 13:15
Several ways to load a Python script file and run a named function

Method 1: Using importlib (Recommended)

import importlib.util
import sys

def load_and_run_script(script_path, function_name="render"):
    # Load the module from file path
    spec = importlib.util.spec_from_file_location("custom_module", script_path)
@jet-logic
jet-logic / readme.md
Created June 24, 2025 02:46
Converting Nested Lists to Tuples for Dictionary Keys in Python

Converting Nested Lists to Tuples for Dictionary Keys in Python

To convert a list (which may contain nested lists) into a tuple that can be used as a dictionary key in Python, you need to recursively convert all lists to tuples. Here's how you can do it:

def list_to_tuple(lst):
    """Recursively convert lists to tuples to make them hashable."""
    return tuple(list_to_tuple(x) if isinstance(x, list) else x for x in lst)

# Example usage:

🚀 Joining Dictionaries in Python 3: Different Versions, Different Ways! 🐍

Are you working with dictionaries in Python? Did you know the syntax for merging them has evolved across Python 3 versions? Here’s a quick guide:

Python 3.4 and earlier

Use the update() method or dictionary unpacking inside a new dict:

dict1 = {'a': 1}  
dict2 = {'b': 2}  
merged = dict1.copy() 

Getting the Root Mount Directory of a Path in Bash

To find the root mount directory (the filesystem mount point) for a given path in bash, you can use several methods:

Method 1: Using df command

get_root_mount() {
    local path="$1"
 df --output=target "$path" | tail -n 1

Common Pitfalls in JavaScript

JavaScript is a powerful but quirky language with several pitfalls that can trip up developers, especially those new to the language. Here are some of the most common ones:

1. Type Coercion Gotchas

console.log(1 + "1"); // "11" (string concatenation)
console.log("1" - 1); // 0 (numeric subtraction)
console.log([] == ![]); // true (wat?!)
@jet-logic
jet-logic / tomkv.sh
Created June 8, 2025 17:35
Bash script that converts MP4 files to MKV using stream copy (no re-encoding) with FFmpeg
#!/bin/bash
# Check if input files are provided
if [ $# -eq 0 ]; then
echo "Usage: $0 file1.mp4 [file2.mp4 ...]"
echo "Converts MP4 files to MKV using stream copy (no re-encoding) and deletes original if successful."
exit 1
fi
# Process each file