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
//general call in express for socket connection// | |
var app = require('express')(); | |
var server = require('http').createServer(app); | |
var io = require('socket.io')(server); | |
io.on('connection', function(){ /* … */ }); | |
server.listen(3000); | |
//example from how we use it in Michael Says// |
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
var SerialPort = require("serialport").SerialPort | |
var serialPort = new SerialPort("/dev/cu.usbmodem1411", { | |
baudrate: 57600 | |
}, false); // this is the openImmediately flag [default is true] | |
serialPort.open(function (error) { | |
// more code here// | |
var regex = /\d+/g; | |
var port = str.match(regex); |
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
require 'yaml' | |
require 'tweetstream' | |
require 'dino' | |
auth = YAML::load_file("twitter_api_config.yml") | |
TweetStream.configure do |config| | |
config.consumer_key = auth["consumer_key"] | |
config.consumer_secret = auth["consumer_secret"] | |
config.oauth_token = auth["oauth_token"] |
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
# dino_sample.rb | |
require 'dino' | |
board = Dino::Board.new(Dino::TxRx.new) | |
led = Dino::Components::Led.new(pin: 13, board: board) | |
[:on, :off].cycle do |switch| | |
led.send(switch) | |
sleep 0.5 |
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
// the setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize digital pin 13 as an output. | |
pinMode(13, OUTPUT); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) |
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
require "serialport" | |
#params for serial port | |
port_str = "/dev/cu.usbmodem1411" #may be different for you | |
baud_rate = 9600 | |
data_bits = 8 | |
stop_bits = 1 | |
parity = SerialPort::NONE | |
serial_port = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity) |
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
require_relative 'spec_helper' | |
describe ApodGet do | |
describe '#initialize' do | |
it "does not raise error when called on with no arguments" do | |
expect { ApodGet.new }.to_not raise_error | |
end | |
it "sets a constant 'base_url' as the root url of the Spotify Chart API" do | |
expect(ApodGet::BASE_URL).to eq("https://api.nasa.gov/planetary/apod?concept_tags=True&api_key=") |
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
def say_with_music(text: 'Space is cool.', | |
music: MUSIC.sample, | |
voice: NONMUSICAL_VOICES.sample, | |
volume: 0.8) | |
cmd = "say -v #{voice} \"#{text}\""\ | |
" & sleep 3 && afplay -v #{volume} #{music} &" | |
system(cmd) | |
end |
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
def take_pictures | |
file = 'lib/assets/images/img.jpg' | |
NUMBER_OF_PICTURES.times do | |
system "imagesnap -q -w 1 #{file}" | |
ascii_image = AsciiArtHelper.generate_ascii(src: "#{file}") | |
ASCII_IMAGES << ascii_image | |
end |
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
def loop_images(n = NUMBER_OF_LOOPS) | |
n.times do | |
ASCII_IMAGES.each do |i| | |
clear_screen | |
puts QUOTE.center(97) | |
puts i | |
sleep 0.5 | |
end | |
end | |
end |