-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Justin Levinsohn
committed
May 18, 2016
0 parents
commit 37c92d3
Showing
217 changed files
with
82,858 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "eslint-config-airbnb", | ||
"rules": { | ||
//Temporarirly disabled due to a possible bug in babel-eslint (todomvc example) | ||
"block-scoped-var": 0, | ||
// Temporarily disabled for test/* until babel/babel-eslint#33 is resolved | ||
"padded-blocks": 0 | ||
}, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
node_modules | ||
dist | ||
npm-debug.log | ||
serve | ||
cert | ||
deploy/.vagrant | ||
.*.swp |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Query It! | ||
This repository houses the Query It! experience. | ||
|
||
##Important | ||
You need a valid [Google Cloud Platform project](http://cloud.google.com/free-trial/) to run this experience. Be aware, if you are not using a free trial, you will be charged for running the queries in this experience. | ||
|
||
###Screenshots | ||
 | ||
 | ||
 | ||
 | ||
|
||
###Generate Cert Token | ||
1. [Visit Credentials in GCP console](https://console.cloud.google.com/apis/credentials) | ||
1. Click Manage Service Accounts | ||
1. Create a new service account | ||
1. Create a directory named `cert` | ||
1. Download certificate and rename it `service_account.json`. | ||
1. Put `service_account.json` in the `/cert` directory. | ||
|
||
This project uses: | ||
* [Webpack](https://github.com/webpack/webpack) | ||
* [Sass](http://sass-lang.com/) | ||
|
||
To run this locally you'll need to: | ||
``` | ||
npm install | ||
npm run dev | ||
cd querysrv | ||
node querysrv.js | ||
``` | ||
|
||
## Vagrant | ||
|
||
To use [Vagrant](https://www.vagrantup.com/) to run the stack: | ||
|
||
1. `cd deploy` | ||
1. `vagrant up` | ||
1. `vagrant ssh` | ||
1. `cd /vagrant/` | ||
1. `npm run dev` | ||
|
||
You may need to run Salt again to set everything up: | ||
|
||
1. `vagrant up` | ||
1. `vagrant ssh` | ||
1. `sudo salt-call --local state.highstate` | ||
|
||
##SocketTalk | ||
|
||
To start the socket server, run `node server.js`. | ||
|
||
After running this server, you need to start the clients for both Player 1 and Player 2 (see below). | ||
|
||
When input is entered either locally or through a Pi, the data that is sent to the server is in JSON format. | ||
|
||
``` | ||
{ | ||
"running": "", // String for running answer, wiped down to an empty string when Enter is pressed | ||
"submitted": boolean, // true if Enter button was pressed, false otherwise | ||
"client": integer, // Should be either 1 or 2, depending on player identity | ||
} | ||
``` | ||
|
||
####Local | ||
|
||
The inputs for Query It! are streamed through websockets. | ||
|
||
Including an instance of `SocketDebugger` (currently in `app.js`), will allow you to enter input for either player. Simply typing will send input to Player 1, where holding shift and typing will send input to Player 2. | ||
|
||
This functionality can also be tested with the `client.js` app by running using the following command in a seperate Terminal window. | ||
|
||
``` | ||
node client.js --host=localhost --port=8095 --id=1 | ||
``` | ||
|
||
Using `--id=1` and `--id=2` will input the query into either Player 1 or Player 2's field. Using neither will give a pipeline for playing all sounds for the experience. | ||
|
||
If you have two extra windows open, you can run a version of both `id`s and switch between them to closely approximate the game. | ||
|
||
**Remember** that you have to type into the Terminal window, not the browser. | ||
|
||
####Raspberry Pi | ||
|
||
The Pis are currently configured to be on static IPs of `172.20.2.150` for Player 1 and `172.20.2.151` for Player 2. In order to update the computer that they automatically connect to on boot, you'll need to ssh in and change their boot address. | ||
|
||
For example, if the computer running the experience has an address of `172.20.6.144`, follow these steps for the Player 1 Pi. | ||
|
||
1. `ssh [email protected]` (use Pi default password) | ||
2. `sudo nano /home/pi/www/client.shl` | ||
3. Edit line 3 to read `/usr/bin/node /home/pi/www/client.js --host=172.20.6.144 --port=8095 --id=1` | ||
4. `sudo reboot` | ||
|
||
Follow these steps for Player 2 Pi, only use `ssh [email protected]` and `--id=2`. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
var keypress = require('keypress'); | ||
var fs = require('fs'); | ||
var argv = require('yargs').argv; | ||
var play = require('play'); | ||
var Sound = require('node-aplay'); | ||
var WebSocket = require('ws'); | ||
var ws; | ||
|
||
var SOUNDS = require('./src/scripts/events/sounds.js'); | ||
var running = ''; | ||
var singleCharRegex = new RegExp(/^[a-zA-Z0-9`=-]$/) | ||
var end = false; | ||
var reconnectTimeout; | ||
|
||
function playSound(sound) { | ||
sound = __dirname + '/wavs/' + sound + '.wav'; | ||
console.log(sound); | ||
if (argv.pi) { | ||
new Sound(sound).play(); | ||
} else { | ||
play.sound(sound); | ||
} | ||
} | ||
|
||
function connectToServer() { | ||
console.log('trying to connect'); | ||
|
||
ws = new WebSocket('ws://' + (argv.host || '10.0.0.5') + ':' + (argv.port || '8095')); | ||
ws.on('error', function(e) { | ||
console.log('cant connect'); | ||
reconnectTimeout = setTimeout( | ||
connectToServer, 1000 | ||
); | ||
}); | ||
setupSocket(); | ||
} | ||
|
||
function setupSocket() { | ||
ws.on('close', function close() { | ||
console.log('disconnected'); | ||
running = ''; | ||
reconnectTimeout = setTimeout( | ||
connectToServer, 1000 | ||
); | ||
}); | ||
|
||
ws.on('open', function() { | ||
console.log('connected'); | ||
clearTimeout(reconnectTimeout); | ||
ws.on('message', function(data) { | ||
var message = JSON.parse(data); | ||
if (message.event === 'clear') { | ||
end = false; | ||
running = ''; | ||
} else if (message.event === 'logError') { | ||
fs.appendFile('logs/big-query-errors.txt', data, function(){ console.log('error saved'); }); | ||
} else if (message.event === 'sound' && (message.data.clients.indexOf(argv.id) !== -1 || !argv.id)) { | ||
playSound(message.data.sound); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
connectToServer(); | ||
|
||
// make `process.stdin` begin emitting "keypress" events | ||
keypress(process.stdin); | ||
|
||
// listen for the "keypress" event | ||
process.stdin.on('keypress', function (ch, key) { | ||
if (key) { | ||
if (!end) { | ||
end = (key.name == 'return'); | ||
} | ||
if (singleCharRegex.exec(key.name)) { | ||
running += ch; | ||
} | ||
if (key.name == 'space') { | ||
running += ' '; | ||
} else if (key.name == 'backspace') { | ||
running = running.slice(0, running.length - 1); | ||
} | ||
|
||
if (end) { | ||
// running = ''; | ||
} | ||
|
||
if (key && key.ctrl && key.name == 'c') { | ||
process.exit(0); | ||
} | ||
} else if (singleCharRegex.exec(ch)) { | ||
ch = ch.replace('`', '#'); | ||
ch = ch.replace('=', '+'); | ||
running += ch; | ||
} | ||
|
||
ws.send(JSON.stringify({ | ||
event: 'playerInput', | ||
data: { | ||
'running': running, | ||
'submitted': end, | ||
'client': argv.id, | ||
} | ||
})); | ||
|
||
}); | ||
|
||
process.stdin.setRawMode(true); | ||
process.stdin.resume(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
VAGRANTFILE_API_VERSION = "2" | ||
|
||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | ||
config.vm.box = "ubuntu/trusty64" | ||
|
||
config.vm.provider "virtualbox" do |v| | ||
v.memory = 1024 | ||
v.cpus = 2 | ||
end | ||
|
||
# Setup ports on your local box to talk to some of the services on the Vagrant box | ||
# 'guest' is the Vagrant box, 'host' is your box | ||
config.vm.network "forwarded_port", guest: 8095, host: 8095 # raspberry pis | ||
config.vm.network "forwarded_port", guest: 3000, host: 3000 # querysrv | ||
config.vm.network "forwarded_port", guest: 8080, host: 8080 # web | ||
config.vm.network "forwarded_port", guest: 5858, host: 5858 # node-debug | ||
config.vm.network "public_network" | ||
config.ssh.forward_agent = true | ||
|
||
config.vm.synced_folder "..", "/vagrant" | ||
|
||
config.vm.provision :salt do |salt| | ||
salt.colorize = true | ||
salt.log_level = "info" | ||
salt.masterless = true | ||
salt.minion_config = "etc/minion" | ||
salt.run_highstate = true | ||
# Some fix I found on a github issue to get salt to work | ||
salt.bootstrap_options = '-F -c /tmp/ -P' | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
file_client: local | ||
|
||
file_roots: | ||
base: | ||
- /vagrant/deploy/salt/ | ||
- /vagrant/deploy/formulas/nvm-formula/ | ||
|
||
pillar_roots: | ||
base: | ||
- /vagrant/deploy/pillar/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
os: | ||
user: vagrant | ||
home_dir: /home/vagrant |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
project: | ||
name: 'Query It!' | ||
base_dir: /vagrant/ | ||
src_dir: /vagrant/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% set environment = salt['grains.get']('environment', default='development') %} | ||
|
||
base: | ||
'*': | ||
- {{ environment }}.os | ||
- {{ environment }}.project |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
font=$(cd /usr/share/figlet/; ls *lf | egrep -v '(mnemonic|term|ivrit|digital)' | shuf -n1) | ||
echo -e '\e[91m' | ||
toilet -tf "$font" {{ salt['pillar.get']('project:name', 'Hello!') }} | ||
echo -e '\e[39m' | ||
|
||
cat << EOF | ||
Hi. | ||
The site should now be available at http://localhost:8080 | ||
To re-run salt: | ||
sudo salt-call --local state.highstate | ||
Your history is primed with some basic commands. Ctrl-R to search through them. | ||
More info to come. *YOU* can add info to this here: | ||
deploy/salt/config/motd.txt | ||
EOF |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cd /vagrant | ||
tmux new-session -d 'node server.js' | ||
tmux new-window -d 'npm run dev' | ||
tmux new-window -d 'cd querysrv; node querysrv.js' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
description "Query It" | ||
author "Nik Zap" | ||
|
||
# Listen and start after the vagrant-mounted event | ||
start on vagrant-mounted | ||
stop on runlevel [!2345] | ||
|
||
expect fork | ||
|
||
exec sudo su -lc 'cd; bash queryit-tmux.sh' vagrant |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Defaults env_keep+=SSH_AUTH_SOCK |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
file_roots: | ||
base: | ||
- /srv/salt/ | ||
- /srv/formulas/nvm-formula |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{% set user = salt['pillar.get']('project:user') %} | ||
{% set src_dir = salt['pillar.get']('project:src_dir') %} | ||
{% set nvm_install_path = salt['pillar.get']('nvm:install_path', '/opt/nvm') %} | ||
|
||
https://github.com/creationix/nvm.git: | ||
git.latest: | ||
- rev: master | ||
- target: {{ nvm_install_path }} | ||
- force: True | ||
|
||
nvm_profile: | ||
file.blockreplace: | ||
- name: /etc/profile | ||
- marker_start: "#> Saltstack Managed Configuration START <#" | ||
- marker_end: "#> Saltstack Managed Configuration END <#" | ||
- append_if_not_found: true | ||
- content: | | ||
if [ -f "{{ nvm_install_path }}/nvm.sh" ]; then | ||
source {{ nvm_install_path }}/nvm.sh | ||
fi | ||
nvm-install: | ||
cmd.run: | ||
- name: source {{ nvm_install_path }}/nvm.sh; nvm install v5.5.0 | ||
- require: | ||
- file: nvm_profile | ||
|
||
npm-install: | ||
cmd.run: | ||
- name: 'source {{ nvm_install_path }}/nvm.sh; npm install' | ||
- cwd: {{ src_dir }} | ||
- user: {{ user }} | ||
- require: | ||
- cmd: nvm-install |
Oops, something went wrong.