Skip to content

Instantly share code, notes, and snippets.

View ndvbd's full-sized avatar

ndvb ndvbd

  • Self
View GitHub Profile
@ndvbd
ndvbd / code_coverage.py
Created June 14, 2021 12:38
Process multiple google chrome debugger tools code coverage jsons in ordet to extract effective source
import json
import re
# code_coverage_filename =
# Will merge all this files
code_coverage_filenames = ['Coverage-20210613T181747.json', 'Coverage-20210613T1817427.json']
specific_file_url = 'https://localhost/bootstrap.min.self.css?body=1'
// 10, 11 are the ones -> keydown, keypress
var toRun = new Array(46);
for (var i = 0; i < toRun.length; ++i) { toRun[i] = true; }
function setupListeners(from, to) {
'use strict';
window.addEventListener('error', function (e) {e.preventDefault();e.stopPropagation();}, false);
let handlers = ['copy', 'cut', 'paste', 'beforeunload', 'blur', 'change', 'click', 'contextmenu', 'dblclick', 'focus', 'keydown', 'keypress', 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'resize', 'scroll', 'selectstart',
@ndvbd
ndvbd / event-listeners.js
Created June 9, 2018 13:34
Get all event listeners on the page in Google Chrome
// Taken from https://gist.github.com/danburzo/9254630
var items = Array.prototype.slice.call(
document.querySelectorAll('*')
).map(function(element) {
var listeners = getEventListeners(element);
return {
element: element,
listeners: Object.keys(listeners).map(function(k) {
return { event: k, listeners: listeners[k] };
})
@ndvbd
ndvbd / gist:86cd48490b98a27b9a1e5636bba614e2
Created May 4, 2018 08:48
Search everything in a javascript object
// Invoke with prefixpath = '', stackdepth = 0, maxdepth = 5
function searchObject(obj, textToSearch, prefixpath, stackdepth, maxdepth){
if (stackdepth >= maxdepth) return;
for (var key in obj) {
try {
if (obj.hasOwnProperty(key)) {
if (key.includes(textToSearch)) {
console.log(prefixpath + "/" + key + " key is: " + (typeof key) + " " + key);
}
@ndvbd
ndvbd / simple_jmeter_get_script.jmx
Created March 12, 2018 10:13
Simple JMeter Concurrent Get Script
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="4.0" jmeter="4.0 r1823414">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
@ndvbd
ndvbd / runtask.sh
Created March 10, 2018 21:14
Running Rails Rake task from any user in any folder, by detecting the RVM environment
#!/bin/bash
# By default, passenger will run your app as the user who owns the config/environment.rb or config.ru file: https://stackoverflow.com/questions/4231711/what-user-is-running-my-rails-app
RAILS_USER=$(stat -c '%U' /YOUR_PATH_HERE/environment.rb)
echo "Detected rails user: $RAILS_USER"
sudo -H -u $RAILS_USER bash -c 'RAILS_USER=$USER; echo "I am $USER, with uid $UID" ; echo "whoamI: $(whoami)" ; echo "Running rvm script: /home/$RAILS_USER/.rvm/scripts/rvm" ; source /home/$RAILS_USER/.rvm/scripts/rvm ; ENV_FILE=`rvm env --path` ; echo $ENV_FILE ; source $ENV_FILE ; cd /YOUR_PATH_HERE/lib/tasks ; rake XXX:YYY RAILS_ENV=production'
@ndvbd
ndvbd / wrapWordSegmentWithElement
Created March 7, 2018 10:52
wrapWordSegmentWithElement | Parse the text out of a DOM element, and wrap a specific part of the text with a supplied wrapper element
/**
* This wraps the extracted text segment with a parent wrapper element.
* If the desired text segement is spread around few nodes, than it will wrap
* EACH one of the nodes with the same parent wrapper.
* As always, the startPosition is inclusive and the endPosition is exclusive
* rootNode - must be a DOM element (not a jquery element)
*/
function wrapWordSegmentWithElement(rootNode, startPosition, endPosition, emptyWrapperElement){
var n, text='', walk=document.createTreeWalker(rootNode, NodeFilter.SHOW_TEXT, null, false);
while (n = walk.nextNode()) {
@ndvbd
ndvbd / ThrottledExecutor
Created March 4, 2018 13:44
ThrottledExecutor | Throttling functions invocations, and allowing only recent invocation to be made. | Javascript
// We want to define a throttledExecutor an object that constructs with a number, which is delay in seconds
// The object has one method: invokeThrottled, that accepts a function.
// The object remembers the last invocation time of the function (any function) - only one number to remember.
// If a function wasn't executed during the last 2 seconds, execute immediately.
// Otherwise, wait until 2 seconds will pass and execute the function
// If during the wait a new invocation arrived, forget about the old pending invocation (only remember the newest).
class ThrottledExecutor{
constructor(delayInSeconds){
this.delayInSeconds = delayInSeconds;
@ndvbd
ndvbd / main.cpp
Last active January 30, 2018 09:05
NadavWatch - View a sequence of PNG files in a directory, allow zoom, pixel values and more.
/*///////////////////////////////////////////////////////////////////////////////////////
//
// NadavWatch
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
@ndvbd
ndvbd / StopWatch
Last active October 24, 2017 08:27
CPP StopWatch
// Written by Nadav Benedek 2017
class StopWatch {
private:
double accumulatedTimeSeconds = 0;
double startTime = 0;
enum State {NONE, START, PAUSE, RESUME, STOP};
State state;
public: