Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Ball sdball

View GitHub Profile
@sdball
sdball / nilbog.rb
Created Dec 14, 2018
From whence nothing but nil can return
View nilbog.rb
class Nilbog
class_eval do
Object.methods.each do |method|
class_eval("def #{method}; #{nil}; end")
end
end
def method_missing(_)
nil
end
View letters.sh
check_letter() {
echo "$1: `type $1 >/dev/null && type $1 | sed -e \"s/^$1: //\" | tr '\n' ' '`";
}
letters() {
for letter in {a..z}; do
check_letter $letter
check_letter `echo $letter | tr a-z A-Z`
done
}
View required_args.js
'use strict';
// none of this is good
class Greet {
required(arg) {
throw new Error(`${arg} is required`);
}
requireArgs(given, required) {
@sdball
sdball / ssl_cert_extraction_example.ex
Last active Mar 31, 2017
functions to extract SSL certs for Erlang SSL from ENV variables
View ssl_cert_extraction_example.ex
def ssl_config do
ssl_config(client_cert, client_cert_key)
end
def ssl_config(_client_cert=nil, _client_cert_key=nil) do
[]
end
def ssl_config(client_cert, client_cert_key) do
[
@sdball
sdball / elixir_data_bytes.exs
Created Jul 19, 2016
Looking at types of Elixir byte data
View elixir_data_bytes.exs
is_binary <<255::size(8)>> # => true
is_bitstring <<255::size(8)>> # => true
is_binary <<255::size(4)>> # => false
is_bitstring <<255::size(4)>> # => true
# So a binary is a bitstring but a bitstring isn't necessarily a binary.
# We can see that effect in pattern matching as well:
<<255::size(4)>> # => <<15::size(4)>>
<<x>> = <<255::size(4)>> # => MatchError!
@sdball
sdball / kafka-consumer.rb
Last active Jan 23, 2020
Simple generic Ruby Kafka producer/consumer for testing
View kafka-consumer.rb
require "kafka"
require "logger"
require "optparse"
script_name = File.basename($0, File.extname($0))
default_logfile = "logs/#{script_name}.log"
default_offset = "latest"
options = {}
OptionParser.new do |opts|
View mutation_behavior.rb
original = [
{ a: { foo: 1 } },
{ b: { foo: 2 } },
{ c: { foo: 3 } },
{ d: { foo: 4 } },
{ e: { foo: 5 } },
{ f: { foo: 6 } },
{ g: { foo: 7 } },
]
View loltie.txt
lol lol
<o>
|
|
|
>o< "I've lost R2!"
@sdball
sdball / keybase.md
Created May 12, 2014
keybase proof
View keybase.md

Keybase proof

I hereby claim:

  • I am sdball on github.
  • I am sdball (https://keybase.io/sdball) on keybase.
  • I have a public key whose fingerprint is D718 9FCA 7760 1079 3990 C5AE 9337 38E4 021E 0115

To claim this, I am signing this object:

@sdball
sdball / self_instance_demo.rb
Created May 1, 2014
self vs instance vs local variables in initialize
View self_instance_demo.rb
class UsingSelf
attr_accessor :a, :b, :c
def initialize(a, b, c)
self.a = a
self.b = b
self.c = c
end
end
class UsingInstance