Skip to content

Instantly share code, notes, and snippets.

Avatar

Alan Hoffmeister alanhoff

View GitHub Profile
@alanhoff
alanhoff / proxy.js
Last active Aug 29, 2015
Proxy transparente para debug
View proxy.js
var https = require('https');
var old = 'https://app.astandes.com.br:8443';
var url = require('url');
var util = require('util');
var fs = require('fs');
var log = function(data, inout){
inout = inout ? inout + ' ' : '';
data = inout + data.trim().replace(/\n/g, inout);
if(data)
View download.js
var fs = require('fs');
var path = require('path');
require('http').Server(function(req, res) {
if (!fs.existsSync(req.url)) {
res.statusCode = 404;
res.end();
}
var name = path.basename(req.url);
View proxydebug.js
require('http').Server(function(req, res){
console.log('%s %s', req.method, req.url);
var data = '';
req.on('data', function(buff){
data += buff;
});
req.on('end', function(){
console.log(data);
View Makefile
# Proxies tasks to Grunt, so we don't need to install Grunt
# globaly on Unix machines.
%:
./node_modules/.bin/grunt $(MAKECMDGOALS)
.PHONY: test
@alanhoff
alanhoff / app.js
Created Oct 6, 2014
Enviar arquivo como anexo de um form-data
View app.js
var fs = require('fs');
var path = require('path');
var os = require('os');
var cuid = require('cuid');
var request = require('request');
var Bluebird = require('bluebird');
Bluebird.resolve().then(function(){
console.log('Baixando captcha.');
View gist:8d850ee4fcf098f91acd
{
"auto_complete": true,
"bold_folder_labels": true,
"color_scheme": "Packages/User/Monokai (SL).tmTheme",
"detect_slow_plugins": false,
"dictionary": "Packages/Dictionaries/Portuguese (Brazilian).dic",
"drag_text": false,
"ensure_newline_at_eof_on_save": true,
"font_face": "Monaco",
"font_options": "subpixel_antialias",
View como-usar.js
var user = require('./userSchema');
user.validate({password: 'alan', email: 'huehue@br.br'}, function(err, data){
if(err)
throw err;
//gravar o data no banco de dados
db.insert(data);
});
@alanhoff
alanhoff / example.js
Created Sep 29, 2014
Fazendo requests com jar global e jar individual
View example.js
var request = require('./request-helper');
// Fazer uma requisição utilizando a jar global, que é compartilhada
// em todo o Node.js que está rodando
request.global({
url: 'https://google.com.br'
}, function(err, res, body){
if(err)
throw err;
@alanhoff
alanhoff / request-proxy.js
Created Sep 29, 2014
request.js com proxy
View request-proxy.js
var request = require('request');
var options = {
url: 'https://portaldocidadao.saude.gov.br/portalcidadao/validaNumeroCNS.htm',
proxy: 'http://huehuebr.com.br'
};
request(options, function (err, res, body) {
if(err)
throw err;
@alanhoff
alanhoff / ssl-disabled.js
Last active Aug 29, 2015
request.js sem veirificação de SSL
View ssl-disabled.js
var request = require('request');
var options = {
url: 'https://portaldocidadao.saude.gov.br/portalcidadao/validaNumeroCNS.htm',
proxy: 'http://huehuebr.com.br',
strictSSL: false
};
request(options, function (err, res, body) {
if(err)
throw err;