Skip to content

Instantly share code, notes, and snippets.

View pvdb's full-sized avatar
🖥️
Busy making computers do things!

Peter Vandenberk pvdb

🖥️
Busy making computers do things!
View GitHub Profile
@pvdb
pvdb / validate_external_urls.sh
Last active March 4, 2017 09:01
Shell script to extract and validate external URLs found in Seedy content files
#!/usr/bin/env sh
#
# install GNU grep (`/usr/local/bin/ggrep`)...
#
# brew tap homebrew/dupes; brew install grep
#
# usage - ensure `${PROJECTS_HOME}` is set...
#
# find ${PROJECTS_HOME}/seedy/content -name '*.md' | ./validate_external_urls.sh > seedy_external_urls.tsv
@pvdb
pvdb / process_tcp.rb
Last active August 29, 2015 14:25
Get the number of TCP connections owned by current Ruby process
#
# This first version should work on Mac OS X and Linux, but it spawns a process
#
# the number of TCP connections owned by the process.
def Process.tcp_count() `lsof -l -n -P -p #{Process.pid} -a -i tcp | egrep -v '^COMMAND' | wc -l`.chomp.to_i ; end
#!/usr/bin/env ruby
require 'pp'
def ruby_repl processor = nil
unless (processor && Proc === processor) || block_given?
warn "Please invoke `ruby_repl` with a block or a proc..."
else
in_pry = Kernel.const_defined?("Pry::ColorPrinter")
cmd_count = 0 # for use in the command prompt
@pvdb
pvdb / proxy.rb
Last active August 29, 2015 14:24 — forked from torsten/proxy.rb
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@pvdb
pvdb / 70-available-updates-incl-age.rb
Last active September 15, 2021 00:22
determine and print out the age of the oldest and the age of the most recent security update
#!/usr/bin/env ruby
#
# This script can be used to patch the following script on an Amazon Linux AMI:
#
# /etc/update-motd.d/70-available-updates
#
# which is run by cron on a daily basis to add package update info to the MOTD:
#
# 19 package(s) needed for security, out of 160 available
@pvdb
pvdb / determine_home.rb
Created June 11, 2014 13:40
Get current user's home directory, even if ${HOME} isn't set in env
# as a String
HOME = ENV['HOME'] || File.expand_path("~#{Etc.getlogin}")
# as a Pathname
HOME = Pathname.new(ENV['HOME'] || File.expand_path("~#{Etc.getlogin}"))
@pvdb
pvdb / gem-reset.rb
Last active December 23, 2015 00:29 — forked from nixpulvis/gem-reset
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
`gem list -d`.split(/\n\n^(?=\w)/).each do |data|
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
name = match[:name]
versions = match[:versions].split(', ')
if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
next if match[1].empty? # it's the only version if this match is empty
@pvdb
pvdb / process_rss.rb
Last active December 14, 2022 10:50
Get real memory (resident set) used by current Ruby process
#
# This first version should work on Mac OS X and Linux, but it spawns a process
#
# http://stackoverflow.com/questions/7220896/
# https://github.com/rdp/os/blob/master/lib/os.rb#L127
# http://www.ruby-doc.org/core-2.0/Process.html
#
# A better - but more complicated - way to achieve the same is documented here:
#
# https://build.betterup.com/tracking-a-processs-memory-usage-in-ruby/
#!/usr/bin/ruby
require 'rubygems'
installed_gems = Gem::Dependency.new '', Gem::Requirement.default
missing = []
# mind the short-hand, looping over installed gem specs
specs = Gem.source_index.search installed_gems
specs.each do |spec|
gem = Gem::Dependency.new spec.name, spec.version
# looping over gem dependencies
specs = Gem.source_index.search gem
@pvdb
pvdb / benchmark.rb
Last active December 10, 2015 07:08
a multi-dimensional Ruby benchmark script :-)
#!/usr/bin/env ruby
#
# NAME
#
# benchmark.rb -- a multi-dimensional Ruby benchmark script :-)
#
# DESCRIPTION
#
# a customized Ruby "interpreter" that benchmarks
# other Ruby scripts... by default, both resident