Skip to content

Instantly share code, notes, and snippets.

@astur
astur / SimpleHTTPServer
Created Apr 14, 2015
Easy share folder via http
View SimpleHTTPServer
$python -m SimpleHTTPServer 8000
@astur
astur / nodeserver.js
Created May 19, 2015
Node http/https server
View nodeserver.js
var fs = require('fs');
var express = require('express');
var https = require('https');
var http = require('http');
var app = express();
var options = {
//openssl genrsa 1024 > key.pem
key: fs.readFileSync('./key.pem'),
//openssl req -x509 -new -key key.pem > cert.pem
cert: fs.readFileSync('./cert.pem')
@astur
astur / vanilla_index.js
Created May 25, 2015
JQuery index in vanilla.js
View vanilla_index.js
function index(item, collection) {
return [].slice.call(document.querySelectorAll(collection)).indexOf(document.querySelector(item));
}
console.log(index('#item', '.collection'));
@astur
astur / icrawler-ferra.js
Last active Jun 9, 2016
Example of using icrawler to scrape data from Ferra.ru
View icrawler-ferra.js
var icrawler = require('icrawler');
var fs = require('fs');
var URL = 'http://www.ferra.ru/ru/techlife/news/';
var opts = {
errorsFirst: true,
concurrency: 10,
saveOnFinish: false,
saveOnCount: 500,
@astur
astur / icrawler-lis.js
Last active Jun 9, 2016
Example of using icrawler to scrape data from PuntoLIS.it
View icrawler-lis.js
var icrawler = require('icrawler');
var fs = require('fs');
var sCookie = 'http://www.puntolis.it/storelocator/defaultsearch.aspx?idcustomer=111'; // Only for cookies
var URL = 'http://www.puntolis.it/storelocator/buildMenuProv.ashx?CodSer=111'; // Start URL. List of 'provincia's
var sLoc = 'http://www.puntolis.it/storelocator/buildMenuLoc.ashx?CodSer=111&ProvSel=%s'; // List of 'localita's for every provincia (PROV)
var sMarker = 'http://www.puntolis.it/storelocator/Result.aspx?provincia=%s&localita=%s&cap=XXXXX&Servizio=111'; // (PROV, LOC)
var opts = {
errorsFirst: true,
@astur
astur / sha256.js
Created Apr 11, 2016
Easy sha256-for-object module
View sha256.js
var crypto = require('crypto');
module.exports = function (obj){
var str = JSON.stringify(obj);
return crypto.createHash('sha256').update(str).digest('base64');
};
@astur
astur / win-ctrl-c-graceful-shutdown.js
Created Apr 29, 2016
Graceful shutdown template for Ctrl-C with Windows support
View win-ctrl-c-graceful-shutdown.js
if (process.platform === 'win32') {
require('readline')
.createInterface({
input: process.stdin,
output: process.stdout
})
.on('SIGINT', function () {
process.emit('SIGINT');
});
}
@astur
astur / index.js
Created May 22, 2016
Ferra scraping (for Habr)
View index.js
var tress = require('tress');
var needle = require('needle');
var cheerio = require('cheerio');
var resolve = require('url').resolve;
var fs = require('fs');
var URL = 'http://www.ferra.ru/ru/techlife/news/';
var results = [];
var q = tress(function(url, callback){
@astur
astur / index.js
Last active Feb 20, 2018
LIS Map scraping (for Habr)
View index.js
var log = require('cllc')();
var tress = require('tress');
var needle = require('needle');
var cheerio = require('cheerio');
var fs = require('fs');
var sCookie = 'http://www.puntolis.it/storelocator/defaultsearch.aspx?idcustomer=111';
var sProv = 'http://www.puntolis.it/storelocator/buildMenuProv.ashx?CodSer=111';
var sLoc = 'http://www.puntolis.it/storelocator/buildMenuLoc.ashx?CodSer=111&ProvSel=%s';
var sMarker = 'http://www.puntolis.it/storelocator/Result.aspx?provincia=%s&localita=%s&cap=XXXXX&Servizio=111';
@astur
astur / index.js
Created Jul 15, 2016
tproger quotes scraping
View index.js
var needle = require('needle');
var log = require('cllc')();
var URL = 'https://tproger.ru/wp-content/plugins/citation-widget/getQuotes.php';
var count = 0;
var results = [];
log('Started');
log.start('%s quotes found');
You can’t perform that action at this time.