-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvhash.rb
More file actions
170 lines (122 loc) · 3.35 KB
/
vhash.rb
File metadata and controls
170 lines (122 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
91
92
93
94
95
96
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'postgresql',
:database => 'fiosv',
:username => 'YOURUSERNAMEHERE',
:password => 'PASSWORD',
:host => 'localhost',
:port => '5432'
)
# NOTE READ THIS
# change the above adapter to mysql from postgresql if your using mysql
# dont forget to change the port too!! change user/ pass/db name to whatever you use
# see README and database_readme.txt for details
#ActiveRecord::Base.logger = Logger.new(STDERR)
def dec2hex(number)
number = Integer(number.to_i);
hex_digit = "0123456789ABCDEF".split(//);
ret_hex = '';
while(number != 0)
ret_hex = String(hex_digit[number % 16 ] ) + ret_hex;
number = number / 16;
end
return ret_hex; ## Returning HEX
end
class NilClass
def show
puts "NOT FOUND"
end
end
class Vhash < ActiveRecord::Base
set_table_name "vhashes"
def show
puts "FOUND input: #{self.input} as decimal: #{self.input_to_decimal_timecode} ouput: #{self.output}"
end
def hash_as_array
v = self
hash_array = [v.output[0..1], v.output[2..3], v.output[4..5], v.output[6..7], v.output[8..9], v.output[10..11], v.output[12..13], v.output[14..15], v.output[16..17], v.output[18..19],
v.output[20..21], v.output[22..23], v.output[24..25], v.output[26..27], v.output[28..29], v.output[30..31], v.output[32..33], v.output[34..35], v.output[36..37], v.output[38..39] ]
puts hash_array.join(" ")
return hash_array
end
def hash
output
end
def input_to_decimal
self.input[0..1].hex.to_s + self.input[2..3].hex.to_s + self.input[4..5].hex.to_s + self.input[6..7].hex.to_s
end
def input_to_decimal_timecode
self.input[0..1].hex.to_s + "-" + self.input[2..3].hex.to_s + ":" + self.input[4..5].hex.to_s + "." + self.input[6..7].hex.to_s
end
end
def find_by_time(time)
hours,minutes,seconds = time.split(":")
if minutes.length < 2
minutes = "0" + minutes.to_s
end
if hours.length < 2
hours = "0" + hours.to_s
end
if seconds.length < 2
seconds = "0" + seconds.to_s
end
if hours.to_s == "0"
hours = "00"
end
if seconds.to_s == "0"
seconds = "00"
end
if minutes.to_s == "0"
minutes = "00"
end
puts "converting 00#{hours}#{minutes}#{seconds} to hex"
hours = dec2hex(hours)
minutes = dec2hex(minutes)
seconds = dec2hex(seconds)
if minutes.length < 2
minutes = "0" + minutes.to_s
end
if hours.length < 2
hours = "0" + hours.to_s
end
if seconds.length < 2
seconds = "0" + seconds.to_s
end
if hours.to_s == "0"
hours = "00"
end
if seconds.to_s == "0"
seconds = "00"
end
if minutes.to_s == "0"
minutes = "00"
end
puts "searching for 00#{hours}#{minutes}#{seconds}"
result = Vhash.find_by_input("00#{hours}#{minutes}#{seconds}")
if result != nil
puts "found hash for time #{result.hash}"
return result
else
puts "oh no couldnt find!"
Kernel.exit
end
end
class Vhash2 < Vhash
set_table_name "vhashes2"
end
#v1 = Vhash.find(:first)
#v1.show
#puts v1.hash
#v2 = find_by_time("2:35:36")
#x = Time.parse("01/01/1970")
#86400.times do
#x = x + 1.second
#vhash = find_by_time(x.strftime("%H:%M:%S"))
#end
#v2.show
#puts "--------"
#v3 = Vhash.find_by_output("62 75 11 73 f6 5c b5 d2 71 62 ef b7 54 be 8c ef 09 e2 86 67".gsub(" ", ""))
# v3.show
#v4 = Vhash.find_by_output("70 01 c2 04 fe 08 50 6b 80 21 37 18 84 a7 6f c2 7e ca 6d 9c".gsub(" ", ""))
# v4.show