Skip to content

Instantly share code, notes, and snippets.

var request = require('request');
var cheerio = require('cheerio');
// use [] ao invés de Array()
var posts = [];
// Iniciando o request principal
request('http://www.hardmob.com.br/promocoes', function teste(error, response, html) {
if (error || response.statusCode !== 200)
throw error | new Error('status code ', + response.statusCode);
@alanhoff
alanhoff / url2base64.js
Last active June 21, 2020 19:57
Conversor de imagem em base64
var http = require('http');
var path = require('path');
var url = require('url');
// Pegando a imagem na internet
http.get(url.parse(process.argv[2]), function(res){
var img = '';
res.on('data', function(buff){
img += buff.toString('base64');
@alanhoff
alanhoff / center.html
Created June 6, 2014 13:26
Centralizar uma div na tela
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Centralizando divs</title>
</head>
<body>
<div id="youtube" style="width: 560px; height: 315px;">
<iframe width="560" height="315" src="//www.youtube.com/embed/DDpSUqjtrRk?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
var gulp = require('gulp');
var connect = require('gulp-connect');
var livereload = require('gulp-livereload');
var watch = require('gulp-watch');
gulp.task('connect', function() {
connect.server({
root : __dirname
});
});
#!/bin/bash
git add . --all
git commit -am "$2"
git push $1 master
var fs = require('fs');
var speed = require('./speedometer');
var write = fs.createWriteStream('./dump.bin');
var read = fs.createReadStream('/dev/urandom');
var measure = speed(write, 1000);
measure.on('speed', function(bytes){
console.log(bytes + ' bytes per seconds');
});
@alanhoff
alanhoff / marked.js
Created June 16, 2014 06:44
marked.js
/*
* angular-marked v0.0.1
* (c) 2013 J. Harshbarger
* License: MIT
*/
/* jshint undef: true, unused: true */
/* global angular:true */
/* global marked:true */
var text = 'Seitan XOXO meh cornhole, before they sold out mustache scenester photo booth. IPhone selvage Pitchfork aesthetic. Polaroid post-ironic Thundercats quinoa, roof party PBR mumblecore cred +1 semiotics scenester freegan organic Godard. Cred Banksy meggings actually, Helvetica kogi gluten-free fap ethical slow-carb flexitarian before they sold out four loko. Fixie ugh yr single-origin coffee mustache. Mumblecore cardigan Helvetica mlkshk iPhone. Biodiesel synth pug Banksy mustache food truck McSweeney\'s, Intelligentsia post-ironic whatever ethnic dreamcatcher.';
var cut = function(text, max, delimiter){
return text.split(' ').reduce(function(arr, word){
if(!Array.isArray(arr))
arr = [new Buffer(arr)];
if(Buffer.concat([arr[arr.length -1], new Buffer(' ' + word)]).length > max)
arr.push(new Buffer(word));
else
var download = require('./lib/download');
download('http://meuarquivolocodedoido.com.br/arquivo.txt', './downloads')
.then(function(id){
console.log('Arquivo gravado com id %s', id);
})
.catch(function(err){
console.log('Deu pau..');
console.log(err.stack);
});
var httpProxy = require('http-proxy');
var http = require('http');
var domain = require('domain');
var proxy = httpProxy.createProxyServer();
// Criamos um server normal para escutar na porta 80
var server = http.createServer();
// Um objeto com o nome dos domínios que podemos
// redirecionar.