Skip to content

Instantly share code, notes, and snippets.

Peter Vandenberk pvdb

Block or report user

Report or block pvdb

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
@pvdb
pvdb / consenter.rb
Last active Sep 4, 2018
idiomatic Enumerable extensions to filter elements by consent
View consenter.rb
# rubocop:disable all
# https://github.com/pvdb/consenter
require 'io/console'
class Consenter # :nodoc:
VALID_RESPONSES = {
'y' => 'yes to this',
@pvdb
pvdb / git-rev-diff
Last active Mar 12, 2018
Run the same command against two git revisions, and diff the output
View git-rev-diff
#!/usr/bin/env bash
#
# INSTALLATION
#
# cp ${PWD}/git-rev-diff $( brew --prefix )/bin/
#
# check command-line options
@pvdb
pvdb / SSLPoke.java
Created May 18, 2016 — forked from 4ndrej/SSLPoke.java
Test of java SSL / keystore / cert setup. Check the commet #1 for howto.
View SSLPoke.java
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {
@pvdb
pvdb / validate_external_urls.sh
Last active Mar 4, 2017
Shell script to extract and validate external URLs found in Seedy content files
View validate_external_urls.sh
#!/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 Aug 29, 2015
Get the number of TCP connections owned by current Ruby process
View process_tcp.rb
#
# 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
View ruby_repl.rb
#!/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
View 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 <torsten.becker@gmail.com>
#
# 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 Dec 15, 2015
determine and print out the age of the oldest and the age of the most recent security update
View 70-available-updates-incl-age.rb
#!/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 Jun 11, 2014
Get current user's home directory, even if ${HOME} isn't set in env
View determine_home.rb
# as a String
HOME = ENV['HOME'] || File.expand_path("~#{Etc.getlogin}")
# as a Pathname
HOME = Pathname.new(ENV['HOME'] || File.expand_path("~#{Etc.getlogin}"))
View gem-reset.rb
#!/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
You can’t perform that action at this time.