Skip to content

Instantly share code, notes, and snippets.

@futurechimp
futurechimp / xmpp4r_harness.rb
Created September 6, 2011 10:37
100% CPU usage in xmpp4r
# Steps to repro:
#
# Set up two XMPP accounts:
# "account1@yourserver.org" and "account2@yourserver.org"
# Both with password "password"
#
# Start the sinatra webserver server using:
#
# ruby -rubygems xmpp4r_harness.rb
#
@futurechimp
futurechimp / xmpp4r_faster.rb
Created September 6, 2011 15:28
A better solution to the problem of sending xmpp in ruby
require 'rubygems'
require 'xmpp4r'
require 'sinatra'
# Doing XMPP connectivity like this has terrible performance:
#
# https://gist.github.com/1197232
#
# Here's a better way.
#
PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
require File.expand_path('../../config/boot', __FILE__)
require 'minitest/matchers'
require 'valid_attribute'
require 'valid_attribute/minitest'
require PADRINO_ROOT + '/test/blueprints'
class MiniTest::Spec
require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
describe "User Model" do
# Associations
#
it "has_many videos" do
v1 = Video.make
v2 = Video.make
user = User.make
@futurechimp
futurechimp / gist:1927503
Created February 27, 2012 22:17
The Conundrum
/* Here's the first way, the "view" version: When your code calls request.pathInfo, the compiler says,
"HttpServletRequest doesn't have pathInfo. But it can implicitly convert to RichRequest.
I'm going to call RichRequest.servletRequestToRichRequest, and then call pathInfo on the result of that." */
class RichRequest(req: HttpServletRequest) extends Request {
def pathInfo = req.getPathInfo
}
object RichRequest {
implicit def servletRequestToRichRequest(req: HttpServletRequest) = new RichRequest(request)
@futurechimp
futurechimp / gist:1966777
Created March 3, 2012 15:48
let's mess with the scalatra docs
The current Scalatra book structure is as follows. Personally I find it confusing that some information can be found in more than one part of the book.
Table of Contents
Introduction
What is Scalatra?
Introduction
Git clone alternative
Dependencies
Building
Hello World Application
// This action receives the file upload.
post("/upload") {
processFile(fileParams("somefile"))
}
// This method processes the uploaded file in some way.
private def processFile(upload:FileItem) = {
val filePath:String = "/some/place/to/store/the/file"
val file:File = new File(filePath + upload.getName)
upload.write(file);
@futurechimp
futurechimp / gist:2250617
Created March 30, 2012 10:20
Padrino 0.10.6 problem on first request in JRuby
# Startup completes successfully. Hitting the first URL, the following error is thrown:
# java package `org.jruby.rack.name.name.name' does not have a method `split'
# this has also happened on javax.security.name.name.name
# Reading the stack trace, we can see that it's somehow related to
https://github.com/padrino/padrino-framework/blob/master/padrino-core/lib/padrino-core/reloader.rb#L106
# The code in question is the "split" method call on the first line of lock!:
@futurechimp
futurechimp / gist:3733579
Created September 16, 2012 18:14
@casualjim - Maybe some trouble with the whole LifeCycle / ScalatraBootstrap thing here?
> compile
[info] Compiling 6 Scala sources to /home/dave/workspace/manning-book/swagger-sample-app/target/scala-2.9.2/classes...
[error] /home/dave/workspace/manning-book/swagger-sample-app/src/main/scala/Bootstrap.scala:3: LifeCycle is not a member of org.scalatra
[error] import org.scalatra.LifeCycle
[error] ^
[error] /home/dave/workspace/manning-book/swagger-sample-app/src/main/scala/Bootstrap.scala:5: not found: type LifeCycle
[error] class ScalatraBootstrap extends LifeCycle {
[error] ^
[error] /home/dave/workspace/manning-book/swagger-sample-app/src/main/scala/Bootstrap.scala:10: value mount is not a member of javax.servlet.ServletContext
[error] context mount (new PetServlet, "/pet")
servlet_name [MyScalatraServlet]: Flowers
scala_version [2.9.2]:
version [0.1.0-SNAPSHOT]:
missing region "; do
case $@end$ tag
Can't parse chunk: (grep ^sbt.version project/build.properties)
versionString=${versionLine##sbt.version=}
echo "
line 1:7: unexpected char: '^'
at org.antlr.stringtemplate.language.ActionLexer.nextToken(ActionLexer.java:220)