Skip to content

Commit

Permalink
WIP of all oracle features for TTATC
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Stiens committed Jul 14, 2018
0 parents commit 70a81a6
Show file tree
Hide file tree
Showing 33 changed files with 25,114 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.5.1
106 changes: 106 additions & 0 deletions belltest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
require 'pp'
require 'serialport'
require 'pry'

class TTy
def initialize
# defaults params for arduino serial
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

# serial port
@sp = nil
@port = nil
end

def open(port)
@sp = SerialPort.new(port, @baud_rate, @data_bits, @stop_bits, @parity)
end

def shutdown(reason)
return if @sp.nil?
return if reason == :int

printf("\nshutting down serial (%s)\n", reason)

# you may write something before closing tty
@sp.write(0x00)
@sp.flush
printf("done\n")
end

def read
@sp.flush
message = @sp.read
puts message
match = /\X:\((.*)\)Y:\((.*)\)Z:\((.*)\)/x.match(message)
if match && match.length == 4
x = match[1].to_f
y = match[2].to_f
z = match[3].to_f
return { x: x, y: y, z: z }
end
end

def write(c)
@sp.putc(c)
@sp.flush
printf("# W : 0x%02x\n", c.ord)
end

def flush
@sp.flush
end
end

# serial port should be connected to /dev/ttyUSB*
# ports = Dir.glob('/dev/ttyUSB*')
# if ports.size != 1
# printf('did not found right /dev/ttyUSB* serial')
# exit(1)
# end

tty = TTy.new
tty.open('/dev/ttyACM0')

at_exit { tty.shutdown :exit }
trap('INT') { tty.shutdown :int; exit }

@counter = 0

# just read forever
loop do
@counter = 0 if @counter > 10
@counter += 1

if @counter == 1
@min_x = @min_y = @min_z = 1000
@max_x = @max_y = @max_z = -1000
end

if @counter == 10
x_var = @max_x - @min_x
y_var = @max_y - @min_y
z_var = @max_z - @min_z
puts x_var
puts y_var
puts z_var
puts 'BELL RANG' if x_var > 4 || y_var > 4 || z_var > 4
end

hash = tty.read
if hash
@min_x = hash[:x] if hash[:x] < @min_x
@max_x = hash[:x] if hash[:x] > @max_x
@min_y = hash[:y] if hash[:y] < @min_y
@max_y = hash[:y] if hash[:y] > @max_y
@min_z = hash[:z] if hash[:z] < @min_z
@max_z = hash[:z] if hash[:z] > @max_z
end
sleep(0.25)
end

sleep 500
tty.shutdown
6 changes: 6 additions & 0 deletions faye.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'faye'

Faye::WebSocket.load_adapter('thin')
Faye.logger = Logger.new(STDOUT)
faye = Faye::RackAdapter.new(mount: '/faye', :timeout => 5)
run faye
14 changes: 14 additions & 0 deletions fayeclient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'faye'
require 'eventmachine'

endpoint = 'http://0.0.0.0:9292/faye'

EM.run do
puts "Connecting to #{endpoint}"

client = Faye::Client.new(endpoint)

