Skip to content

Instantly share code, notes, and snippets.

Avatar

Alan Hoffmeister alanhoff

View GitHub Profile
View server.js
const http = require('http');
const httpProxy = require('http-proxy');
const proxy = httpProxy.createProxyServer({
target: {
host: 'pulsar-host',
port: 8080
}
});
View main.rs
extern crate actix;
extern crate tokio;
use actix::io::{WriteHandler, Writer};
use actix::prelude::*;
use actix::{Actor, Addr, Context, Handler, Syn};
use tokio::io;
use tokio::io::{ReadHalf, WriteHalf};
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::stream::Stream;
@alanhoff
alanhoff / index.js
Created Dec 2, 2017
Rust and WebAssembly error
View index.js
const rust = require('rustify');
const wasm = rust`
use std::ffi::{CString};
use std::os::raw::{c_char};
#[no_mangle]
pub extern "C" fn str_len(ptr: *mut c_char) -> usize {
unsafe {
let string = CString::from_raw(ptr);
string.to_bytes().len()
View async.js
async function fazerAlgo() {
const resposta = await request('https://google.com.br')
await fs.writeFile('resposta.html', resposta)
const resposta2 = await request('https://facebook.com')
await fs.writeFile('resposta2.html', resposta2)
console.log('Todas as respostas foram salvas!')
}
View semaforo.js
var semaforo = 0
var valores = ['hello', 'world']
function callback () {
semaforo--
if (semaforo === 0) {
console.log('Acabou tudo o que tinha pra fazer, vou finalizar')
process.exit()
} else {
View crypto.js
'use strict'
const crypto = require('crypto')
/**
* Encripta dados utilizando o cipher camellia256
* @param {String} data dados a serem encriptados
* @param {String} encoding utf8, base64 ou hex
* @param {String} output base64 ou hex
* @return {String} O resultado da encriptação com o output selecionado
View index.js
function hello () {
return new Promise((resolve) => {
setTimeout(() => resolve('Hello world!'), 100)
})
}
View test.js
const nsq = require('nsq')
const crypto = require('crypto')
module.exports = async (req, res) => {
async validarAuth(req.header.authentication)
// Depois de validar iniciar a escuta em uma fila única para essa request
const replyQueue = crypto.randomBytes(30).toString('hex')
nsq.on(replyQueue, data => {
res.json(data)
View test.js
const path = require('path')
const glob = require('glob')
glob.sync('minha_pasta/**/arquivo.js').forEach(caminho => require(path.normalize(__dirname, caminho)))
You can’t perform that action at this time.