Skip to content

Instantly share code, notes, and snippets.

View bcap's full-sized avatar

Bruno Penteado bcap

  • London, United Kingdom
View GitHub Profile
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@bcap
bcap / go-profile.sh
Last active May 22, 2023 23:05
small script to capture profiling data from a go process. The process needs to have the pprof web handler installed (https://pkg.go.dev/net/http/pprof)
#!/bin/bash
FLAMEGRAPH_PATH="${FLAMEGRAPH_PATH:-$HOME/code/github.com/brendangregg/FlameGraph/}"
SECONDS=10
GEN_PROFILE=true
GEN_GOROUTINE=false
GEN_BLOCK=false
GEN_MUTEX=false
GEN_ALLOC=false
GEN_HEAP=false
@bcap
bcap / multiple-pipelines.md
Last active August 29, 2015 13:56
Multiplos pipelines no shell

Os multiplos pipelines de shell q tava falando:

seq 1 100 \
    > >(awk '$1 % 2 == 0' | wc -l | read i && echo "$i divisiveis por 2") \
    > >(awk '$1 % 3 == 0' | wc -l | read i && echo "$i divisiveis por 3") \
    > >(awk '$1 % 5 == 0' | wc -l | read i && echo "$i divisiveis por 5")

O grande lance aqui é que voce pode duplicar os file descriptors de stdout/stderr de qualquer processo direto no bash/zsh/ksh(acho). Se voce tiver interesse, por baixo ele usa a syscall dup/dup2 (man -a dup). Na pratica o comando tee acaba sendo um wrapper pra usar essa syscall a partir do shell:

Por exemplo:

#!/bin/bash
stream="$1"
start_fragment="$2"
seconds_between_requests="$3"
calc_segment() {
echo $(($fragment / 100 + 1))
}
#!/bin/sh
#
# Use ipfw to throttle bandwidth.
# usage:
# ./throttle.sh # Throttle at default (60KB/s)
# ./throttle.sh 5 # Throttle at custom speed (5KB/s)
# ./throttle.sh off # Turn throttling off
# flush rules
ipfw del pipe 1
@bcap
bcap / btsync.conf
Created November 3, 2013 18:44
Simple BTSync config for Linux btsync CLI
{
"device_name": "sync test 1",
"listening_port" : 7788,
"storage_path" : "/var/lib/btsync/.sync",
"check_for_updates" : false,
"use_upnp" : false,
// limits in kB/s. 0 = no limit
"download_limit" : 0,
"upload_limit" : 0,
@bcap
bcap / carbon-vhost
Last active December 19, 2015 00:29
Python HTTP proxy (mod_python) for graphite-carbon
# apache2 virtual host configuration
<VirtualHost *:80>
ServerName graphite
DocumentRoot "/opt/graphite/webapp"
ErrorLog "/var/log/graphite/error.log"
CustomLog "/var/log/graphite/access.log" common
<Location "/carbon-web-proxy/v1.0/">
SetHandler python-program
@bcap
bcap / terminal-control.sh
Last active March 29, 2024 14:02
Useful terminal control characters
# Terminal output control (http://www.termsys.demon.co.uk/vtansi.htm)
TC='\e['
CLR_LINE_START="${TC}1K"
CLR_LINE_END="${TC}K"
CLR_LINE="${TC}2K"
# Hope no terminal is greater than 1k columns
RESET_LINE="${CLR_LINE}${TC}1000D"
@bcap
bcap / start-stop-daemon-template
Last active July 21, 2023 11:12
Template file for creating linux services out of executables using the start-stop-daemon
#!/bin/bash
### BEGIN INIT INFO
# Provides: <service name>
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: <service description>
### END INIT INFO
@bcap
bcap / update.pp
Created January 20, 2013 05:11
Run apt get update in a more reasonable fashion
class apt::update {
# execute apt-get update if any of the following conditions met:
# - there is no apt-get update cache data (eg. first run)
# - any file in the /etc/apt/** was changed after the last execution
# - it was executed more than 24h ago
$apt_update_min_age_in_seconds = "24 * 60 * 60" # you can edit this
$apt_update_condition_1 = "[[ ! -f /var/cache/apt/pkgcache.bin ]]"
$apt_update_condition_2 = "find /etc/apt -cnewer /var/cache/apt/pkgcache.bin | grep ."
$apt_update_condition_3 = "[[ $(( $(date +%s) - $(stat -c %Z /var/cache/apt/pkgcache.bin) )) -gt $(( ${apt_update_min_age_in_seconds} )) ]]"