Skip to content

Instantly share code, notes, and snippets.

View kaiquewdev's full-sized avatar

Kaique Silva kaiquewdev

View GitHub Profile
@kaiquewdev
kaiquewdev / projection.js
Created February 12, 2018 17:10
play a list with projection
'use strict'
const Browser = require('nodecast-js');
const timestamp = 60; // in seconds
const browser = new Browser();
let args = process.argv.slice(2);
let url = args[0];
var Browser = require('nodecast-js');
var url = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4';
var timestamp = 60; // in seconds
var browser = new Browser();
browser.onDevice(function (device) {
device.onError(function (err) {
console.log(err);
});
The Project Gutenberg EBook of Romeo and Juliet, by William Shakespeare
This eBook is for the use of anyone anywhere at no cost and with
almost no restrictions whatsoever. You may copy it, give it away or
re-use it under the terms of the Project Gutenberg License included
with this eBook or online at www.gutenberg.org/license
Title: Romeo and Juliet
The Project Gutenberg EBook of The Kama Sutra of Vatsyayana, by Vatsyayana
This eBook is for the use of anyone anywhere at no cost and with
almost no restrictions whatsoever. You may copy it, give it away or
re-use it under the terms of the Project Gutenberg License included
with this eBook or online at www.gutenberg.net
Title: The Kama Sutra of Vatsyayana
Translated From The Sanscrit In Seven Parts With Preface,
@kaiquewdev
kaiquewdev / jogo-dos-numeros.js
Last active February 27, 2017 22:54
Um dos primeiros exemplos do fth-cast.
#!/usr/bin/env node
// As regras do jogo são simples,
// Você vai jogar contra a maquina e
// Quem formar o numero 15 ganha.
// Mas para formar o numero 15,
// Você só pode adicionar 1, 2, 3
// Até somar 15. Passando disso é empate.
var placar = 0;
var maquinaComeca = !!( Math.max( 0, Math.round( Math.random() * 1 ) ) );
var maquinaJogando = false;

why ./task.js?

One word: task automation. It's basically zero effort and you can use the ./task.js package manager to handle any repetitive tasks. You can use ./task.js to automate everything with minimum effort.

./task.js provides the structure, order, and authority that you as a developer so desperately crave. ./task.js will also take responsibility for your actions if you need it to. It's what everybody is using now. ./task.js is the new hotness. It's all about ./task.js now, just like that.

This is compared to npm run/bash scripts, which are:

@kaiquewdev
kaiquewdev / watch.js
Created January 11, 2014 15:27
Exemplo de uma ferramenta para debug.
var spawn = require('child_process').spawn;
var fs = require('fs');
var args = process.argv.slice(2);
var program = null;
var filename = args[ 0 ];
function execHandler ( err, stdout, stderr ) {
if ( err ) console.log( 'error: %s', err );
if ( stdout ) console.log( 'stdout: ', stdout );
if ( stderr ) console.log( 'stderr: %s', stderr );
@kaiquewdev
kaiquewdev / hell.js
Last active January 2, 2016 00:09
Callback hell? Let me show you a trick.
// Promessas podem resolver a sua vida.
// Mas se o Javascript foi pensado desta forma, com a possibilidade
// de funções dentro de funções, então existiria algum recurso para resolver este problema?
// Bom, não tem um recurso especifico que vai fazer a sua vida mudar, mas com algum conhecimento
// sobre a linguagem, você acaba descobrindo que isso pode acontecer.
// Primeiro exemplo - #1
function sayHello () {

Why declaring globals is better than exporting

The module pattern

During the past several years the way of managing javascript dependencies evolved bringing some advanced solutions. One of the concepts which became very popular today, is a module pattern. The beginning of this article explains the idea pretty well. This concept was then reused in many modern dependency-management solutions, and was finally suggested as a specification of AMD API, the most known implementation of which is probably the RequireJS.

Exporting feature, the problems of which are discussed in this text, is part of the module pattern. Strictly speaking, the module pattern itself has no relation to the dependency resolution, it is rather designed for managing and storing the data in a special way. But it naturally integrates as a base for the dependency management libraries.

Strophe.addConnectionPlugin("xdomainrequest", {
init: function () {
if (window.XDomainRequest) {
Strophe.debug("using XdomainRequest for IE");
// override the send method to fire readystate 2
if (typeof XDomainRequest.prototype.oldsend == 'undefined') {
XDomainRequest.prototype.oldsend = XDomainRequest.prototype.send;
XDomainRequest.prototype.send = function() {
XDomainRequest.prototype.oldsend.apply(this, arguments);