Skip to content

Instantly share code, notes, and snippets.

View tadman's full-sized avatar
🤔
Enumerating

Scott Tadman tadman

🤔
Enumerating
View GitHub Profile
@tadman
tadman / minimal_falcon_rack_ws_app.rb
Created March 24, 2020 06:16
Minimal Falcon + Rack + WebSocket Adapter Demo
require 'async'
require 'async/http/endpoint'
require 'async/websocket/adapters/rack'
require 'falcon'
websocket_endpoint = Async::HTTP::Endpoint.parse('http://127.0.0.1:3000')
module WebSocketApp
def self.call(env)
@tadman
tadman / method_call-vs-send.rb
Created October 15, 2019 16:29
Method call vs. send benchmark in Ruby
require 'benchmark'
Benchmark.bm do |bm|
repeat = 10000000
bm.report('send') { repeat.times { 5.send(:>, 2) } }
bm.report('method.call') { repeat.times { 5.method(:>).call(2) } }
end
# user system total real
@tadman
tadman / server.rs
Created June 23, 2015 17:05
Rust MIO Example
extern crate mio;
use std::error::Error;
use mio::*;
use mio::tcp::{TcpListener, TcpStream};
// Setup some tokens to allow us to identify which event is
// for which socket.
const SERVER: Token = Token(0);
class String
def substrings
((0...length).to_a.combination(2).map do |from,to|
# Extract substrings
self[from, to]
end + self.chars).map do |s|
# Trim off any unwanted characters
s.sub(/\A\W+/, '').sub(/\W+\z/, '')
end.sort.uniq.reject do |s|
# Remove empty strings
require 'nokogiri'
doc = Nokogiri::HTML(DATA)
doc.css('head').remove
puts doc.to_s
__END__
@tadman
tadman / hstore.js
Last active December 18, 2015 11:38
module.exports = {
stringifyPart: function(part) {
switch(typeof part) {
case 'boolean':
case 'number':
return String(part)
case 'string':
return '"' + part.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'
case 'undefined':
return 'NULL'
#!/usr/bin/env ruby
require 'benchmark'
LETTERS = ('a'..'z').to_a.freeze
def random_customer_name
name = [ ]
(rand(10) + 1).times do
@tadman
tadman / rubygems-warning.patch
Created May 11, 2011 04:28
Rubygems 1.8.1 Deprecate Warning Patch
diff --git a/Manifest.txt b/Manifest.txt
index 6e79ebd..6a2f480 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -121,6 +121,7 @@ test/rubygems/rubygems_plugin.rb
test/rubygems/sff/discover.rb
test/rubygems/simple_gem.rb
test/rubygems/test_config.rb
+test/rubygems/test_deprecate.rb
test/rubygems/test_gem.rb
@tadman
tadman / monkeypatch.rb
Created April 15, 2011 20:03
FreeTDS Configuration Monkeypatch
module ActiveRecord
class Base
def self.sqlserver_connection(config) #:nodoc:
config = config.dup.symbolize_keys!
config.reverse_merge! :mode => :dblib, :host => 'localhost', :username => 'sa', :password => ''
mode = config[:mode].to_s.downcase.underscore.to_sym
case mode
when :dblib
# <monkeypatch>
# raise ArgumentError, 'Missing :dataserver configuration.' unless config.has_key?(:dataserver)
#!/bin/sh
MYSQL_USER=root
MYSQL_PASSWORD=<PASSWORD>
MYSQL_OPTS=
RETAIN_PERIOD=5
DUMP_DIRECTORY="$HOME/dumps"