Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
thomasjslone / dictionarydatabank.rb
Last active July 25, 2024 16:33
redid my old dictionary database with efficiency in mind
#@# dictionarydatabank.rb - version 1.0 tested on 2024.07.26 - thomas j slone
## a sort of database, designed for dictionary builders, store billions of words by dividing massive arrays into bank files of limited size.
## final todos
##
## enforce add string size limit
## add a config file for banks so when reloading bank and string sizes dont have to be given only when making a bank for the first time
## add methods for geting and setting size limits and possibly renaming bank though that literally requires moving the entire directory to rename it
@thomasjslone
thomasjslone / gpt spiral ascii
Created June 25, 2024 16:31
gpt actually did ok
def draw_spiral(size)
grid = Array.new(size * 2 + 1) { Array.new(size * 2 + 1, ' ') }
x, y = size, size
direction = 0 # 0: right, 1: down, 2: left, 3: up
step = 1
(size * size).times do |i|
grid[y][x] = '*'
case direction
@thomasjslone
thomasjslone / splice multi instance
Created August 28, 2023 18:11
improved splice method returns array
def splice(b,e)
ilist = []
if b.is_a?(String) == false or e.is_a?(String) == false; raise "Arguements require String type."
elsif b.to_s=="" or e.to_s == ""; raise "Arguements cannot be nilstring."
end
s=self ## self inside the loop will not be the string
if s.length<=(b.to_s.length+e.to_s.length); raise "Base string is too small."; end
pos=0; stack = false; list=[]
if b.length > e.length ; buffer_length = b.length; else; buffer_length = e.length; end
buffer = []; buffer_length.times{ buffer << "" }
@thomasjslone
thomasjslone / repairedirbdemo.rb
Created August 23, 2023 18:21
had to make some tweaks to get this to run
#######################################################
#
# demo-ruboto-irb.rb (by Scott Moyer)
#
# This demo duplicates the functionality of
# Ruboto IRB (written in Java) with a ruboto
# script (written in Ruby).
#
#######################################################
@thomasjslone
thomasjslone / rubin_installer.rb
Created May 31, 2023 15:11
most recent ve4sion
VERSION='1.0.30'
## RubinSystem is a ruby app runtime environment. Multi-Instance, bot controller on Mingw Windows Ruby
## ## !! WARNING !! If you did not download this script from github or the official website, DO NOT RUN IT!
## Run this script to install Rubin System, either select the work directory or enter an install location.
## After installing run "launch.rb" and you will get the system shell by default. The shell runs input as
## ruby script on the RubinSystem context. Precede a command with * if you are entering windows scripts
## or host commands, also *context=MAIN changes shell context. The shell does not handle stack errors well
## so IRB is used to catch error messages that crash the shell.
##
## Upon first use, you will get a default system config, use SYSTEM.config? to see what config settings
@thomasjslone
thomasjslone / splice.rb
Last active May 2, 2023 23:21
i guided chat gpt into creating a working version of my method, it took a few tries and one tweak to get working.
def splice(b, e)
if !b.is_a?(String) || !e.is_a?(String) ; raise "Arguments require String type."
elsif b.empty? || e.empty? ; raise "Arguments cannot be empty."
end
s_copy = self.dup
if s_copy.length <= (b.length + e.length); raise "Base string is too small."; end
pos = 0 ; stack = false ; list = []
if b.length > e.length ; buffer_length = b.length
else ; buffer_length = e.length
@thomasjslone
thomasjslone / splice_method1.rb
Created May 2, 2023 23:01
my splice method made with ruby parsing in mind for future development
def splice(b,e)
if b.is_a?(String) == false or e.is_a?(String) == false; raise "Arguements require String type."
elsif b.to_s=="" or e.to_s == ""; raise "Arguements cannot be nilstring."
end
s=self ## self inside the loop will not be the string
if s.length<=(b.to_s.length+e.to_s.length); raise "Base string is too small."; end
pos=0; stack = false; list=[]
if b.length > e.length ; buffer_length = b.length; else; buffer_length = e.length; end
buffer = []; buffer_length.times{ buffer << "" }
empty_buffer=[]; buffer_length.times{ empty_buffer << "" } ## again, in the loop we can only refer to vars
@thomasjslone
thomasjslone / aes_password_object.rb
Created May 2, 2023 23:00
really not good password object, do not use this for passwords you share with stuff
require 'openssl'
class Password
def initialize(string, seed)
@seed = seed
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt
cipher.key = Digest::SHA256.digest(@seed)
@password = cipher.update(string) + cipher.final
end
@thomasjslone
thomasjslone / time.rb
Created May 2, 2023 22:58
most popular copy paste time methods
Time.class.class.class_eval{
def parse_seconds(s)
s = s.to_i
if s < 60 ; [0, 0, s]
elsif s < 3600 ; [0, s / 60, s % 60]
elsif s < 86400 ; [s / 3600, (s / 60) % 60, s % 60]
else
days = s / 86400
hours = (s / 3600) % 24
@thomasjslone
thomasjslone / parse_array_hash.rb
Created May 2, 2023 22:54
this was created out of the need to read arrays and hashes from files with out the worry of evaling injected script
def parse_array *args
if args.length > 0 ; str = args[0]
else; str = self
end
if str.to_s == "[]"; return []; end
str = str.strip.gsub(/^\[|\]$/, '')
elements = []; current_element = ''; nested_level = 0
str.each_char do |c|