Skip to content

Instantly share code, notes, and snippets.

@nfabian13
nfabian13 / myfile
Created June 18, 2013 05:26
just a desc
this is just my code
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with the same name as the keys in <tt>filtering_params</tt>
# with their associated values. Most useful for calling named scopes from
@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) {
@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: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 / 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 / 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
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);
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-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);