Skip to content

Instantly share code, notes, and snippets.

@astur
astur / react-redux-bp.js
Last active Dec 31, 2017
Boilerplate for small React+Redux app
View react-redux-bp.js
//ACTION_CREATORS
const actions = {
setText: function(text){
return{
type: 'SET_TEXT',
text: text
}
},
inc: function(){
@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 / 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 / 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 / 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 / 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 / SimpleHTTPServer
Created Apr 14, 2015
Easy share folder via http
View SimpleHTTPServer
$python -m SimpleHTTPServer 8000