Skip to content

Instantly share code, notes, and snippets.

@jamster
jamster / clean_json.rb
Created May 6, 2011 20:39
Cleaning JSON
require 'rubygems'
require 'yajl/json_gem'
require 'pp'
json_string = DATA.read
pp JSON.parse(json_string)
__END__
{"contact": {
"kABPersonEmailProperty": [{"email": "John-Appleseed@mac.com","label": "Blah","label_local": "Blah"},
{"email": "home@home.com","label": "_$!<Home>!$_","label_local": "home"}
@jamster
jamster / mecached_bm.rb
Created August 8, 2011 13:51
Memcached Miss Benchmarker
require 'rubygems'
require 'benchmark'
GC.disable
@mp = MemcachedPage.new
CRZ = 100000
CRZ.times do |x|
@mp.set("/#{x}", "Testing")
end
require 'rubygems'
require 'sinatra'
require 'haml'
class Kaboom < Sinatra::Base
set :show_exceptions, false
set :views, File.dirname(__FILE__) + '/templates'
error do
"{'error' : #{env['sinatra.error'].to_s}}"
@jamster
jamster / driver.sh
Created September 6, 2011 14:52
A way to pipe in rails logs and split along the double newline
cat sample_rails.log | ruby rails_multiline_log_splitter.rb > output
# ["Started GET \"/\" for 98.113.86.74 at Tue Sep 06 09:44:35 -0400 2011","Processing by LinksController#index as HTML","Completed 401 Unauthorized in 0ms"]
# ["Started GET \"/\" for 98.113.86.74 at Tue Sep 06 09:44:36 -0400 2011","Processing by LinksController#index as HTML","Rendered links/index.html.erb within layouts/main (227.1ms)","Completed 200 OK in 339ms (Views: 228.3ms | ActiveRecord: 21.0ms)"]
# ["Started GET \"/links/11\" for 98.113.86.74 at Tue Sep 06 09:44:52 -0400 2011","Processing by LinksController#show as HTML","Parameters: {\"id\"=>\"11\"}","Rendered links/show.html.erb within layouts/main (190.2ms)","Completed 200 OK in 194ms (Views: 191.1ms | ActiveRecord: 1.2ms)"]
# ["Started GET \"/links/search?utf8=%E2%9C%93&q=ruby+on+rails&commit=Search\" for 98.113.86.74 at Tue Sep 06 09:45:12 -0400 2011","Processing by LinksController#search as HTML","Parameters: {\"commit\"=>\"Search\", \"utf8\"=>\"✓\", \"q\"=>\"ruby on rails\"}"
@jamster
jamster / gist:1212216
Created September 12, 2011 19:56
Install Notes for Logstash
version=0.17.6
ES_PACKAGE=elasticsearch-$version.zip
ES_DIR=${ES_PACKAGE%%.zip}
SITE=http://github.com/downloads/elasticsearch/elasticsearch
if [ ! -d "$ES_DIR" ] ; then
wget --no-check-certificate $SITE/$ES_PACKAGE
unzip $ES_PACKAGE
fi
@jamster
jamster / gist:1457369
Created December 11, 2011 00:48
jQuery.autoFitText Plugin Docs

Documentation

Auto Fit Text is a plugin that allows you to programmatically change the font size of text living in an element. Often times when you have a common layout and dynamic content, you may find headers and certain text boxes overflow, or wrap making the design break. With Auto Fit Text, you can have it reduce the font so that it fits perfectly within the original size set for your container element.

Dependencies

  • jQuery 1.6

How To Use By Example

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
.axis text {
font: 10px sans-serif;
}
@jamster
jamster / Results.txt
Created April 13, 2012 21:49
Finding Prime Palindrome in Pi
1
2 26 33
3 4 141
4 47 3993
5 24 46264
6 768 999999
7 647 1736371
8 3740 23911932
9 6586 398989893
10
require 'pp'
def perms(s)
base = [s.downcase, s.upcase]
case s.downcase
when 'a'
base << '@'
when 'o'
base << '0'
when 'e'
@jamster
jamster / gist:3362954
Created August 15, 2012 19:39 — forked from saetia/gist:1623487
Clean Install – Mountain Lion OS X 10.8 DP3 Update 4