Skip to content

Instantly share code, notes, and snippets.

View rssilva's full-sized avatar

Rafael Specht da Silva rssilva

View GitHub Profile
const getSourceNode = (audioContext, buffer) => {
// let's create an empty buffer
const source = audioContext.createBufferSource()
// then we assign the passed buffer to node's buffer
source.buffer = buffer
// this is will play the buffer in looping
source.looping = true
return source
// Let's add a canvas to see the graphs, a textarea to write the equation
// and a button to start playing
const context = document.querySelector('#canvas').getContext('2d')
const textArea = document.querySelector('#function-area')
const button = document.querySelector('#play-button')
const audioContext = new AudioContext()
const SAMPLE_RATE = 3000
// doing a query to get the element on html file
const canvas = document.querySelector('#canvas')
// getting the canvas context
const context = canvas.getContext('2d')
// Let's create an Image instance
const baseImage = new Image()
// 'lena.jpg' is the image path on your file system
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style media="screen">
.scrolling-indicator {
position: fixed;
top: 0;
var five = require('johnny-five');
var http = require('http');
var Router = require('node-simple-router');
var router = Router();
var board = new five.Board();
var server = http.createServer(router);
server.listen(3000);
@rssilva
rssilva / karma-conf.js
Created May 6, 2016 18:31
Writing tests using Jasmine with Browserify, Babel and generating coverage with Istanbul
const istanbul = require( 'browserify-istanbul' )
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['browserify', 'jasmine'],
files: [
// 'js/**/*.js',
'js/utils/**/*.js',
'test/spec/*.js'
// Como o johnny five é um módulo Node.js, ele é carregado como qualquer outro
var five = require('johnny-five');
// Instanciamos uma placa, que neste caso será a do Arduino que se comunicará com o computador
var board = new five.Board();
// O evento de ready é disparado quando a comunicação é estabelecida entre o processo Node.js e o Arduino
board.on('ready', function() {
// Instanciamos um led no pino 13
var led = new five.Led(13);
var Human = function (name, age) {
return {
init: function () {
this.setName(name);
this.setAge(age);
},
setName: function (name) {
this.setName = name;
},
@rssilva
rssilva / example-require.js
Created October 22, 2013 17:57
A simple way to use Requirejs with Backbone, Underscore and Jquery. The different widgets and features can stay on different files and everything it'll be fine when you load require.js and the AppBootstrap.js files. After you can add the "page controller" script wich will load everything you need.
/*
* AppBootstrap.js - This file contains the path to Backbone, Underscore, Jquery and
*also the variables that which one will export
*/
/*global require*/
'use strict';
require.config({
shim: {
var numero = 10;
var Calculadora = function () {
this.soma = function (numero1, numero2) {
return numero1 + numero2
}