Skip to content

Instantly share code, notes, and snippets.

View fbn4sc's full-sized avatar

Fábio Nascimento fbn4sc

View GitHub Profile
@fbn4sc
fbn4sc / command.txt
Created January 29, 2018 01:35
Delete all branches except master and develop.
git branch | grep -v "master\|develop" | xargs git branch -D
@fbn4sc
fbn4sc / program.js
Created January 26, 2018 01:16
Stream the contents of a file via http
const http = require("http");
const fs = require("fs");
const server = http.createServer((req, res) => {
fs
.createReadStream(process.argv[3])
.on("data", data => res.write(data))
.on("end", () => res.end());
});
@fbn4sc
fbn4sc / program.js
Last active January 25, 2018 01:31
Fetchs data from a given url.
const http = require("http");
const url = process.argv[2];
http.get(url, response => {
response.setEncoding("utf8");
response.on("data", data => console.log(data));
});
@fbn4sc
fbn4sc / program.js
Created January 23, 2018 23:53
Filter files by extension.
const fs = require("fs");
const dir = process.argv[2];
const ext = process.argv[3];
fs.readdir(dir, (error, files) => {
if (error) throw error;
const re = new RegExp(`\.${ext}$`);
files.map(file => {
@fbn4sc
fbn4sc / app.js
Created January 23, 2018 17:36
An example of the split method.
const arr = ('1,2,3').split(',')
//arr equals [ 1, 2, 3 ]