Skip to content

Instantly share code, notes, and snippets.

View amosshapira's full-sized avatar

Amos Shapira amosshapira

  • Sydney, Australia
View GitHub Profile
@amosshapira
amosshapira / rename graphite metrix after upgrade to 5.2.1
Last active December 17, 2015 15:29
Have you upgraded collectd from pre-5.2.1 to 5.2.1 or higher (5.3 in my case) and it started to send graphite metrics without the annoying ".value" in the name? Here is a quick find command to rename the old files to the new names.
find -name value.wsp -printf "mv -v %h.wsp %h.wsp.new; mv -v %p %h.wsp\n" | /bin/sh
#
# file_content.rb
#
# Amos Shapira: cloned from exists.rb at https://gist.github.com/chrisleavoy/5312010,
# returns the content of the file found
#
# James Fellows 8/8/12: cloned from git://gist.github.com/1160472.git then
# modified to resolve puppet:/// paths
#
# Copyright 2011 Puppet Labs Inc.
@amosshapira
amosshapira / find-puppet-resource-failutes.rb
Last active December 20, 2015 07:58
This script takes a list of names of Puppet report files and extract the names and time stamps of failed resources.
#!/usr/bin/env ruby
require 'yaml'
ARGV.each do |filename|
yaml = YAML.load_file(filename)
hash = yaml.ivars["resource_statuses"]
# The following line will just print the resource reference
# puts hash.keys.sort.select{|resource| hash[resource].ivars["failed"]}
# The following line will also print the resource time stamp, it demonstrates access
@amosshapira
amosshapira / find-root-hogs
Last active December 20, 2015 12:19
Common problem - root file system (or another file system which has other file systems mounted under it) is full and you want to run "du" only on directories which are only on the current file system in order to find the break down of the space users:
#!/bin/bash
find -mindepth 1 -type d -prune |
while read i
do
[[ $(stat -c %m $i) == $(stat -c %m $(pwd)) ]] && echo $i
done |
xargs du -shcx |
sort -h
#!/bin/bash
set -e
cd ~/
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.65.tar.gz
tar -zxf mysql-5.1.65.tar.gz
cd mysql-5.1.65
./configure '--prefix=/usr' '--exec-prefix=/usr' '--libexecdir=/usr/sbin' '--datadir=/usr/share' '--localstatedir=/var/lib/mysql' '--includedir=/usr/include' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-system-type=debian-linux-gnu' '--enable-shared' '--enable-static' '--enable-thread-safe-client' '--enable-assembler' '--enable-local-infile' '--with-fast-mutexes' '--with-big-tables' '--with-unix-socket-path=/var/run/mysqld/mysqld.sock' '--with-mysqld-user=mysql' '--with-libwrap' '--without-readline' '--with-ssl' '--without-docs' '--with-extra-charsets=all' '--with-plugins=max' '--with-embedded-server' '--with-embedded-privilege-control'
make
@amosshapira
amosshapira / html to csv in ruby
Last active December 28, 2015 13:59
Convert HTML from input files (or standard input, if no file name given) to CSV. Taken from a stackoverflow.com answer I lost since.
#!/usr/bin/ruby
require 'nokogiri'
doc = Nokogiri::HTML(ARGF.read)
doc.xpath('//table//tr').each do |row|
row.xpath('td').each do |cell|
print '"', cell.text.gsub("\n", ' ').gsub('"', '\"').gsub(/(\s){2,}/m, '\1'), "\", "
end
print "\n"
@amosshapira
amosshapira / replace-plus-with-urlconde
Last active August 29, 2015 13:56
Replace all "+" characters in file names to "%2b" url encoded
What I like about this way of doing this is that it takes advantage of Bash internals without external commands.
for i in *; do mv $i ${i//+/%2b}; done
xmllint --format -
("-" for standard input)
@amosshapira
amosshapira / osx-number-of-cpus
Created June 23, 2014 03:53
Find number of CPU's on OSX
From https://groups.google.com/d/msg/gnu.emacs.help/gr5lC8sPyks/SNx6JblcuvgJ:
sysctl -n hw.logicalcpu_max
@amosshapira
amosshapira / .gvimrc
Created July 4, 2014 00:53
.gvimrc on Mac
set guifont=Menlo\ Regular:h18
set number
" configure expanding of tabs for various file types
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.c set noexpandtab
au BufRead,BufNewFile *.h set noexpandtab
au BufRead,BufNewFile Makefile* set noexpandtab
" --------------------------------------------------------------------------------