Skip to content

Instantly share code, notes, and snippets.

View sdball's full-sized avatar

Stephen Ball sdball

View GitHub Profile
@sdball
sdball / hardcoded_swap.rb
Created January 25, 2013 15:02
Ruby fun: a one time method override.
require 'minitest/spec'
require 'minitest/autorun'
class String
def one_time_override(method, &override)
self.instance_eval do
def to_s
self.instance_eval do
def to_s
'foo'
@sdball
sdball / javascript_learning_sources.md
Last active December 13, 2015 18:08
Want to learn JavaScript?
@sdball
sdball / ezproxy_redirect.php
Created March 1, 2013 17:16
Some old PHP code I wrote to have PHP force EZProxy into being more secure.
<?php
/**
* ezproxy_redirect
*
* EZProxy requires that the username and password be passed via GET.
* This is just about as insecure as possible.
*
* So, we trick ezproxy into security by opening a socket connection
* to the server; acting as a browser to initiate the connection; then
* writing out its response to the actual browser.
@sdball
sdball / index.php
Created March 1, 2013 17:18
Snippets from an old PHP IP Database I wrote. My hand rolled framework code was kind of nice.
<?php
// page setup
require('/www/includes/ipdatabase/ipdb_page.php');
$javascript = '<script type="text/javascript" src="/ipdatabase/js/index.js"></script>';
$page = new IPDB_Page();
$page->title('Main');
$page->javascript($javascript);
@sdball
sdball / nil_what_are_you_doing_stahp.rb
Last active March 16, 2019 01:35
Sometimes Ruby is Weird
class NilWhatAreYouDoingStahp
attr_accessor :not_nil
def initialize
@not_nil = "I'm not nil! I'm a value!"
end
def wat
if not_nil.nil?
not_nil = "Ok, now I'm not nil."
@sdball
sdball / self_instance_demo.rb
Created May 1, 2014 14:12
self vs instance vs local variables in initialize
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
@sdball
sdball / keybase.md
Created May 12, 2014 14:35
keybase proof

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 / loltie.txt
Created March 4, 2015 02:23
loltie.txt
lol lol
<o>
|
|
|
>o< "I've lost R2!"
original = [
{ a: { foo: 1 } },
{ b: { foo: 2 } },
{ c: { foo: 3 } },
{ d: { foo: 4 } },
{ e: { foo: 5 } },
{ f: { foo: 6 } },
{ g: { foo: 7 } },
]
@sdball
sdball / kafka-consumer.rb
Last active January 23, 2020 05:14
Simple generic Ruby Kafka producer/consumer for testing
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|