Skip to content

Instantly share code, notes, and snippets.

@nfabian13
nfabian13 / MyReactComponent.js
Created May 16, 2016 20:05 — forked from thmain/MyReactComponent.js
Skeleton React Component with descriptions for all of its lifecycle methods
/**
* @jsx React.DOM
*/
var React = require('react'),
MyReactComponent = React.createClass({
// The object returned by this method sets the initial value of this.state
getInitialState: function(){
return {};
@nfabian13
nfabian13 / collectionRecord.json
Created August 5, 2015 15:42
this is the structure of the documents of my database mongoDB collection (mongosails4.case)
{
"_id" : ObjectId("55a907962109d0860b71aff1"),
"appointment" : {
"appointment_time" : null,
"customer_requested_appointment_time" : null,
"label" : "",
"service_slot" : ""
},
"asset" : {
"in_service_date" : null,
@nfabian13
nfabian13 / main-ES2015.js
Last active October 1, 2015 08:01
this is the code to display a bitcoin price every 10 senconds and calculate the average of the last 5 prices retrieved from the HTTP resource.
let BitcoinPrices = [];
$(document).ready(function() {
let priceIntervalStream = Rx.Observable.interval(1000).flatMap( param => {
$('#cdDiv').html(param);
return getPriceStream();
});
priceIntervalStream.subscribe( x => {
$('#lbl-price').html(x.data.total.amount);
BitcoinPrices.push(x.data.total.amount);
var BitcoinPrices = [];
$(document).ready(function() {
var priceIntervalStream = Rx.Observable.interval(1000).flatMap(function (param){
$('#cdDiv').html(param);
return getPriceStream();
});
priceIntervalStream.subscribe(function(x){
$('#lbl-price').html(x.data.total.amount);
BitcoinPrices.push(x.data.total.amount);
@nfabian13
nfabian13 / main.js
Last active August 29, 2015 14:25
this is the code to display a bitcoin price every 10 senconds and calculate the average of the last 5 prices retrieved from the HTTP resource.
var BitcoinPrices = [];
function countdown() {
var count = 10;
setInterval(function() {
count--;
//display the countdown timer to UI
$('#cdDiv').html(count);
@nfabian13
nfabian13 / wordnikAPI
Created April 21, 2015 14:50
an example how to call the wordnik API using swagger.
<script src="~/lib/swagger-client.js" type='text/javascript'></script>
<script type="text/javascript">
$(document).ready(function () {
// initialize swagger, point to a resource listing
window.swagger = new SwaggerClient({
url: "http://api.wordnik.com/v4/resources.json",
success: function () {
swagger.apis.account.getLoggedInUser({username: 'myusername', password: 'mypass'}, function(data){
@nfabian13
nfabian13 / main.js.erb
Created March 10, 2015 23:40
Send a file to the other client
//To make this work include the RTCMulticonnection.js file
//create a connection object to handle the sending procress of a file.
var connection = new RTCMultiConnection();
document.getElementById('files').onchange = function() {
var file = this.files[0];
connection.send(file);
};
@nfabian13
nfabian13 / show.html.haml
Created March 10, 2015 23:29
Send message to all participants on Enter key pressed
//To send messages
var txtMsg = document.querySelector("#txtMsg")
$("#txtMsg").keydown(function(event){
if(event.keyCode == 13){
session.signal({
type: "chat",
data: txtMsg.value
}, function(error){
if(error){
@nfabian13
nfabian13 / rooms_controller.rb
Created March 10, 2015 23:25
generate the client token with the Ruby server SDK
#rooms_controller.rb
def show
@room = Room.find(params[:id])
@opentTok_token = @opentok.generate_token @room.session_id
end
@nfabian13
nfabian13 / show.html.haml
Created March 10, 2015 23:22
Creating Object Session and Connecto to the session
var apiKey = '45173502';
var sessionId = "#{@room.session_id}"
var token = '#{@opentTok_token}';
// Create a session object
var session = OT.initSession(apiKey, sessionId);
// connect to the session
session.connect(token, function(error) {
if (error) {