Skip to content

Instantly share code, notes, and snippets.

View alarrosa14's full-sized avatar

Alvaro Larrosa alarrosa14

View GitHub Profile
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid
@alarrosa14
alarrosa14 / delete_git_submodule.md
Created July 27, 2019 19:28 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@alarrosa14
alarrosa14 / local-mongo-replicaset-with-docker
Created March 14, 2019 20:56 — forked from oleurud/local-mongo-replicaset-with-docker
Local mongo replicaset with docker #docker #mongo
# pull the official mongo docker container
docker pull mongo
# create network
docker network create my-mongo-cluster
# create mongos
docker run -d --net my-mongo-cluster -p 27017:27017 --name mongo1 mongo mongod --replSet my-mongo-set --port 27017
docker run -d --net my-mongo-cluster -p 27018:27018 --name mongo2 mongo mongod --replSet my-mongo-set --port 27018
docker run -d --net my-mongo-cluster -p 27019:27019 --name mongo3 mongo mongod --replSet my-mongo-set --port 27019
@alarrosa14
alarrosa14 / scroll-listener.js
Created April 3, 2017 20:13
60FPS onscroll event listener
(function() {
var lastScrollY = 0;
var ticking = false;
var update = function() {
// do your stuff
ticking = false;
};
var requestTick = function() {
@alarrosa14
alarrosa14 / abbreviate.js
Last active August 2, 2018 12:41
Angular filter to abbreviate large numbers, optionally receiving the number of decimal places as parameter.
// Based in http://stackoverflow.com/a/2686098/4436816
//
// Usage examples:
// {{ 2134124 | abbreviate:2}} -> 2.13M
// {{ 2134124 | abbreviate }} -> 2M
// {{ 1000 | abbreviate }} -> 1K
myApp.filter('abbreviate', function() {
return function(number, decPlaces) {
@alarrosa14
alarrosa14 / Meter.ino
Created May 31, 2016 01:11 — forked from dernster/Meter.ino
ESP Sync Meter
#include "Arduino.h"
// Include API-Headers
extern "C" {
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
#include "cont.h"
@alarrosa14
alarrosa14 / mbed_sendero_synchronization_test.cpp
Created February 6, 2016 05:53
An app for the mBed that tests the Sendero ESP-8266 clock sinchronization.
#include "mbed.h"
InterruptIn device1(p11);
InterruptIn device2(p12);
InterruptIn device3(p13);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
@alarrosa14
alarrosa14 / artnet_middleware.py
Last active August 2, 2022 13:30
A Python ArtNet packet receiver that broadcasts its payload.
import sys
from socket import (socket, AF_INET, SOCK_DGRAM, SOL_SOCKET, SO_REUSEADDR,
SO_BROADCAST)
from struct import pack, unpack
UDP_IP = "127.0.0.1"
UDP_PORT = 6454
@alarrosa14
alarrosa14 / kmeans-master.c
Created October 10, 2015 22:38
A master-slave implementation of kmeans algorithm using PVM3.
#include <pthread.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <float.h>
#include <stdio.h>
#include <sys/types.h>
#include <pvm3.h>
#define CANT_SLAVES 20
@alarrosa14
alarrosa14 / kmeans-posix.c
Last active November 12, 2015 01:07
A Kmeans implementation using posix threads. Generates a Octave script to plot the output.
#include <pthread.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <float.h>
#include <stdio.h>
#include <sys/types.h>
#define CANT_THREADS 8