Skip to content

Instantly share code, notes, and snippets.

View johnthethird's full-sized avatar

John Lynch johnthethird

View GitHub Profile
@johnthethird
johnthethird / ReactRenderer.rb
Created February 2, 2014 19:01
React Server-Side Rendering for Rails
require 'connection_pool'
class ReactRenderer
mattr_accessor :pool
def self.setup!
size = ::Rails.configuration.react.max_renderers || 10
timeout = ::Rails.configuration.react.renderer_timeout || 20 #seconds
@@pool ||= ConnectionPool.new(:size => size, :timeout => timeout) { ReactRenderer.new }
#!/usr/bin/env python
# Quick and dirty demonstration of CVE-2014-0160 by
# Jared Stafford (jspenguin@jspenguin.org)
# Modified so that it finds cookies
import sys
import struct
import socket
import time
import select
@johnthethird
johnthethird / torquebox_logger.rb
Created May 29, 2014 13:59
TorqueBox Logger that respects tagged logging
# Copy of TorqueBox::Logger
# Try to unfrak it
require 'logger'
module TorqueBox
# @api private
class FallbackLogger < ::Logger
@johnthethird
johnthethird / Gemfile
Last active August 29, 2015 14:13 — forked from bf4/Gemfile
gem 'lograge' # more readable logs
gem 'logstash-event' # for logstash json format
gem 'mono_logger' # threadsafe logging
@johnthethird
johnthethird / react_rails_benchmark.rb
Last active August 29, 2015 14:22
React-Rails Benchmark Script
Runtime Threads Pool Renders user system total real
JavaScriptCore 1 1 100 0.060000 0.140000 3.590000 ( 3.621248)
JavaScriptCore 10 1 100 0.060000 0.180000 3.760000 ( 3.913241)
JavaScriptCore 1 10 100 0.060000 0.160000 4.100000 ( 4.511085)
JavaScriptCore 10 10 100 0.070000 0.230000 6.000000 ( 1.366264)
Node.js (V8) 1 1 100 0.050000 0.140000 10.390000 ( 10.602247)
Node.js (V8) 10 1 100 0.070000 0.190000 10.510000 ( 10.632389)
Node.js (V8) 1 10 100 0.050000 0.150000 10.150000 ( 10.297540)
Node.js (V8) 10 10 100 0.060000 0.210000 17.010000 ( 3.465977)
therubyrhino (Rhino) 1 1 100 0.980000 0.030000 1.010000 ( 0.651000)
script/plugin install git://github.com/myobie/htmldiff.git
# bottom of environment.rb
require 'htmldiff'
# in model
class Page < ActiveRecord::Base
extend HTMLDiff
end
# Read the log into an array.
@mylog = IO.readlines("path/to/log/file.log")
Now, if you want to get rid of the ANSI escape codes from the log (assuming you are accessing your application/database logs) you will have to use regular expressions. There are two ways of doing this. The first is to get rid of the codes after you read the log file, or do it as you display.
Here are the examples:
# Read the log into an array.
@mylog = IO.readlines("/path/to/log/file.log")
class Canine
VERSION = '1.3'
def initialize(&block)
@commands = Hash.new
@default = @latest = :commands
@empty = nil
@auto = {
:commands => hash_command("commands","Show a list of commands",Proc.new {
@commands.each { |cmd| c = cmd[1]
name = c[:name].to_s
test.rb
-----------------------------------
#!/usr/local/bin/ruby
require 'ripple'
# Create a client interface
client = Riak::Client.new
# Retrieve a bucket
bucket = client.bucket("doc") # a Riak::Bucket
/**
IMPORTANT: Requires this version of jquery
until 1.3.3 comes out http://gist.github.com/186325
ALSO: This is very dirty still and has not been
abstracted for use. It is just solving our immediate problems.
Use cases that must pass (and should be tested someday):
* Clicking on links updates layout
* Click around a bit and then use back/forward buttons