Skip to content

Instantly share code, notes, and snippets.

View labra's full-sized avatar

Jose Emilio Labra Gayo labra

View GitHub Profile
@labra
labra / marcela.js
Created December 3, 2016 15:32
Marcela
let marcela = {
"nombre": "Marcela",
"edad": 25 } ;
console.log(marcela);
console.log("Edad de marcela " + marcela.edad);
console.log("El año que viene tendrá " + (marcela["edad"] + 1));
var fs = require('fs');
fs.readdir("listados/", function(err, filenames) {
if (err) throw err;
filenames.forEach(function(filename) {
fs.readFile("listados/" + filename, 'utf-8', function(err, content) {
if (err) throw err;
console.log("Fichero: " + filename)
console.log(content)
});
const http = require('http'),
fs = require('fs'),
url = require('url'),
qs = require('querystring');
const server = http.createServer((req, res) => {
switch (req.method) {
case 'POST':
var body = '';
req.on('data', data => { body += data;
const http = require('http');
const fs = require('fs');
var personas;
fs.readFile("personas.json",'utf8', (err,datos) => {
if (err) throw err;
json = JSON.parse(datos);
console.log("Total personas:" + json.total);
personas = json.personas;
@labra
labra / fileForm.js
Last active October 20, 2016 14:53
const formidable = require('formidable'), fs = require('fs'), http = require('http')
http.createServer((req, resp ) => {
switch (req.method) {
case 'GET': pideFichero(req,resp); break;
case 'POST': procesaFichero(req,resp); break;
}}).listen(3000);
function procesaFichero(req,resp) {
var form = new formidable.IncomingForm();
<html><head><title>Formulario</title></head>
<body>
<h1>Procesa ficheros</h1>
<?php if ($_SERVER['REQUEST_METHOD'] == 'GET') : ?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>"
method="POST"
enctype="multipart/form-data">
<label>Nombre:
<input name="cliente"></label><br>
<label>Dame un fichero:
@labra
labra / local.scala
Last active September 1, 2016 08:13
Example of monad transformer stack...question on how to lift local
package examples
import cats._, data._
import cats.implicits._
object local {
type Env = Map[String,Int]
type MyState = List[Int]
type S[A] = EitherT[StateT[WriterT[Kleisli[List,Env,?],String,?],MyState,?], String, A]
@labra
labra / Implicitscats.scala
Created August 25, 2016 08:54
Example comparing behaviour of WriterT and StateT to find implicits
package example
import cats._, data._
import cats.implicits._
abstract class CheckerWriter {
type Config
type Err
type Log
implicit val logMonoid: Monoid[Log]
@labra
labra / Implicits.scala
Created August 25, 2016 05:25
Example that generates Null Pointer Exception trying to find implicits
package example
import cats._, data._
import cats.implicits._
abstract class Checker {
type Config
type Err
type Log
implicit val logMonoid: Monoid[Log]
@labra
labra / WriterTExample.scala
Last active August 22, 2016 07:43
Example using WriterT and liftT
package examples
import cats._, data._
import cats.implicits._
object writerTExample {
type Env = Int
type Err = String
type V[A] = Either[Err,A]
type ReaderV[A] = Kleisli[V,Env,A]