Skip to content

Instantly share code, notes, and snippets.

View emilioriosvz's full-sized avatar
🍍

Emilio Rios emilioriosvz

🍍
View GitHub Profile
@emilioriosvz
emilioriosvz / index.js
Created December 17, 2018 16:25
Simple example of how stream transforms work
const { createReadStream, createWriteStream } = require('fs')
const { Transform } = require('stream')
const stream = createReadStream('./text.txt')
const writeStream = createWriteStream('./result.txt')
const transformStream = new Transform({
transform (chunk, encoding, done) {
let text = String(chunk)
text = text.toLowerCase().replace(/hola/g, 'adiós')
done(null, text)
@emilioriosvz
emilioriosvz / README.md
Created December 13, 2018 19:12
AT Commands to connect to Wifi (ESP8266)
AT
AT+CIOBAUD=9600
AT+GMR
AT+CWMODE?
AT+CWMODE=3
AT+CWMODE?
AT+CWLAP
AT+CWJAP="wifi_SSID","your_wifi_password"
AT+CIPMUX=1
@emilioriosvz
emilioriosvz / README.md
Last active December 12, 2018 10:37
How to install GDAL 2.3 in Amazon Linux
sudo yum -y update
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --enable epel
sudo yum -y install make automake gcc gcc-c++ libcurl-devel proj-devel geos-devel
cd /tmp
curl -L http://download.osgeo.org/gdal/2.0.0/gdal-2.3.2.tar.gz
tar -xvzf gdal-2.3.2.tar.gz
cd gdal-2.3.2/
./configure --prefix=/usr/local --without-python
@emilioriosvz
emilioriosvz / node-targz.js
Created May 10, 2018 07:30
Node targz example
var fs = require('fs');
var fstream = require('fstream')
var tar = require('tar');
var zlib = require('zlib');
var gzip = zlib.createGzip();
//var deflate = zlib.createDeflate();
var dirSrcName = process.argv[2] || __dirname;
var dirDestName = process.argv[3] || './dir.tar.gz'
var dirDestStream = fs.createWriteStream(dirDestName);
@emilioriosvz
emilioriosvz / Finiquito.md
Last active May 10, 2018 07:31
finiquito or not

RUN

npx https://gist.github.com/emilioriosvz/8ce9745e98276f4a288bad062d6f01b3

@emilioriosvz
emilioriosvz / readline.js
Created May 2, 2018 12:55
readline sample
var rl = readline.createInterface({
input: fs.createReadStream(filePath),
crlfDelay: Infinity
})
rl.on('line', async (line) => {
counter += 1
rl.pause()
// some async code
rl.resume()
@emilioriosvz
emilioriosvz / mongoose-connection.js
Created April 4, 2018 09:40
connect with mongoose using async/await
const mongoose = require('mongoose')
mongoose.Promise = Promise
mongoose.connection.on('connected', () => {
console.log('Connection Established')
})
mongoose.connection.on('reconnected', () => {
console.log('Connection Reestablished')
@emilioriosvz
emilioriosvz / rabbitasyncawait.js
Created September 7, 2017 12:04
rabbitmq async await
var amqp = require('amqplib')
var open = require('amqplib').connect('amqp://localhost');
const connect = (url = 'amqp://localhost') => {
return new Promise((resolve, reject) => {
amqp.connect(url)
.then(conn => resolve(conn))
.catch(err => reject(err))
})
@emilioriosvz
emilioriosvz / asyncGreater.js
Last active May 10, 2018 07:32
Simple example to understand async await
#!/usr/bin/env node
const getName = name => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(name)
}, 500)
})
}
@emilioriosvz
emilioriosvz / objectComparator.js
Last active July 31, 2017 12:00
Object Comparator
const objectComparator = (a, b) => {
if (a === b) {
return {
changed: 'equal',
value: a
}
}
var value = {}
var equal = true