Skip to content

Instantly share code, notes, and snippets.

@mzsanford
mzsanford / keybase.md
Created April 10, 2014 03:08
keybase.md

Keybase proof

I hereby claim:

  • I am mzsanford on github.
  • I am mzsanford (https://keybase.io/mzsanford) on keybase.
  • I have a public key whose fingerprint is 3B22 CD6F 7871 FD73 7ED2 5307 1051 10ED C04C BEF1

To claim this, I am signing this object:

import java.util.logging.Logger
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.mortbay.jetty.Server
import org.mortbay.jetty.handler.AbstractHandler
object Test extends AbstractHandler {
val log = Logger.getLogger("handler")
def main(args : Array[String]) = {
latin = "a"
arabic = [0xfeb6].pack('U') # Sheen, ش
cjk = [0x3333].pack('U') # HUIITO, ㌳
kcodes = [ 'NONE', 'u', 's' ]
chars = [latin, arabic, cjk]
patterns = [ /\w/, /\W/, /[[:punct:]]/ ]
kcodes.each do |kcode|
$KCODE = kcode
space = " "
japanese_space = [0x3000].pack('U')
puts "---"
puts "Space and \\s : #{!!space.match('\s')}"
puts "Japanese Space and \\s : #{!!japanese_space.match('\s')}"
puts "---"
puts "Space and [[:space:]] : #{!!space.match('[[:space:]]')}"
puts "Japanese Space and [::space:]] : #{!!japanese_space.match('[[:space:]]')}"
latin = "6"
egypt = [0x0666].pack('U') # Arabic-Indic 6 - ٦
china = [0x516d].pack('U') # 六
braille = [0x2820].pack('U')
chars = [latin, egypt, china, braille ]
patterns = [ /\d/, /[[:digit:]]/, /[[:alnum:]]/]
chars.each do |char|
# From a .vimrc
# Usage: <ESC>,indent<Enter>
#
map <Leader>indent :s/^\( *[^ ]\)/ \1/<CR>
# Shell commands:
# ∴ sudo gem install twitter-text
# ∴ ruby script/console
Loading development environment (Rails 2.3.5)
>> require 'twitter-text'
=> []
>> include Twitter::Extractor
=> Object
>> urls = extract_urls("This has a url: http://twitter.com")
require 'flockdb'
flock = Flock.new "localhost:7915", :graphs => { :a_to_b => 1, :b_to_c => 2 }
flock.add(1, :a_to_b, 1)
flock.add(1, :a_to_b, 2)
flock.add(1, :a_to_b, 3)
flock.add(2, :b_to_c, 1)
flock.add(2, :b_to_c, 2)
@mzsanford
mzsanford / em-http.rb
Created September 29, 2012 04:23
Scatter Gather HTTP with EventMachine (from a non-EM Ruby class, like Rails)
require 'rubygems'
require 'benchmark'
require 'httparty'
require 'eventmachine'
require 'em-http'
class Interatred
@mzsanford
mzsanford / Sintra Log (subclass) on 3 curl requests
Last active December 17, 2015 14:09
Sintra memory usage - Part 1
∴ ruby subclass.rb
== Sinatra/1.4.2 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:4567, CTRL+C to stop
---- Init myApp
-- Setting up array id 70252864198560
-- Starting GC
---- Waiting in memory (1848): #<MyApp:0x007fca08831ad8 @default_layout=:layout, @app=nil, @template_cache=#<Tilt::Cache:0x007fca08830f20 @cache={}>>
---- Waiting in memory (3576): #<MyApp:0x007fca0a0710a8 @default_layout=:layout, @app=nil, @template_cache=#<Tilt::Cache:0x007fca08830f20 @cache={}>, @env={"SERVER_SOFTWARE"=>"thin