RenatoGeh / snippets

Bunch of snippets of various kinds and flavors.

Repository from Github https://github.comRenatoGeh/snippetsRepository from Github https://github.comRenatoGeh/snippets

Snippets

  1. pgm_compress.cpp:
  • Compresses PGM image files to an n-bit new PGM.
  1. pgm_histogram.cpp:
  • Prints histogram of color usage of a set of grayscale PGM images files.
  1. rcompress.sh:
  • Recursively find each PGM file in a given directory.
  • Creates an n-bit compressed PGM of each found PGM file.
  • Constructs a histogram out of all such PGM n-bit files.
  • Prints histogram to the stdin.
  1. trim.sh:
  • Trims an image with 10% fuzzy rate.
  1. jpg2pgm.sh:
  • Resizes all files to a given (x, y) size.
  • Searches for files in directories one level down.
  • Ignores aspect ratio.
  1. count.sh:
  • Counts number of files in directories one level down.
  • Prints each count, mean, max and min.
  1. coin.sh:
  • For each directory inside pwd, toss a coin for each PGM file in it.
  • If heads, put it in a folder named train inside the directory being scanned.
  • If tails, put it in test.
  • Number of files is limited by ntest and ntrain.
  1. word_count.cpp:
  • Takes a .voc file and counts word occurences (frequencies and percentage).
  1. prune_words.cpp:
  • Takes a .voc file and rewrites it as a new vocabulary containing only the k most frequent words.
  • Optionally deletes words that do not meet the criterion.
  1. longest_word.sh:
  • Searches for the longest word in a file.
  1. rand_sq_gen.cpp:
  • Generates a .pgm file containing an NxN (where N is a defined macro) square with n black squares in random positions.
  1. sq_gen.cpp:
  • Let N be the size of a square. sq_gen.cpp generates N-1 distinct instances of an NxN square with n random black squares in random distinct positions.
  1. has_duplicate.sh:
  • Given a set of files F, let i and j in F be distinct files. has_duplicate.sh returns whether there exists i and j such that the contents of i are equal to those of j.
  1. cat_sq_gen.sh:
  • For every possible n black squares configurations in a square of NxN dimension, create a category for each n and output N^2 configurations into their respective categories.
  1. pgm2data.sh:
  • Generates k random PGM images given a width, height and maximum pixel value.
  • Debug mode generates individual PGM files for visualization.
  • Compiles the k images into a .data file as specified in https://github.com/RenatoGeh/gospn.
  1. unique_id.go:
  • Tests a one-to-one and onto function for subrectangles in a rectangle.
  1. split_audio.sh:
  • Takes an audio or video f and splits it into pieces.
  • Every timestamp given as argument splits f from the previous timestamp to the next timestamp.
  • Great for splitting a single file album audio into multiple singles!
  1. extract_ty.sh:
  • Takes a YouTube URL, downloads the video, extracts the audio (.mp3) and splits it into different sections based on timestamps.
  • Uses split_audio.sh to split it by timestamps.
  1. diff_cmp.sh:
  • Takes a directory and an expression. Finds all same name files from current directory and given directory. For each of these files, use NeoVim's diff tool.
  • Useful for manually applying patches from different branches of the same repository.
  1. draw_scope.sh:
  • Draws the assigned pixels in a w x h image.
  1. pgauss.go:
  • Returns the probability of a value in a gaussian distribution with mean and standard deviation given.
  • Returns up to p digits of precision.
  • Requires GoNum.
  1. argrun.sh:
  • Takes a file f and command c.
  • For each line l in f, run c with l as arguments.
  1. prepend.sh:
  • Prepends contents of first file to all remaining files.
  1. extract_credits.sh:
  • Extracts credit information from University of São Paulo's (USP) course webpage.
  • Takes a list of courses and outputs the number of theory and practical credits, aswell as total credits for each type of credit.
  • Requires lynx.
  1. spot.sh:
  • Prints sidescrolling Spotify information.
  • Requires playerctl and the Spotify App.
  • Great for i3status bar.
  • Prints Title, Artist and Album.
  • Prompt cycles sideways every second, avoiding long titles to be hidden by other i3status components.
  • Skips ads every even second if ad is being played.
  1. draw_region.sh:
  • Draws a region of a rectangle given width, height and pixels.
  1. list_ratios.c:
  • Takes arguments w, h and d, where (w, h) are dimensions and d divides w and h.
  • Returns all possible dimensions (x, y) such that d divides both x and y, and ordered s.t. the ratio x/y is the closest to w/h.
  1. binder_org.py:
  • Binder organizer for music sheets or other compatible formats.
  • Prints how a binder should be organized given a set of sheets.
  • Output is ordered alphabetically and either categorized by author or title's first letter.
  • Load from file or directly through methods.
  1. gentags.sh:
  • Generate ctags for a given library.
  1. generate_all.sh
  • Utility script for generating ctags for common libs.
  1. generate_ttt.c
  • Generate all possible endgame configurations of the tic-tac-toe game.

About

Bunch of snippets of various kinds and flavors.


Languages

Language:Shell 32.6%Language:C++ 27.5%Language:C 22.2%Language:Go 9.2%Language:Python 8.5%