Skip to content

Instantly share code, notes, and snippets.

Danny Ben Shitrit DannyBen

Block or report user

Report or block DannyBen

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
@DannyBen
DannyBen / cron-explain
Last active Jan 2, 2020
cron-explain - CLI for showing cron expression in plain English
View cron-explain
#!/usr/bin/env ruby
# Show cron expression in plain english
# Place in /usr/local/bin and chmod +x
require 'bundler/inline'
gemfile do
source "https://rubygems.org"
gem 'cron2english'
end
@DannyBen
DannyBen / approvals.bash
Last active Dec 14, 2019
Bash interactive approval testing (MOVED to https://github.com/DannyBen/approvals.bash)
View approvals.bash
# Interactive approval testing for Bash.
# Author: Danny Ben Shitrit (https://github.com/dannyben)
#
# This utility will compare the output of a command with an expected output
# stored in the approvals folder.
#
# - When the approval file does not exist, the actual output will be shown to
# you, and you will be prompted to approve (and save) it.
# - When the approval file exists, but contains different data, the diff will
# be shown to you, and you will be prompted to approve (and save) it.
@DannyBen
DannyBen / stub.bash
Created Dec 9, 2019 — forked from jimeh/stub.bash
Shell script helpers to stub and restore bash shell functions/commands in tests.
View stub.bash
# Stub commands printing it's name and arguments to STDOUT or STDERR.
stub() {
local cmd="$1"
if [ "$2" == "STDERR" ]; then local redirect=" 1>&2"; fi
if [[ "$(type "$cmd" | head -1)" == *"is a function" ]]; then
local source="$(type "$cmd" | tail -n +2)"
source="${source/$cmd/original_${cmd}}"
eval "$source"
fi
@DannyBen
DannyBen / asn
Last active Oct 27, 2019 — forked from nitefood/asn
ASN/IP/Route/hostname command line lookup tool to map any network to the corresponding ASN and prefix
View asn
#!/usr/bin/env bash
##############################################################################
# ----------------------------------------------------------------------
# ASN/IPv4/Prefix lookup tool. Uses Team Cymru's whois service for data.
# ----------------------------------------------------------------------
# example usage:
# asn <ASnumber> -- to lookup matching ASN data. Supports "as123" and
# "123" formats (case insensitive)
# asn <IP.AD.DR.ESS> -- to lookup matching route and ASN data
@DannyBen
DannyBen / Ruby Benchmark Helper.md
Last active Sep 20, 2019
Ruby Benchmark Helper
View Ruby Benchmark Helper.md

Ruby Benchmark Helper

Usage

require './bm'

bm = BM.new

bm.add(:sleep_long) { sleep 0.1 }
@DannyBen
DannyBen / config.ru
Last active May 7, 2019
Minimal Server for Request Header Debugging
View config.ru
# Usage:
# $ rackup -p3000
# $ curl localhost:3000
require 'rack'
require 'yaml'
run proc { |env| [200, {'Content-Type' => 'text/html'}, [env.select { |key| key.include?('HTTP_') }.to_yaml ] ] }
@DannyBen
DannyBen / Runfile
Created Aug 26, 2018
Ruby UDP Example
View Runfile
require 'socket'
title "UDP Test"
action :server do
s = UDPSocket.new
s.bind(nil, 1234)
5.times do
text, sender = s.recvfrom(16)
puts "received #{text} from #{sender}"
@DannyBen
DannyBen / spec_helper.rb
Last active Feb 15, 2018 — forked from nu7hatch/spec_helper.rb
Testing standard input with RSpec
View spec_helper.rb
module Helpers
# Replace standard input with faked one StringIO.
def stdin_send(*args)
begin
$stdin = StringIO.new
$stdin.puts(args.shift) until args.empty?
$stdin.rewind
yield
ensure
$stdin = STDIN
View Xenial Xerus Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
forward_port = ->(guest, host = guest) do
config.vm.network :forwarded_port,
guest: guest,
host: host,
auto_correct: true
end
@DannyBen
DannyBen / ssx
Last active Feb 25, 2016
Run a ruby or shell script remotely
View ssx
# Run a ruby or shell script remotely
#
# Install:
# - Put the file in your home directory
# - Source it from your .bashrc:
# if [ -f $HOME/ssx ]; then source $HOME/ssx; fi
ssx() {
show_usage() {
echo "Run a ruby or shell script remotely"
You can’t perform that action at this time.