Blake Hilscher

Thoughts on ruby development.

Monitor Incoming Http Requests

Install the tcpflow package:

1
apt-get install tcpflow

Monitor network traffic:

1
tcpflow -p -c -i eth1 port 80 | grep -oE '(GET|POST|HEAD) .* HTTP/1.[01]|Host: .*'

Grape API Formatter for Sending Inline Data.

I needed to add a .png formatter to the quandl Grape API.

The png is generated using phantomjs, so it needed to be sent down inline.

1
2
3
4
5
6
7
content_type :png, "image/png"

formatter :png, lambda { |response, env|
    path = response.try(:object).try(:to_png)
    rack = Rack::Response.new(File.read(path) , 200, { "Content-type" => "image/png" }).finish
    rack[2].body[0]
}

Generate Images With Phantomjs.

These images are generated through the quandl api using the png response type. Other supported response types are json, xml, csv, xls, and html. The api provides programatic access to trim, collapse, transform, merge, and order datasets.

Invoke a Proc in the Context of Another Object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class ObjectContext

  def initialize
    @number = 10
  end

  def evaluate(proc)
    instance_exec &proc
  end

end

# our multiplication proc
t = -> { puts( @number * @number) }

# evaluate in current context
@number = 5
t.call #=> 25 

# evaluate in context of an ObjectFactory instance 
o = ObjectContext.new
o.evaluate(t) #=> 100

Show Hidden Files and Folders in Textmate.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.

# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References

# Replace the following:

# File Pattern
!(/\.(?!\W*)[^/]*|\.(gitkeep|DS_Store|tmproj|o|pyc)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$

# Folder Pattern
!.*/(.git|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$