Skip to content

Instantly share code, notes, and snippets.

@DannyBen
DannyBen / Runfile
Created August 26, 2018 07:30
Ruby UDP Example
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 / config.ru
Last active May 7, 2019 18:51
Minimal Server for Request Header Debugging
# 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 / Ruby Benchmark Helper.md
Last active September 20, 2019 09:34
Ruby Benchmark Helper

Ruby Benchmark Helper

Usage

require './bm'

bm = BM.new

bm.add(:sleep_long) { sleep 0.1 }
@DannyBen
DannyBen / asn
Last active August 16, 2023 16:35 — forked from nitefood/README.md
ASN/IP/Route/hostname command line lookup tool to map any network to the corresponding ASN and prefix
#!/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 / stub.bash
Created December 9, 2019 13:19 — forked from jimeh/stub.bash
Shell script helpers to stub and restore bash shell functions/commands in tests.
# 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 / approvals.bash
Last active December 14, 2019 08:52
Bash interactive approval testing (MOVED to https://github.com/DannyBen/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 / cron-explain
Last active January 2, 2020 14:56
cron-explain - CLI for showing cron expression in plain English
#!/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 / Gemfile
Last active July 19, 2020 07:34
Demonstrating TTY Prompt testing with rspec
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "tty-prompt", github: 'piotrmurach/tty-prompt'
gem "rspec"
@DannyBen
DannyBen / cryptokitties.sol
Created September 12, 2021 17:43 — forked from arpit/cryptokitties.sol
Cryptokitties Contract from the Eth blockchain
pragma solidity ^0.4.11;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
@DannyBen
DannyBen / tmux.md
Created May 13, 2022 20:56 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a