Skip to content

Instantly share code, notes, and snippets.

@rduque1
rduque1 / svg-image2.js
Created November 8, 2017 14:04 — forked from iwek/svg-image2.js
D3js click function to save SVG as dataurl in IMG tag, load into CANVAS and save as PNG dataurl, and auto download the actual PNG file.
d3.select("#save").on("click", function(){
var html = d3.select("svg")
.attr("version", 1.1)
.attr("xmlns", "http://www.w3.org/2000/svg")
.node().parentNode.innerHTML;
//console.log(html);
var imgsrc = 'data:image/svg+xml;base64,'+ btoa(html);
var img = '<img src="'+imgsrc+'">';
d3.select("#svgdataurl").html(img);
@rduque1
rduque1 / s3Sync.sh
Created June 24, 2018 01:52 — forked from kellyrmilligan/s3Sync.sh
Sync files to s3 and set cache control headers
#!/bin/bash
if [[ "$1" != "" ]]; then
S3BUCKETNAME="$1"
else
echo ERROR: Failed to supply S3 bucket name
exit 1
fi
aws s3 sync build s3://$S3BUCKETNAME --delete --cache-control max-age=31536000,public
@rduque1
rduque1 / get-latest-tag-on-git.sh
Created January 29, 2020 10:00 — forked from rponte/get-latest-tag-on-git.sh
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@rduque1
rduque1 / git-tag-delete-local-and-remote.sh
Created January 29, 2020 10:00 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@rduque1
rduque1 / create_loop_delete.sh
Last active October 4, 2020 15:19 — forked from nashjain/delete_all_aws_s3_object_versions.sh
Let's assume you backup a file every hour on AWS S3 and you want to clean up versions that are older than a week. However for the older versions, you want to leave one version per day just in case if you need them. Following script does that for you.
for id in `(cat toDel.txt)`; do echo "aws --profile wasabi s3 --endpoint-url=<endpoint> rm --recursive s3://<bucket>/id_$id/"; done
@rduque1
rduque1 / iptables.sh
Created February 23, 2021 12:50 — forked from Tristor/iptables.sh
Simple IPtables script for an OpenVPN server
#!/bin/bash
# Flushing all rules
iptables -F FORWARD
iptables -F INPUT
iptables -F OUTPUT
iptables -X
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
@rduque1
rduque1 / docker-healthcheck.md
Created March 16, 2021 13:27 — forked from shotgunner/docker-healthcheck.md
How to view docker healthcheck logs?

How to see healthcheck Logs ?

Use docker inspect is different in swarm mode and normal mode if you wnat to use it in swarm mode:

  • Manager nodes: use this command for services. (but if you want to see healthceck logs of specific container see worker nodes section):

    • docker inspect --format "{{json .Spec.TaskTemplate.ContainerSpec.Healthcheck }}" hinava_dashboard |jq
  • Worker nodes: you should use complete name of the container that completed with <tab> key

  • docker inspect hinava_filebeat.1.umvobmm9wrjdz1b08y5jibvl2 | grep -B 10 -A 10 "health"
@rduque1
rduque1 / pearson-correlation.js
Created June 9, 2021 16:06 — forked from matt-west/pearson-correlation.js
Pearson Correlation (JavaScript)
/**
* @fileoverview Pearson correlation score algorithm.
* @author matt.west@kojilabs.com (Matt West)
* @license Copyright 2013 Matt West.
* Licensed under MIT (http://opensource.org/licenses/MIT).
*/
/**
* Calculate the person correlation score between two items in a dataset.
@rduque1
rduque1 / nodejs-tcp-example.js
Created February 22, 2022 12:08 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@rduque1
rduque1 / parallel
Created June 29, 2022 13:46 — forked from mjambon/parallel
bash: Run parallel commands and fail if any of them fails
#! /usr/bin/env bash
#
# Run parallel commands and fail if any of them fails.
#
set -eu
pids=()
for x in 1 2 3; do