Created
April 14, 2017 11:07
-
-
Save thomasjslone/48bcec48d9c4c6b9e7f9ac862e3f2870 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Name: Rios Methods | |
## Version: 1.0.6 | |
## Release: 2017-1-5 | |
## Manufacturer: Thomas Tech | |
def splice(str,b,e) | |
res = [] | |
loop do | |
p = str[/#{b}(.*?)#{e}/m, 1].to_s | |
if p.to_s.length == 0 | |
break | |
else | |
res << p | |
str = str.split(b + p + e)[-1].to_s | |
end | |
end | |
return res | |
end | |
def starts_with(string,tag) | |
chk = true | |
i = 0 | |
string.to_s.split("").each do |ch| | |
if ch.to_s != tag.to_s[i].to_s | |
chk = false | |
end | |
if i + 1 == tag.length.to_i | |
break | |
else | |
i += 1 | |
end | |
end | |
chk | |
end | |
def ends_with(string,tag) | |
string = string.reverse | |
tag = tag.reverse | |
chk = true | |
i = 0 | |
string.to_s.reverse.split("").each do |ch| | |
if ch.to_s != tag.to_s[i].to_s | |
chk = false | |
end | |
if i + 1 == tag.length.to_i | |
break | |
else | |
i += 1 | |
end | |
end | |
chk | |
end | |
def list_spacer(spaces,left,right) | |
width = spaces .to_i+ 5 | |
str = '' | |
left.each do |l| | |
spacer = "" | |
t = width - l.length.to_i | |
t.to_i.times { spacer << " " } | |
str << l.to_s + spacer.to_s + right[left.index(l)].to_s + "\n" | |
end | |
return str.to_s | |
end | |
def fnum(n) | |
str = "" | |
s = n.to_s.split("").reverse | |
i=0 | |
s.each do |nc| | |
if i == 2 | |
i=0 | |
str << nc.to_s + "," | |
else | |
str << nc.to_s | |
i+=1 | |
end | |
end | |
if str.to_s[-1].to_s == "," | |
str = str.reverse.to_s.split("")[1..-1].join("").to_s | |
else | |
str = str.reverse.to_s | |
end | |
return str | |
end | |
def rands(l) | |
key = "" | |
l.times { key << rand(10**8..10**9).to_s(36).to_s[rand(6).to_i].to_s } | |
key.to_s | |
end | |
def numerize(str) | |
if str == "" | |
return 0 | |
else | |
chbytes = ["97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "126", "96", "33", "64", "35", "36", "37", "94", "38", "42", "40", "41", "45", "95", "61", "43", "91", "93", "123", "125", "59", "58", "34", "39", "92", "47", "124", "63", "60", "62", "44", "46", "32", "9", "10"] | |
ch_inds = [] | |
str.to_s.split("").each { |ch| ch_inds << chbytes.index(ch.to_s.ord.to_s) } | |
enc = [] | |
ch_inds.each do |ch| | |
code = ch.to_i + 1 | |
if code.to_s.length == 1 | |
code = "0" + code.to_s | |
else | |
code = code.to_s | |
end | |
enc << code.to_s | |
end | |
enc = enc.join("").to_s | |
if enc.to_s[0].to_s == "0" | |
enc = enc[1..-1].to_s | |
end | |
return enc.to_s | |
end | |
end | |
def denumerize(str) | |
kbchars = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9","~","`","!","@","#","$","%","^","&","*","(",")","-","_","=","+","[","]","{","}",";",":","\"","'","\\","/","|","?","<",">",",","."," ","\t","\n"] | |
if str.to_s.length.odd? ; str = "0" + str.to_s ; end | |
str_codes = [] ; i = 0 ; hold = "" | |
str.to_s.split("").each do |num| | |
if i.to_i == 0 | |
hold << num.to_s ; i += 1 | |
elsif i.to_i == 1 | |
hold << num.to_s | |
i = 0 | |
str_codes << hold.to_s | |
hold = "" | |
end | |
end | |
str = str_codes | |
str_codes = [] | |
str.each do |c| | |
str_codes << c.to_i - 1 | |
end | |
dec_str = "" | |
str_codes.each { |c| dec_str << kbchars[c.to_i].to_s } | |
dec_str.to_s | |
end | |
def map_directory(dir) | |
if File.directory?(dir) | |
remaining = [dir] ; found_files = [] ; file_size = [] ; found_folders = [] | |
until remaining.length == 0 | |
cur_dir = remaining[0].to_s | |
remaining.delete_at(0) | |
begin | |
cont = Dir.entries(cur_dir) | |
cont.delete(".") | |
cont.delete("..") | |
rescue | |
cont = [] | |
end | |
if cont.length > 0 | |
cont.each do |obj| | |
if File.file?(cur_dir.to_s + "/" + obj.to_s) | |
found_files << cur_dir.to_s + "/" + obj.to_s | |
file_size << File.size?(found_files[-1]) | |
elsif File.directory?(cur_dir.to_s + "/" + obj.to_s) | |
found_folders << cur_dir.to_s + "/" + obj.to_s | |
remaining << cur_dir.to_s + "/" + obj.to_s | |
end | |
end | |
else | |
end | |
end | |
return [file_size,found_files,found_folders] | |
else | |
"DIRECTORY NON-EXISTENT: " + dir.to_s | |
end | |
end | |
def exponates(n) | |
c=2 ; e=2 ; r = [0,0] | |
until c > n.to_i | |
e = 2 | |
until e >= n.to_i | |
if c**e == n.to_i | |
return [c,e] | |
end | |
e += 1 | |
end | |
c += 1 | |
end | |
end | |
def factors(n) | |
p = [2] ; vn = 2 | |
until vn == n | |
vn += 1 | |
p << vn | |
end | |
p.delete_at(-1) | |
f1 = 0 ; f2 = 0 ; pd = [] | |
p.each do |pn| | |
s = n.to_f / pn.to_f | |
if s.to_s[-2..-1].to_s == ".0" | |
pd << pn | |
end | |
end | |
pd.each do |p| | |
if p * p == n | |
f1, f2 = p, p | |
else | |
cd = pd | |
cd.delete(p) | |
cd.each do |pr| | |
if p * pr == n | |
f1, f2 = p, pr | |
break | |
end | |
end | |
end | |
end | |
return [f1,f2] | |
end | |
def tstamp ; Time.now.to_s.split(" ")[0..1].join(".").split(":").join(".").split("-").join(".").to_s ; end | |
def cstamp(ts) ; t = ts.to_s.split(".") ; t = Time.new(t[0],t[1],t[2],t[3],t[4],t[5]) ; t ; end | |
def nest_code(code) | |
end | |
def denest_code() | |
end | |
def compress_byte_array(path) | |
end | |
def decompress_byte_array(string) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment