Skip to content

Instantly share code, notes, and snippets.

View miguelcnf's full-sized avatar

Miguel Fonseca miguelcnf

View GitHub Profile
@miguelcnf
miguelcnf / rollback.go
Last active January 29, 2021 20:56
Idiomatic, simple, defer-based rollback mechanism https://play.golang.org/p/p28rpnpiUcL
package main
import (
"errors"
"log"
)
// rollback function
func rollback(rollbackCtrl *bool, rollbackFunc func()) {
if *rollbackCtrl {
@miguelcnf
miguelcnf / main.rs
Last active August 14, 2020 18:01
Raw notes taken during the udemy The Rust Programming Language course by Dmitri Nesteruk
#![allow(dead_code)]
use std::collections::{HashMap, HashSet};
use std::mem;
fn main() {
println!("Hello, world!");
// test_vars();
// test_operators();
// test_constants();
@miguelcnf
miguelcnf / ssh-deploy-key
Created September 23, 2013 00:49
Perl script to iterate through a list of hosts and deploy an ssh public key without having to enter the same user password each and every time.
#!/usr/bin/env perl
#
# Usage: ssh-deploy-key -h (--hostsfile) PATH_TO_HOSTS_FILE
# -p (--pubkeyfile) PATH_TO_PUBKEY_FILE
# [ -u (--user) USER ]
#
# Expects --hostsfile to contain 1 host per line
# Assumes current user if --user is not given
#
<HEADER>
<TITLE>The World Wide Web project</TITLE>
<NEXTID N="55">
</HEADER>
<BODY>
<H1>World Wide Web</H1>The WorldWideWeb (W3) is a wide-area<A
NAME=0 HREF="WhatIs.html">
hypermedia</A> information retrieval
initiative aiming to give universal
access to a large universe of documents.<P>
@miguelcnf
miguelcnf / heap-usage-with-util-console
Last active August 29, 2015 14:24
node winston heap usage under load measured with memwatch
{ nodes: 42444,
time: Mon Jul 06 2015 16:36:48 GMT+0100 (WEST),
size_bytes: 7244456,
size: '6.91 mb' }
{ nodes: 45852,
time: Mon Jul 06 2015 16:36:48 GMT+0100 (WEST),
size_bytes: 7755120,
size: '7.4 mb' }
{ num_full_gc: 145,
num_inc_gc: 105,
@miguelcnf
miguelcnf / influxdb.conf
Created July 1, 2015 19:16
influxdb_0_9_cluster_config
reporting-disabled = true
[admin]
bind-address = ":8083"
enabled = true
[cluster]
shard-writer-timeout = "5s"
[continuous_queries]
@miguelcnf
miguelcnf / plusLargeData.js
Created June 30, 2015 15:52
node util.format performance test
#!/usr/bin/env node
var fs = require('fs');
fs.readFile('urandomStrings', 'utf8', function (err,data) {
if (err) {
return console.log(err);
} else {
console.time('concat');
var string = '';
@miguelcnf
miguelcnf / ping_packet_loss
Created May 18, 2015 17:53
Measure packet loss between hosts and push it as a gauge to statsd every 5 seconds.
#!/usr/bin/env bash
DST_IP=XXX.XXX.XXX.XXX
SRC_IP=$(/sbin/ip -f inet addr | grep inet | grep -v 127.0.0.1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $1}')
PACKET_LOSS=$(/bin/ping -w 4 -q $DST_IP | tail -2 | awk -F ' ' '{print $6}' | awk -F '%' '{print $1}' | grep -v '^$')
SANITIZED_DST_IP="${DST_IP//./_}"
SANITIZED_SRC_IP="${SRC_IP//./_}"
METRIC_PREFIX=""
require 'chef/provisioning'
with_driver 'aws'
with_machine_options :bootstrap_options => {
:security_group_ids => ["#{ENV['AWS_SECURITY_GROUP']}"],
:key_name => "#{ENV['AWS_KEY_NAME']}",
:image_id => "#{ENV['AWS_IMAGE_ID']}"
},
:ssh_username => "#{ENV['AWS_SSH_USERNAME']}"
#!/usr/bin/env bash
######
# CPU
######
if [ $# -lt 2 ]
then
echo "Missing arguments"
echo "Usage:"