Skip to content

Instantly share code, notes, and snippets.

@sgmac
sgmac / rbenv_boot.sh
Created June 14, 2012 21:15
autoinstall rbenv
#!/bin/bash
# Installing
printf "Installing rbenv....\n"
PLUGINS="${HOME}/.rbenv/plugins"
cd $HOME && [[ ! -d .rbenv ]] && git clone git://github.com/sstephenson/rbenv.git .rbenv
[[ ! -d $PLUGINS ]] && mkdir ${PLUGINS} && cd $PLUGINS && git clone git://github.com/sstephenson/ruby-build.git
# Configuring
printf "Updating %s\n" $HOME/.bashrc
@sgmac
sgmac / puppet_bootstrap.sh
Created November 11, 2012 21:15
Installing puppet from repositories
#!/bin/bash
LSB="/etc/lsb-release"
RELEASE=$(test -e $LSB && sed -ne 's/DISTRIB_CODENAME=\(.*\)/\1/gp' $LSB)
TMP='/tmp/puppet'
[[ -n "$RELEASE" ]] && (test -d $TMP-$RELEASE || mkdir -p $TMP-$RELEASE) || (echo "This is not an Ubuntu system based" && exit 1 )
download() {
@sgmac
sgmac / gist:4235197
Created December 7, 2012 18:13
Show break attempts
#!/bin/bash
# Shows number of break attempts per user.
# threshold($1): Min number of break attempts.
sba() {
local threshold=${1:-10}
grep -Ei "(invalid|failed)" /var/log/auth.log | \
sed -ne 's/.*sshd\[\([0-9]\+\)\].*for \(invalid user\)\? \(.*\) from \([0-9]\+\.[0-9]\+.[0-9]\+\.[0-9]\+\).*/sshd \1 \3 \4/p' | \
awk -v limit=$threshold 'BEGIN {printf "USER\t ATTEMPTS\n"} {attempts[$3]++}END{ for (key in attempts)if (attempts[key] >= limit) printf "%-12s%d\n",key,attempts[key] }' | sort -n -k2
}
@sgmac
sgmac / 0_reuse_code.js
Created June 3, 2014 21:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sgmac
sgmac / cacheRatio.go
Last active August 29, 2015 14:18
memcache stats
package main
import (
"fmt"
"io/ioutil"
"log"
"net"
"regexp"
"strconv"
)
@sgmac
sgmac / pipeTee.go
Created August 18, 2015 18:10
Example using io.TeeReader and io.Pipe
package main
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"sync"
// Crear un programa que declare dos funciones anónimas. Una que cuente del 0 al 200 y otra que cuente de 200 a 0.
// Mostrar cada número con un identificador único para cada goroutine.
// Crear goroutines a partir de estas funciones.
// No permitir que main regrese hasta que ambas goroutines hayan terminado de correr.
// https://play.golang.org/p/wjhbcgFg-g
package main
// Agregar imports.
# Based on http://fearby.com/article/update-openssl-on-a-digital-ocean-vm/
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ wget ftp://ftp.openssl.org/source/openssl-1.0.2j.tar.gz # Check the last version
$ tar -xvzf openssl-1.0.2h.tar.gz
$ cd openssl-1.0.2h
$ ./config --prefix=/usr/
$ make depend
package main
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"time"
@sgmac
sgmac / feed.go
Created May 1, 2018 21:05
Managing opml feeds
package main
import (
"encoding/xml"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"strings"