Skip to content

Instantly share code, notes, and snippets.

View ndvbd's full-sized avatar

ndvb ndvbd

  • Self
View GitHub Profile
def sinc_interp(x, s, u):
"""
Interpolates x, sampled at "s" instants
Output y is sampled at "u" instants ("u" for "upsampled")
"""
if len(x) != len(s):
raise Exception, 'x and s must be the same length'
@ndvbd
ndvbd / approx_sinc_interp.py
Created March 7, 2017 13:12
Upsampling - Approximated Sinc Interpolation in Python
# Written by Nadav Benedek
import numpy as np
from numba import jit, autojit
import scipy
@jit(nopython=True)
def approx_sinc_interp(x, s, u):
MAX_ELEMENTS_TO_TAKE_EACH_SIDE = 20 # Change this number to change the accuracy
result = np.empty(len(u))
@ndvbd
ndvbd / SparseConnectedComponents.cpp
Created October 19, 2017 14:42
SparseConnectedComponents - Efficient Algorithm for Finding the Connected Components of Binary OpenCV Mat and Compute Their Center of Mass
// Written by Nadav Benedek 2017
#include "SparseConnectedComponents.h"
#include <iostream>
#include "opencv2/opencv.hpp"
SparseConnectedComponents::SparseConnectedComponents() {
}
@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:
@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 / 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 / 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 / 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 / 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 / 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);
}