Skip to content

Instantly share code, notes, and snippets.

View Beyarz's full-sized avatar
💎
Searching for Ruby gems

Beyar Beyarz

💎
Searching for Ruby gems
  • Sweden
  • 12:53 (UTC +01:00)
View GitHub Profile
@Beyarz
Beyarz / bulk_rename.rb
Created August 8, 2024 21:13
Rename every folder in a directory
# frozen_string_literal: true
# Put me in a folder where you want to bulk rename every folder
# In this case, this script will rename every folder from "Photos from YEAR" to "YEAR" only
# Run: ruby bulk_rename.rb
folders = Dir.entries('.').reject { ['.', '..'].include? _1 }
folders.each do |folder|
File.rename(File.join(Dir.pwd, folder), File.join(Dir.pwd, folder.delete_prefix("Photos from ")))
end
@Beyarz
Beyarz / flatten.rb
Last active August 9, 2024 17:57
Flatten a directory structure and its hierarchy. This script moves every file in a subfolder to its parent and then delete the subfolder
# frozen_string_literal: true
# Put me in a folder where you want to get rid of all the subfolders
# Run: ruby flatten.rb
def move_and_delete(dir)
puts "Cleaning \"#{dir}\""
Dir.foreach(dir) do |file|
next if ['.', '..'].include?(file)
@Beyarz
Beyarz / collision.c
Created June 8, 2024 12:42
Check collision between a circle and a rectangle
#include <math.h>
typedef float f32;
typedef struct Vector2
{
f32 x, y;
} Vector2;
typedef SDL_FRect RectangleF;
typedef struct Circle
@Beyarz
Beyarz / common.h
Created June 8, 2024 12:37
Shorter typdefs
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef size_t umax;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
@Beyarz
Beyarz / README.md
Last active November 8, 2024 21:03
Comprehensive guide to get working environment with MRuby

Getting started

Compile on Windows

  1. Install msys2 (because we need mingw64, gcc and libws2_32.a)
  2. Open msys2 or mingw64 and run pacman -S mingw64/mingw-w64-x86_64-mruby
  3. Get MRuby and extract the folder
  4. Run make inside the folder mruby-3.3.0, there will be a new folder called /build after the compilation, we need the file at /build/host/lib/libmruby.a
  5. Compile using the following command gcc main.c -I"mruby-3.3.0/include" "mruby-3.3.0/build/host/lib/libmruby.a" "C:\msys64\mingw64\lib\libws2_32.a" -lm -o main or substitue "C:\msys64\mingw64\lib\libws2_32.a" with -lws2_32
  6. Run the compiled binary main.exe
@Beyarz
Beyarz / windows_subsystem_cmd.md
Last active March 28, 2024 13:01
Windows unix commands in CMD

Run unix stuff in cmd

Run: choco install msys

Symlink directory (some project assume its in C:\msys64): MKLINK /D "C:\msys64" "C:\tools\msys64"

Add the following path C:\msys64\usr\bin to your PATH environment variable

Now you shoule be able to run pacman -Q, choco list | sed s/msys2/test/g, help | grep disk

We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 7 in line 1.
2023;Jan;Feb;Mars;April;Maj;Juni;Juli;Aug;Sep;Okt;Nov;Dec
Södertörn;469,25;469,25;424,5;424,5;439;439;435;435;460;460;457,5;457,5
Stockholm;497,5;497,5;425;425;460;460;465;465;529;529;485;485
Nacka;-;-;520;520;449,75;449,75;455,25;455,25;462,5;462,5;470,25;470,25
Solna;535;535;437,5;437,5;491,75;491,75;-;-;503,5;503,5;470;470
Attunda;503;503;417,5;417,5;460,5;460,5;431,25;431,25;475;475;453,75;453,75
2022;Jan;Feb;Mars;April;Maj;Juni;Juli;Aug;Sep;Okt;Nov;Dec
Södertörn;452,5;452,5;423,75;423,75;436;436;487,75;487,75;441,25;441,25;454,75;454,75
Stockholm;498,5;498,5;482,5;482,5;470;470;453;453;477,5;477,5;475;475
Nacka;463,5;463,5;426;426;426,5;426,5;-;-;452,5;452,5;440;440
@Beyarz
Beyarz / optimize_video.md
Last active July 6, 2024 13:46
Automatically optimize every video in a folder via ffmpeg to save up storage. It's multithreaded and supports GPU acceleration, just put this script in the folder and execute it.

Optimize video

Run

  1. Download the script
  2. Put this file in the same folder as your videos
  3. Run: ruby optimize_video.rb, for help, use ruby optimize_video.rb --help

Watch log / debug

@Beyarz
Beyarz / itob.rb
Created August 19, 2023 19:37
Convert integer to binary
def itob(number)
decimals = []
while (number.positive?)
number, remainder = number.divmod(2)
decimals << remainder
end
bits = decimals.length.times.map { |i| 2**i }
validate_sum = 0
@Beyarz
Beyarz / README.md
Last active May 31, 2023 06:48 — forked from andrewmd5/README.md
Decipher this text - solution

Decipher this text

Can you crack the secret message hidden within this cipher? I've taken a phrase and encoded it into a string of words that look like "meatball". It's a bit tricky, but I believe in your skills!

Cipher Text:

mEaTbALLmEAtBALLmEATbALL, mEATBalLmEAtBALLmEATbAlL mEAtbalLmEATbaLlmEAtbAlL mEATbaLLmEATbAlLmEATballmEAtbAlLmEATbaLl mEATbaLLmEAtBAlLmEAtbalLmEATbaLlmEATbAll! mEaTbALLmEAtbalLmEAtBALlmEATbAll mEAtbalL mEAtBaLlmEAtBALLmEAtbaLl? mEaTbALLmEAtbAlL'mEATbaLlmEAtbAlL mEAtBallmEAtBalLmEATbaLlmEAtBalLmEAtBALlmEAtbALL: mEAtbalLmEAtBALlmEAtbAllmEATbaLlmEAtbAlLmEATbALL@mEAtbaLlmEAtbAlLmEATbAllmEATbALLmEAtBalLmEATBallmEATbAllmEAtBAllmEAtbalLmEAtbaLlmEATbaLL.mEAtbaLLmEAtBALLmEAtBAlL