Skip to content

Instantly share code, notes, and snippets.

View binario200's full-sized avatar

Victor Hernandez binario200

View GitHub Profile
@binario200
binario200 / build.gradle
Created November 9, 2017 20:50
Gradle Getting Started.
plugins {
id 'base'
}
task copy(type: Copy) {
from 'src'
into 'dest'
}
task zip(type: Zip) {
@binario200
binario200 / NodeHints.md
Last active May 6, 2018 02:41
node hints

Generators are function execution contexts that can be paused and resumed.

A Generator function will yield a value then stop but the function context of a Generator is not disposed of (as it is with normal functions). You can re-enter the Generator at a later point in time and pick up further results

function* threeThings() {
    yield 'one';
    yield 'two';
    yield 'three';
}
@binario200
binario200 / httpResponseCodes.md
Created October 18, 2017 04:46
http response codes

HTTP Response Codes

The HTTP specification contains a large number of response codes a server can return to calling clients. You can learn more about them on Wikipedia (http://en.wikipedia.org/wiki/List_of_HTTP_status_codes).

Although a dizzying number of response codes is possible, you’ll find yourself using a few of the more common responses in most of your applications:

• 200 OK—Everything went fine.

• 301 Moved Permanently—The requested URL has been moved, and the client should re-request it at the URL specified in the response.

@binario200
binario200 / fileServer.js
Created October 18, 2017 04:02
http server listing files providing the directory in nodejs
var http = require('http'),
fs = require('fs');
function load_file_list(callback) {
// this is the name of the folder you want inpect
fs.readdir("NodeJS", function (err, files){
if (err) {
callback(err);
return;
}
@binario200
binario200 / udpClient.js
Created October 17, 2017 04:40
UDP communication on NodeJS
var PORT = 33333;
var HOST = '127.0.0.1';
var dgram = require('dgram');
var message = new Buffer('My what is good');
var client = dgram.createSocket('udp4');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
if (err) throw err;
@binario200
binario200 / tcpClient.js
Created October 17, 2017 04:08
TCP Communication in NodeJS
var net = require('net');
var client = new net.Socket();
client.connect(6969, '127.0.0.1', function() {
console.log('loko are you connected');
client.write('Hello, server! here, client.');
});
client.on('data', function(data) {
@binario200
binario200 / nodejs-tcp-example.js
Created October 17, 2017 03:32 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@binario200
binario200 / JSRecipes.MD
Last active April 25, 2018 14:16
Javascript recipes

Copy an object but reseting its values

function skeleton(source, isArray) {
   var o = Array.isArray(source) ? [] : {};
   for (var key in source) {
      if (source.hasOwnProperty(key)) {
         var t = typeof source[key];
 o[key] = t == 'object' ? 
@binario200
binario200 / WebpackAndReact.md
Last active September 29, 2017 15:27
Webpack and React getting started guid

In a traditional React Web App you will need: ~/index.html src/index.js webpack.config.js server.js

Also install npm packages like

babel loader

@binario200
binario200 / .eslintrc
Last active September 28, 2017 16:05
Guide to implement ESLint in a React project.
{
"parser": "babel-eslint",
"env": {
"browser": true,
"es6": true,
"node": true,
"jquery": true
},
"plugins": [
"react"