Skip to content

Instantly share code, notes, and snippets.

@kenilt
kenilt / restore_config.sh
Created July 30, 2025 14:34
Restore key dotfiles (.zshrc, .gitconfig, .vimrc, etc.), the ~/.config/ directory, and ~/.zsh and ~/.ssh folders
#!/bin/bash
# Set backup directory
BACKUP_DIR="$(pwd)/Backup"
SSH_BACKUP_DIR="$BACKUP_DIR/ssh"
CONFIG_BACKUP_DIR="$BACKUP_DIR/config"
ZSH_BACKUP_DIR="$BACKUP_DIR/zsh"
echo "🔄 Starting restore..."
@kenilt
kenilt / backup_config.sh
Created July 30, 2025 14:33
Backup key dotfiles (.zshrc, .gitconfig, .vimrc, etc.), the ~/.config/ directory, and my ~/.zsh and ~/.ssh folders.
#!/bin/bash
# Set backup directory
BACKUP_DIR="$(pwd)/Backup"
SSH_BACKUP_DIR="$BACKUP_DIR/ssh"
CONFIG_BACKUP_DIR="$BACKUP_DIR/config"
ZSH_BACKUP_DIR="$BACKUP_DIR/zsh"
echo "🔄 Starting backup..."
@kenilt
kenilt / flatten_folder.py
Created July 24, 2025 14:55
Flattens all files from subdirectories into a single base folder. This is helpful when your backups or exports are nested in many useless folders.
import os
import shutil
# Set your base folder here
base_folder = "/path/to/target/folder"
# Walk through all subdirectories (bottom-up to safely remove them)
for root, dirs, files in os.walk(base_folder, topdown=False):
for file in files:
# Skip hidden/system files
@kenilt
kenilt / remove_duplicated_files.py
Created July 24, 2025 14:54
Detects and moves duplicate files to a separate `Duplicated` folder. It chooses the best copy to keep based on filename and folder structure.
import os
import shutil
import re
from collections import defaultdict
from datetime import datetime
# === CONFIG ===
scan_folder = "path/to/target/folder" # ← change this to your target folder
duplicate_target = os.path.join(os.getcwd(), "Duplicated")
@kenilt
kenilt / group_files_by_date.py
Created July 24, 2025 14:52
Group media files (photos, videos, etc.) into folders by date. This is useful when you have thousands of mixed files exported from phones, cameras, or cloud services.
import os
import shutil
import re
from datetime import datetime
# Set your folder path
folder_path = "path/to/target/folder"
# Date patterns to extract from filenames
patterns = [
package com.facebook
object AccessTokenCreator {
fun createToken(grantedPermissions: Collection<String?>?): AccessToken? {
return AccessToken("token", "appId", "userId", grantedPermissions,
ArrayList<String>(), null, AccessTokenSource.WEB_VIEW, null, null, null)
}
}
import java.math.BigDecimal
import java.text.SimpleDateFormat
import java.util.*
abstract class Benchmark(internal val name: String) {
@Throws(Throwable::class)
internal abstract fun run(iterations: Int)
private fun time(): BigDecimal {
@kenilt
kenilt / MutableListTypeAdapter.kt
Last active August 2, 2018 05:57
Gson: Treat null as empty string or empty array
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonToken
import com.google.gson.stream.JsonWriter
import java.io.IOException
class MutableListTypeAdapter<T>(private val delegate: TypeAdapter<MutableList<T>>?) : TypeAdapter<MutableList<T>>() {
@Throws(IOException::class)
override fun write(out: JsonWriter?, value: MutableList<T>?) {