Skip to content

Instantly share code, notes, and snippets.

@bradland
bradland / pingr
Created March 17, 2021 18:35
Ping a host and announce its status; requires macOS or suitable replacement for the say command line app.
#!/usr/bin/env ruby
require 'logger'
require 'open3'
require 'optparse'
require 'ostruct'
require 'thread'
class ShellScript
# Excerpt from ptools gem
# Returns whether or not +file+ is a binary non-image file, i.e. executable,
# shared object, ect. Note that this is NOT guaranteed to be 100% accurate.
# It performs a "best guess" based on a simple test of the first
# +File.blksize+ characters, or 4096, whichever is smaller.
#
# By default it will check to see if more than 30 percent of the characters
# are non-text characters. If so, the method returns true. You can configure
# this percentage by passing your own as a second argument.
@bradland
bradland / ac-telemetry.rb
Last active May 13, 2020 03:46
Beginnings of a rudimentary CLI telemetry utility for Assetto Corsa written in Ruby.
#!/usr/bin/env ruby
$: << './lib'
require 'socket'
require 'bindata'
require 'json'
class UTF8String < BinData::String
def snapshot

Ebike batteries have a handful of important ratings that you should check before purchasing any battery. The main two (V and Ah) are commonly listed, but there are some other important measurements that may be more difficult to find:

  • Voltage (V): It's useful to think of voltage as pressure in a system. Higher voltage = higher pressure. The voltage of the pack must match your controller and display. Motors are generally pretty flexible in what they can accept. Voltage limits are strict; that is to say, you cannot exceed them. The important caveat there is, of course, motors. A motor's voltage rating isn't actually a max voltage rating, it's a suggestion based on the motor's max amperage and power rating. Why this is the case will become clear later.
  • Amps (A): Think of amperage (amps) as the volume of flow in a system. More amps = greater flow. All of the electrical components on your ebike will have amperage ratings expressed as max and continuous. The max number is a "never exceed" number, while
# Server is defined in stage file deploy/staging.rb
# server 'staging.example.com', user: 'staginguser', roles: %i(app db web)
# Expect `say_hello` task to output:
# echo 'hello from "staginguser"'
# What `say_hello` task actually outputs:
# echo 'hello from nil'
task :say_hello do
on roles(:app) do
execute "echo 'hello from #{fetch(:user).inspect}'"
#!/usr/bin/env ruby
# This script establishes a UNIX server socket.
#
# Expected result: Script should run and immediately exit.
#
# Actual result: Script fails with Errno::EADDRINUSE error.
#
# Environment: Windows 10 Pro, WSL, Ubuntu 18.04.2, ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux-gnu]
#
@bradland
bradland / pingr
Last active December 13, 2018 22:04
#!/usr/bin/env ruby
require 'logger'
require 'open3'
require 'optparse'
require 'ostruct'
require 'thread'
class ShellScript
@bradland
bradland / 000-sftp.rb
Last active August 8, 2018 02:33
Net::SFTP test script. Fails when downloading files larger than 4 GB
#!/usr/bin/env ruby
require 'net/sftp'
@host = 'localhost'
@user = 'username'
@password = 'password'
@remote_dir = '/source/path/goes/here'
@remote_file_name = 'test-data.txt'
@tmp_dir = '/destination/path/goes/here'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web application could not be started</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet">
<style type="text/css">/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
id gear
0 R
1 N
2 1st
3 2nd
4 3rd
5 4th
6 5th
7 6th
8 7th