Skip to content

Instantly share code, notes, and snippets.

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

Peter Vandenberk pvdb

🖥️
Making computers do things!
View GitHub Profile
@pvdb
pvdb / methodfinder.rb
Created March 30, 2011 20:11
MethodFinder and irb via .irbrc
#
# https://github.com/citizen428/methodfinder
#
# stick the below snippet in your .irbrc file
# in order to be able to do something like...
#
# irb :001 > ' blegga '.method_finder 'blegga'
# => [:strip, :strip!]
# irb :002 > 'blegga'.method_finder 6
# => [:bytesize, :length, :size]
$ export GITHUB_USER="your-github-username"
$ export GITHUB_PASSWORD="your-github-password"
@pvdb
pvdb / markdown.xml
Created May 14, 2012 20:57 — forked from lg0/markdown.xml
Markdown Syntax Highlighting for Sublime text 2
<!-- copy this to YOUR_THEME.tmTheme-->
<dict>
<key>name</key>
<string>diff: deleted</string>
<key>scope</key>
<string>markup.deleted</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#EAE3CA</string>
@pvdb
pvdb / fields_inheritance_fix.rb
Created May 17, 2012 07:12
mongoid - git bisect FTW!
#!/usr/bin/env ruby
$:.unshift File.join File.dirname(__FILE__), "lib"
require 'mongoid.rb'
class Shape
include Mongoid::Document
field :x, type: Integer, default: 0
field :y, type: Integer, default: 0
@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
#!/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 / 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/
@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 / 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 / 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