subscription = client.subscribe '/fortune' do |message|
puts message
end
end
25 changes: 25 additions & 0 deletions h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=> #<Faye::Client:0x000055b4ea7022f0
@advice={"reconnect"=>"retry", "interval"=>0.0, "timeout"=>60000.0},
@channels=#<Faye::Channel::Set:0x000055b4ea6e6708 @channels={}>,
@dispatcher=
#<Faye::Dispatcher:0x000055b4ea68b1c8
@alternates={},
@client=#<Faye::Client:0x000055b4ea7022f0 ...>,
@cookies=#<CookieJar::Jar:0x000055b4ea68a8e0 @domains={}>,
@disabled=[],
@endpoint=#<URI::HTTP http://localhost:9292/faye>,
@envelopes={},
@headers={},
@listeners={"message"=>[#<Proc:0x000055b4ea5bda70 (lambda)>]},
@max_request_size=2048,
@proxy={},
@retry=5.0,
@scheduler=Faye::Scheduler,
@state=0,
@timeout=60.0,
@transports={},
@ws_extensions=[]>,
@listeners={},
@message_id=0,
@response_callbacks={},
@state=1>
95 changes: 95 additions & 0 deletions marky_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
require 'marky_markov'
require 'pry'
require 'yaml'
require 'literate_randomizer'

class String
def titlecase
split(/([[:alpha:]]+)/).map(&:capitalize).join
end
end

def setup
@markov = MarkyMarkov::Dictionary.new("#{rand(10000)}asdf")
# @markov.parse_file 'text/iching.txt'
@markov.parse_file 'text/iching-words.txt'
@markov.parse_file 'text/tarot-words.txt'
@markov.parse_file 'text/mckenna.txt'
@markov.parse_file 'text/rilke-words.txt'
@markov.save_dictionary!

@seeds_one = YAML.load(File.open('symbols/arcana.yml', 'r+'))
@seeds_two = YAML.load(File.open('symbols/dreams.yml', 'r+'))
@seeds_three = YAML.load(File.open('symbols/qualities.yml', 'r+'))
@seeds_four = YAML.load(File.open('symbols/hexagrams.yml', 'r+'))

@random = LiterateRandomizer.create(source_material_file: "#{Dir.pwd}/text/tarot-words.txt")

@counter = 0
end

def get_seed_word
words = [@seeds_one, @seeds_two, @seeds_three, @seeds_four].sample
words.sample
end

def find_sentence_for_word
1000.times do
sentence = @markov.generate_n_sentences(rand(3))
return sentence if sentence.downcase.include?(@seed_word.downcase)
end
nil
end

def find_sentence
sentence = nil
@seed_word = get_seed_word
sentence = find_sentence_for_word
return sentence if sentence
@counter += 1
return @random.sentence if @counter > 10
find_sentence
end

def modifiers
[
'leads to',
'follows',
'perplexes',
'shifts towards',
'obstructs',
'enhances',
'brings about',
'comes first, then',
'is a possibility, but so is',
'cannot stop',
'can turn into',
'can never stop',
'seems likely, but so does',
'can only lead to hesitation. Instead go for'
]
end

setup

loop do
gets.chomp
sentence = find_sentence
sentence = sentence.sub(/\w+/) { |m| m.capitalize }
sentence = sentence.gsub(/#{Regexp.escape(@seed_word)}/i, @seed_word.titlecase)
rand = rand(1..100)
if rand <= 4
puts "TYPE 1"
puts "#{get_seed_word.titlecase} #{modifiers.sample} #{get_seed_word.downcase}."
elsif rand <= 7
puts "TYPE 2"
sentence = sentence.split('.').first
sentence = sentence.split(',').first if sentence.split(' ').length > 10
puts "#{sentence}."
elsif rand <= 10
puts "TYPE 3"
puts "(#{get_seed_word.titlecase}) #{sentence.split('.').first}."
else
puts sentence.gsub(/#{Regexp.escape(@seed_word)}/i, @seed_word.upcase)
end
end
Empty file added new_fortune.rb
Empty file.
2 changes: 2 additions & 0 deletions oracle_sinatra/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem 'sinatra'
gem 'sinatra-asset-pipeline'
50 changes: 50 additions & 0 deletions oracle_sinatra/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
GEM
specs:
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
execjs (2.7.0)
ffi (1.9.25)
mustermann (1.0.2)
rack (2.0.5)
rack-protection (2.0.3)
rack
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
sass (3.5.6)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sinatra (2.0.3)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.3)
tilt (~> 2.0)
sinatra-asset-pipeline (2.1.0)
coffee-script (~> 2.4)
rake (~> 12.3)
sass (~> 3.5)
sinatra (~> 2.0)
sprockets (~> 3.7)
sprockets-helpers (~> 1.2)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-helpers (1.2.1)
sprockets (>= 2.2)
tilt (2.0.8)

PLATFORMS
ruby

DEPENDENCIES
sinatra
sinatra-asset-pipeline

BUNDLED WITH
1.16.2
8 changes: 8 additions & 0 deletions oracle_sinatra/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'sinatra'
require 'sinatra/asset_pipeline'

register Sinatra::AssetPipeline

get '/' do
erb :index
end
3 changes: 3 additions & 0 deletions oracle_sinatra/assets/faye-browser-min.js

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions oracle_sinatra/assets/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function increaseSpeed() {
speed = window.pJSDom[0].pJS.particles.move.speed
console.log(speed);
if (speed < 20)
speed += 3;
else
speed = 3;
clearInterval(increaseSpeed);
window.pJSDom[0].pJS.particles.move.speed = speed
}

function showText(text) {
$('#fortune').text(text);
$('#fortune').fadeIn(500);
setTimeout($('#fortune').fadeOut(5000), 25000)
}

function fortuneTeller(message) {
interval = setInterval(function(){
speed = window.pJSDom[0].pJS.particles.move.speed
console.log(speed);
if (speed < 30) {
speed += 1
}
else {
speed = 3;
clearInterval(interval);
showText(message)
}
window.pJSDom[0].pJS.particles.move.speed = speed
}, 200)
}

$( document ).ready(function() {
console.log('hello')
var url = 'http://0.0.0.0:9292/faye'
var client = new Faye.Client(url, {retry: 5});
client.disable('websocket');
console.log('subscribing')
client.subscribe('/fortune', function(message) {
fortuneTeller(message.text);
});
});
18 changes: 18 additions & 0 deletions oracle_sinatra/assets/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, rgba(117, 114, 113, 0.8) 10%, rgba(40, 49, 77, 0.8) 30%, rgba(29, 35, 71, 0.8) 50%, rgba(19, 25, 28, 0.8) 80%, rgba(15, 14, 14, .8) 100%);
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}

#fortune {
position: absolute;
width: 100%;
text-align: center;
padding-top: 200px;
display: none;
font-size: 3em;
}
2 changes: 2 additions & 0 deletions oracle_sinatra/assets/jquery.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions oracle_sinatra/assets/particles.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 70a81a6

Please sign in to comment.