Skip to content

Instantly share code, notes, and snippets.

@plcgi1
plcgi1 / nightmare preload.txt
Last active August 2, 2017 08:18
nightmare preload
/* прирмер использлования скрипта для браузера - подключенного ко всем переходам nightmare*/
var Nightmare = require('nightmare');
const path = require('path');
var nightmare = new Nightmare({
"show": true,
"alwaysOnTop": false,
"typeInterval": 400,
"pollInterval": 1000,
@plcgi1
plcgi1 / Get keys count from redis
Last active May 15, 2017 20:00
Get keys count from redis
// http://stackoverflow.com/questions/9888387/print-number-of-keys-in-redis
eval “return #redis.call(‘keys’, ‘mbt*‘)” 0
// or
dbsize
var nightmare = new Nightmare({
"show": true,
"alwaysOnTop": false,
"switches": {
"ignore-certificate-errors": true
},
"allowDisplayingInsecureContent": true
});
var urls = ['http://ya.ru', 'https://moreboats.com'];
/**
*
* @param {Function} fn - source callback-based function
* @param {Function} ctx - context
*/
const promisifyMe = function( fn, ctx ) {
return function wrappped() {
var args = Array.prototype.slice.call( arguments );
return new Promise( function( resolve, reject ) {
var tempCallback = function( err, data ) {
@plcgi1
plcgi1 / async timeSeries example
Last active March 17, 2017 18:04
async timeSeries example
var async = require('async');
function createUser(id, callback) {
console.info('ITERATION', id);
callback(null, { id: 'user' + id });
}
async.times(5, function(n, next) {
createUser(n, function(err, user) {
next(err, user);
// module
(function(){
"use strict";
this.Calc = function () {
return Object.freeze({
add: function(x, y) { return x + y; },
div: function(x, y) { return x / y; },
version: 0.01,
});
window.Object.defineProperty( Element.prototype, 'documentOffsetTop', {
get: function () {
return this.offsetTop + ( this.offsetParent ? this.offsetParent.documentOffsetTop : 0 );
}
} );
window.Object.defineProperty( Element.prototype, 'documentOffsetLeft', {
get: function () {
return this.offsetLeft + ( this.offsetParent ? this.offsetParent.documentOffsetLeft : 0 );
}
@plcgi1
plcgi1 / fire click on pageb js
Created November 15, 2016 13:33
fire click on pageb js
function fireEvent(obj, evt){
var fireOnThis = obj;
if (document.createEvent) {
var evObj = document.createEvent('MouseEvents');
evObj.initEvent(evt, true, false);
fireOnThis.dispatchEvent(evObj);
} else if (document.createEventObject) {
fireOnThis.fireEvent('on' + evt);
}
@plcgi1
plcgi1 / mongo group by date
Last active October 14, 2016 16:28
mongo group by date
{
$match: {
date: {
$gte: criteria.startDate,
$lt: criteria.endDate
}
}
},
{
$project: {
@plcgi1
plcgi1 / index.html
Created September 19, 2016 06:17 — forked from anonymous/index.html
tristate checkbox
<div>
<span class="tristate tristate-checkbox">
<input type="radio" id="item1-state-off" name="item1" value="-1" checked>
<input type="radio" id="item1-state-null" name="item1" value="0">
<input type="radio" id="item1-state-on" name="item1" value="1">
<i></i>
<label for="item1-state-null">Выключено</label>
<label for="item1-state-on">Не задано</label>
<label for="item1-state-off">Включено</label>
</span>