Skip to content

Instantly share code, notes, and snippets.

import os
from PIL import Image # pip install Pillow
import pytesseract # pip install pytesseract
newly_renamed = 0
not_renamed = 0
for subdir, dirs, files in os.walk('./memes'):
for file in files:
src_path = os.path.join(subdir, file)
@aonemd
aonemd / subtitle_extractor.rb
Last active March 7, 2022 14:05
A Ruby script to extract text from images with subtitles and rename the image file to the extracted text (requires Tesseract to be installed)
require 'pathname'
require 'open3'
require 'mini_magick'
SRC_DIR = '/path/to/src/dir/'.freeze
TMP_DIR = '/path/to/tmp/dir/'.freeze
class TextReader
def initialize(input_path, output_path)
@input_path = input_path
  • Connect to wifi: wifi-menu
  • Partition the disk:
    1. list all disks: fdisk -l
    2. partition the disk: gdisk /dev/disk_name:
    • o: clear all partitions, n: create new partition, p: list partitions, w: save partitions, q: quit
    • create 4 partitions each with their equivalent code for partition type, boot: EF00, system: 8300, home: 8300, and swap: 8200
  • Format the partitions:
    • boot partition: mkfs.vfat /dev/boot_partition_name
    • system and home partitions: mkfs.ext4 /dev/system_partition_name && mkfs.ext4 /dev/home_partition_name
  • swap partition: mkswap /dev/swap_partition_name && swapon /dev/swap_partition_name
@aonemd
aonemd / missing_indices.rake
Last active September 21, 2016 12:50
Check missing indices on foreign keys in your tables
# https://tomafro.net/2009/09/quickly-list-missing-foreign-key-indexes
desc "Check missing indices on foreign keys in your tables"
task missing_indices: :environment do
c = ActiveRecord::Base.connection
c.tables.collect do |t|
columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
@aonemd
aonemd / how_many_words.sh
Last active February 18, 2016 23:17
Count how many words from different input sources
#!/bin/bash
# Usage: ./how_many_words.sh "word1|word2" "inputpath" "input type"
# Words separated by |
Words="$1"
InputPath="$2"
InputType="$3"
TempOutputPath="outttemp.txt"
@aonemd
aonemd / generate_db.rb
Last active January 24, 2016 01:08
Generate a Bulk of Data into Postgre
require 'pg'
conn = PG::Connection.open(dbname: 'mydb',
host: 'localhost',
user: 'testuser')
# create the first table (cup_matches)
conn.exec("CREATE TABLE cup_matches (
mid serial PRIMARY KEY,
round varchar(20),
@aonemd
aonemd / run.sh
Last active February 14, 2016 23:01
Go Benchmark for Subset Function
#!/bin/sh
# to run the benchmark
go test -bench=.