Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/ruby
# This code is to demonstrate these very important things to remember about Ruby:
#
# 1. Classes are also Objects in Ruby.
# 2. Every Object in Ruby has its own Singleton Class (or "Meta Class" or "Eigen
# Class"
# 3. In other languages you may be familiar with the idea that each Object
# Instance is unique, but in Ruby, each Object Instance has its own unique
# Class definition, unique to JUST THAT instance. This is called the Object's
# singleton class.
@bradoaks
bradoaks / hfsc-shape.sh
Created April 25, 2011 14:51 — forked from eqhmcow/hfsc-shape.sh
HFSC - linux traffic shaping's best kept secret
#!/bin/bash
# As the "bufferbloat" folks have recently re-discovered and/or more widely
# publicized, congestion avoidance algorithms (such as those found in TCP) do
# a great job of allowing network endpoints to negotiate transfer rates that
# maximize a link's bandwidth usage without unduly penalizing any particular
# stream. This allows bulk transfer streams to use the maximum available
# bandwidth without affecting the latency of non-bulk (e.g. interactive)
# streams.
@tobert
tobert / start-lxc-cluster.sh
Created August 29, 2011 04:54
instant lxc cluster
#!/bin/bash
COUNT=10
BRIDGE="br1"
FORMAT="lxc%d"
PARENT=$(hostname --fqdn)
LXC_ROOT=/srv/virt/lxc
OS_ROOT=/srv/virt/lxc/base/root
for num in $(seq 1 $COUNT)
@rtomayko
rtomayko / optparse-template.rb
Last active June 3, 2023 03:16
Ruby optparse template
#!/usr/bin/env ruby
#/ Usage: <progname> [options]...
#/ How does this script make my life easier?
# ** Tip: use #/ lines to define the --help usage message.
$stderr.sync = true
require 'optparse'
# default options
flag = false
option = "default value"
@samqiu
samqiu / nginx.conf
Created September 15, 2011 01:07 — forked from huacnlee/nginx.conf
Nginx http proxy cache to mirror of Rubygems.org
# 在本地服务器建立 rubygems.org 的镜像缓存,以提高 gem 的安装速度
# 此配置设置缓存过期为1天,也就是说,新上的 gem 无法马上安装
# 做这个起什么作用?
# rubygems 的很多资源文件是存放到 Amazon S3 上面的,由于 GFW 对某些 S3 服务器又连接重置或丢包,导致 gem 安装异常缓慢或有时候根本无法连接安装。
# 而通过这种跳板的方式可以很好的解决这个问题,当然前提是 Nginx反向代理 服务器需要在国外
proxy_cache_path /var/cache/rubygems levels=1:2 keys_zone=RUBYGEMS:10m
inactive=24h max_size=1g;
server {
listen 80;
@tobert
tobert / tune_cassandra_raid.sh
Created September 20, 2011 06:20
Tuning Linux MDRAID 5 for acceptable performance
#!/bin/bash
# Linux RAID5 tuning
# Al Tobey 2011-09-19 <al@ooyala.com>
for sysent in /sys/block/sd*
do
drive=$(basename $sysent)
sector_size=$(blockdev --getss /dev/$drive)
@dexterbt1
dexterbt1 / create_libvirt_lxc_guest.sh
Last active December 11, 2015 09:49
Centos 6.3 script to automate creation of the LXC rootfs and libvirt definition
#!/bin/bash
# vim: set ts=4 sw=4 et nu
set -e
usage="Usage: $0 <name>"
name=$1
if [ -z "$name" ]; then
echo $usage
exit 1;
fi
@skihero
skihero / gist:5046841
Created February 27, 2013 10:09
error: unpacking of archive failed on file /usr/sbin/haproxy;512ddaaa: cpio: Digest mismatch
Was trying to create an rpm from the installed haproxy binaries.
Ran into this problem.
Turns out we need to do a prelink -u haproxy on the binary that we're packaging.
The binary had come from a different machine than the place where we're building it.
@jkstill
jkstill / proc_net_tcp_decode
Last active May 8, 2024 13:54
decode entries in /proc/net/tcp
Decoding the data in /proc/net/tcp:
Linux 5.x /proc/net/tcp
Linux 6.x /proc/PID/net/tcp
Given a socket:
$ ls -l /proc/24784/fd/11
lrwx------ 1 jkstill dba 64 Dec 4 16:22 /proc/24784/fd/11 -> socket:[15907701]
@rcoup
rcoup / rsync_parallel.sh
Created April 10, 2013 21:52
Parallel-ise an rsync transfer when you want multiple concurrent transfers happening,
#!/bin/bash
set -e
# Usage:
# rsync_parallel.sh [--parallel=N] [rsync args...]
#
# Options:
# --parallel=N Use N parallel processes for transfer. Defaults to 10.
#
# Notes: