Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Last active September 28, 2016 07:08
Show Gist options
  • Save thomasjslone/da0d0f39771b2f8dd5c209d74fb21588 to your computer and use it in GitHub Desktop.
Save thomasjslone/da0d0f39771b2f8dd5c209d74fb21588 to your computer and use it in GitHub Desktop.
ossy android version
class Ossy
def initialize()
@vdrive = ''
@log = ""
@app_name = "Ossy"
@app_version = "0.1.9"
@app_release_date = "2016.11.13"
@app_manufacturer = "Thomas Technical"
@app_description = "Ruby Operating Environment"
@main_thread1 = nil
@main_thread2 = nil
@main_thread3 = nil
@main_thread4 = nil
@main1 = false
@main2 = false
@main3 = false
@main4 = false
@main1_tasks = []
@main2_tasks = []
@main3_tasks = []
@main4_tasks = []
@main1_auto = true
@main2_auto = false
@main3_auto = false
@main4_auto = false
@main1_repeat = true
@main2_repeat = true
@main3_repeat = true
@main4_repeat = true
@main1_delay = "3.0"
@main2_delay = "10.0"
@main3_delay = "30.0"
@main4_delay = "60.0"
@gmail_logins = []
@gmail_login_usernames = []
@gmail_keychain = "[email protected];littletree3,"
@drive = "v:"
@files = []
@directories = [@drive]
@key = 0
@vdrive_changed = false
@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"]
@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"]
@alphnumdex = ["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"]
@alphdex = ["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"]
@alphdexl = ["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"]
@alphdexu = ["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"]
@symdex = ["`","~","!","@","#","$","%","^","&","*","(",")","_","-","=","+","[","]","{","}","\\","|","/","<",">",".",",",";",":","'",'"'," ", " "]
@numdex = ['0','1','2','3','4','5','6','7','8','9']
@vowels = ['a','e','i','o','u']
@doublevowels = ['ee','ae','oe','uu','iu','oo','aa']
@consonants = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']
@doubleconsonants = ['bl','br','cl','cr','dr','fr','ft','fl','gr','gl','gn','nd','ld','ll','pl','pr','sl','sn','sp','ss','rl','rn','rt','rr','rd','st','nt','rm','mm','xp']
@short_delays = [0.2500,0.5000,1.0,1.5,2.0,5.0,10.0,30.0]
@delays = [60.0,120.0,300.0,600.0,1200,1500.0,1800.0,3200.0,6400.00,12800.0] # minutes: 1, 2, 5, 10, 15, 20, 25, 30, 60, 120
@host_file_extensions = ['txt','bin','lib','dat','ini','cfg','key','rb','rbw','java','exe','html','xml','bat']
begin
fi = File.open(Dir.getwd.to_s + "/startup_configuration.tcfg","r")
fc = fi.read.to_s
fi.close
eval(fc.to_s)
rescue => exception
raise "Exception encountered in configuration: " + exception.to_s
end
if @main1_auto
start_main(1)
end
if @main2_auto
start_main(2)
end
if @main3_auto
start_main(3)
end
if @main4_auto
start_main(4)
end
end
def state
str = "## MAIN1 ## Running: " + @main1.to_s + "\n"
str << @main1_tasks.length.to_s + " TASKS: " + @main1_tasks.join(", ").to_s + "\n"
str << "AUTO: " + @main1_auto.to_s + "\n"
str << "REPEAT: " + @main1_repeat.to_s + "\n"
str << "INTERVAL: " + @main1_delay.to_s + "\n"
str << "\n"
str << "## MAIN2 ## Running: " + @main2.to_s + "\n"
str << @main2_tasks.length.to_s + " TASKS: " + @main2_tasks.join(", ").to_s + "\n"
str << "AUTO: " + @main2_auto.to_s + "\n"
str << "REPEAT: " + @main2_repeat.to_s + "\n"
str << "INTERVAL: " + @main2_delay.to_s + "\n"
str << "\n"
str << "## MAIN3 ## Running: " + @main3.to_s + "\n"
str << @main3_tasks.length.to_s + " TASKS: " + @main3_tasks.join(", ").to_s + "\n"
str << "AUTO: " + @main3_auto.to_s + "\n"
str << "REPEAT: " + @main3_repeat.to_s + "\n"
str << "INTERVAL: " + @main3_delay.to_s + "\n"
str << "\n"
str << "## MAIN4 ## Running: " + @main4.to_s + "\n"
str << @main4_tasks.length.to_s + " TASKS: " + @main4_tasks.join(", ").to_s + "\n"
str << "AUTO: " + @main4_auto.to_s + "\n"
str << "REPEAT: " + @main4_repeat.to_s + "\n"
str << "INTERVAL: " + @main4_delay.to_s + "\n"
str << "\n"
return str.to_s
end
def start_main(index)
res = []
ls = []
if index.is_a? String
if index.to_s.include?(",")
index.split(',').each { |n| ls << n.to_i }
else
ls << index.to_i
end
elsif index.is_a? Integer
ls << index.to_i
elsif index.is_a? Array
index.each { |n| ls << n.to_i }
end
ls.each do |ind|
if ind == 1
@main_thread1 = Thread.new{ main1 }
res << true
elsif ind == 2
@main_thread2 = Thread.new{ main2 }
res << true
elsif ind == 3
@main_thread3 = Thread.new{ main3 }
res << true
elsif ind == 4
@main_thread4 = Thread.new{ main4 }
res << true
end
end
if res.length == 0
return false
else
return res
end
end
def stop_main(index)
res = []
ls = []
if index.is_a? Integer
ls << index.to_i
elsif index.is_a? String
if index.include?(',')
index.split(',').each { |n| ls << n.to_i }
else
ls << index.to_i
end
elsif index.is_a? Array
index.each { |n| ls << n.to_i }
end
ls.each do |ind|
if ind == 1
@main1 = false
res << true
elsif ind == 2
@main2 = false
res << true
elsif ind == 3
@main3 = false
res << true
elsif ind == 4
@main4 = false
res << true
end
end
if res.length == 0
return false
else
return res
end
end
def main1
@main1 = true
while @main1
feedback = []
@main1_tasks.each do |cmd|
feedback << self.request(cmd.to_s)
end
if @main1_repeat.to_s == "true"
sleep @main1_delay.to_f
else
@main1 = false
break
end
end
end
def main2
@main2 = true
while @main2
feedback = []
@main2_tasks.each do |cmd|
feedback << self.request(cmd.to_s)
end
if @main2_repeat.to_s == "true"
sleep @main2_delay.to_f
else
@main2 = false
break
end
end
end
def main3
@main3 = true
while @main3
feedback = []
@main3_tasks.each do |cmd|
feedback << self.request(cmd.to_s)
end
if @main3_repeat.to_s == "true"
sleep @main3_delay.to_f
else
@main3 = false
break
end
end
end
def main4
@main4 = true
while @main4
feedback = []
@main4_tasks.each do |cmd|
feedback << self.request(cmd.to_s)
end
if @main4_repeat.to_s == "true"
sleep @main4_delay.to_f
else
@main4 = false
break
end
end
end
def request(inp) #3 performs activities for any callers
if inp.to_s[0..8] == "get_page:"
f = open(inp.to_s[9..-1].to_s)
res = f.read.to_s
f.close
return res.to_s
elsif inp.to_s[0] == "{"
begin
res = eval("`" + inp.to_s[1..-1].to_s + "`")
rescue => exception
res = exception.to_s + "\n" + exception.backtrace.join("\n").to_s
end
elsif inp.to_s[0] == "<"
begin
res = eval(inp[1..-1].to_s)
rescue => exception
res = exception.to_s
end
return res
elsif inp.to_s == "drives"
return self.get_windows_drives
elsif inp.to_s[0..4] == "dmap:"
m = self.map_directory(inp[5..-1].to_s)
return numerize(m[0].join("::D::").to_s + "::S::" + m[1].join("::F::").to_s).to_s
elsif inp.to_s[0..5] == "rfile:"
if File.exist?(inp[6..-1].to_s)
f = File.open(inp[6..-1].to_s,"r")
res = f.read.to_s
f.close
return res.to_s
else
return "No such file: " + inp[6..-1].to_s
end
else
return "Invalid Request"
end
end
def load_drive
fi = File.open(__FILE__,'r')
fc = fi.read.to_s.split("\n")
fi.close
fimg = denumerize(fc[2].to_s.split("'")[1].to_s)
puts "FIMG: " + fimg.to_s
encf = fimg.split(':sep:')[0].to_s.split(',')
encd = fimg.split(':sep:')[1].to_s.split(',')
files = []
directories = []
encf.each { |ef| files << denumerize(ef).chomp.to_s }
encd.each { |ed| directories << denumerize(ed).chomp.to_s }
@files = files
@directories = directories
true
end
def save_drive
encf = []
encd = []
@files.each { |f| encf << numerize(f).to_s }
@directories.each { |d| encd << numerize(d).to_s }
fimg = numerize(encf.join(",") + ":sep:" + encd.join(',').to_s)
fi = File.open(__FILE__,"r")
fc = fi.read.to_s.split("\n")
fi.close
fc[2] = "@vdrive = '" + fimg.to_s + "'"
fi = File.open(__FILE__,'w')
fi.write(fc.join("\n").to_s)
fi.close
true
end
def format_drive
@files = []
@directories = []
self.save_drive
end
def measure_drive
bytes = 0
@files.each do |fi|
bytes += fi.to_s.split('').length
end
return [@directories.length,@files.length,bytes]
end
def export_drive
encf = []
encd = []
@files.each { |f| encf << numerize(f).to_s }
@directories.each { |d| encd << numerize(d).to_s }
fimg = numerize(encf.join(",") + ":sep:" + encd.join(',').to_s).to_i * @key.to_i
return fimg.to_s
end
def import_drive(obj)
fc = obj.to_s.to_i / @key.to_i
fimg = denumerize(fc[2].to_s.split("'")[1].to_s)
encf = fimg.split(':sep:')[0].to_s.split(',')
encd = fimg.split(':sep:')[1].to_s.split(',')
files = []
directories = []
encf.each { |ef| files << denumerize(ef).chomp.to_s }
encd.each { |ed| directories << denumerize(ed).chomp.to_s }
@files = files
@directories = directories
true
end
def write_file(path,content)
if file_exist?(path)
ind = get_findex(path).to_i
file = @files[ind]
@files[ind] = file.split("::")[0].to_s + "::" + numerize(content.to_s).to_s
return "File was overwritten"
else
if @directories.include?(path.to_s.split('/')[0..-2].join('/').to_s)
@files << path.to_s + "::" + numerize(content.to_s).to_s
return "File created and written"
else
return "Invalid directory in file path"
end
end
end
def insert_file(path,pos,content)
end
def read_file(path)
if file_exist?(path)
return denumerize(@files[get_findex(path)].split("::")[-1].to_s).to_s
else
return "Invalid directory or file name"
end
end
def move_file(path,npath)
end
def copy_file(path,npath)
end
def delete_file(path)
if file_exist?(path)
@files.delete_at(get_findex(path).to_i)
true
else
false
end
end
def rename_file(path,name)
if file_exist?(path)
fi = @file[get_findex(path)].to_s
fc = fi.split('::')[1]
fp = fi.split('::')[0].to_s.split("/")[0..-2].join("/").to_s + "/" + name.to_s
if file_exist?(fp) == false
@file[get_findex(path)] = fp.to_s + "::" + fc.to_s
true
else
false
end
else
false
end
end
def measure_file(path)
@file[get_findex(path)].to_s.split('::')[1].to_s.split('').length
end
def file_exist?(path)
found = false
ct = 0
@files.each do |fi|
if fi.split("::")[0].to_s == path.to_s
found = ct.to_i
break
else
ct += 1
end
end
if found != false
return true
else
return false
end
end
def get_findex(path)
found = false
ct = 0
@files.each do |fi|
if fi.split("::")[0].to_s == path.to_s
found = ct.to_i
break
else
ct += 1
end
end
if found != false
return found.to_i
else
return false
end
end
def directory_exist?(path)
if @directories.include?(path)
true
else
false
end
end
def get_dindex(path)
if @directories.include?(path)
@directories.index(path).to_i
else
false
end
end
def directory_contents(path)
if @directories.include?(path)
conts = []
@directories.each do |d|
if d.to_s.include?(path)
conts << d.to_s
end
end
@files.each do |f|
if f.split("::")[0].to_s.include?(path)
conts << f.split("::")[0].to_s
end
end
if conts.length == 0
return nil
else
return conts
end
else
return false
end
end
def move_directory(path,npath)
end
def copy_directory(path,npath)
end
def make_directory(path)
ndir = path.split('/')[-1].to_s
if @directories.include?(path.split('/')[0..-2].join('/').to_s) and @directories.include(path.to_s) == false
@directories << path.to_s
true
else
false
end
end
def rename_directory(path,name)
if @directories.include?(path)
if directory_exist?(path.to_s.split('/')[0..-2].join('/').to_s + "/" + name.to_s) == false
@directories[get_dindex(path)] = path.to_s.split("/")[0..-2].join('/').to_s + "/" + name.to_s
return true
else
return false
end
else
return "Invalid directory"
end
end
def delete_directory(path)
if @directories.include?(path)
@directories.delete_at(get_dindex)
true
else
false
end
end
def measure_directory(path)
end
def import(paths,impath)
end
def export(paths,expath)
end
def splice(b,e,str)
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 rands(digits)
if digits.to_i < 5
key = rand(10**8..10**9).to_s(36).to_s[0..digits.to_i].to_s
else
key = ""
digits.times do
key << rand(10**8..10**9).to_s(36).to_s[rand(6).to_i].to_s
end
end
return key.to_s
end
def numeric?(s)
return s !~ /\D/
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 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
puts str.to_s
end
def numerize(str)
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
def denumerize(str)
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 }
return dec_str.to_s
end
def numeric?(s) ## check if a string has only positive integers
return s !~ /\D/
end
def exponate(n) ## take the given number and search for exponets which would result in it
c=2
e=2
r = [0,0]
until c > n
e = 2
until e >= n
if c**e == n
return [c,e]
end
e += 1
end
c += 1
end
end
def factors(n) ## get two numbers that multiplied together would result in the given value
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
end
$ossy = Ossy.new()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment