Skip to content

Instantly share code, notes, and snippets.

Bruno "Polaco" Penteado bcap

Block or report user

Report or block bcap

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bcap
bcap / multiple-pipelines.md
Last active Aug 29, 2015
Multiplos pipelines no shell
View multiple-pipelines.md

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:

View ig-test-stream.sh
#!/bin/bash
stream="$1"
start_fragment="$2"
seconds_between_requests="$3"
calc_segment() {
echo $(($fragment / 100 + 1))
}
View ipfw bandwidth throttle.sh
#!/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 Nov 3, 2013
Simple BTSync config for Linux btsync CLI
View btsync.conf
{
"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 Dec 19, 2015
Python HTTP proxy (mod_python) for graphite-carbon
View carbon-vhost
# 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 Nov 2, 2019
Useful terminal control characters
View terminal-control.sh
# 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 Mar 11, 2019
Template file for creating linux services out of executables using the start-stop-daemon
View start-stop-daemon-template
#!/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 Jan 20, 2013
Run apt get update in a more reasonable fashion
View update.pp
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} )) ]]"
@bcap
bcap / LinuxDualMonitors
Created Sep 20, 2012
Adjust double monitors display, edit changing screen names and position
View LinuxDualMonitors
#!/bin/bash
# xrandr --nograb --output <primary display name> --auto --pos 0x0 --primary --preferred
# xrandr --nograb --output <secondary display name> --auto --pos <position X in relation to the primary monitor>x<position Y in relation of the primary monitor>
xrandr --nograb --output VGA1 --auto --pos 0x0 --primary --preferred
xrandr --nograb --output DP1 --auto --pos 1920x200
You can’t perform that action at this time.