Skip to content

Instantly share code, notes, and snippets.

@hchoroomi
hchoroomi / README.txt
Created April 14, 2012 06:03
Rails Assert pipeline changes for controller-specific assets
By default, Rails 3.2 loads everything in app/javascripts and everything in app/stylesheets on
every page, despite controller-specific file naming. If you want to load controller-specific
files only on views from their respective controllers, you need to change the manifests and the
layout. The basic idea is to NOT require the entire trees, but only specific subfolders, in the
manifests, and then load the controller-specific files separately in the layout.
Any file you DO want loaded on every page should be placed in app/assets/javascripts/general or
app/assets/stylesheets/general.
For this to work in production, you also need to ensure that the individual files are precompiled by modifying your production.rb file, listing all of the controller-specific files.
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
<cluster-user>admin</cluster-user>
<cluster-password>mypassword</cluster-password>
@hchoroomi
hchoroomi / jmx.scala
Created August 6, 2012 21:10 — forked from dln/jmx.scala
Reading some JMX MBeans from a Scala script
#!/bin/sh
exec scala $0 "$@"
!#
import scala.collection.JavaConversions._
import java.lang.management.{ManagementFactory, MemoryMXBean}
import java.net.URI
import javax.management.JMX
import javax.management.remote.{JMXConnectorFactory, JMXServiceURL}
@hchoroomi
hchoroomi / Secured.scala
Created August 19, 2012 20:19 — forked from guillaumebort/Secured.scala
HTTP Basic Authorization for Play 2.0
def Secured[A](username: String, password: String)(action: Action[A]) = Action(action.parser) { request =>
request.headers.get("Authorization").flatMap { authorization =>
authorization.split(" ").drop(1).headOption.filter { encoded =>
new String(org.apache.commons.codec.binary.Base64.decodeBase64(encoded.getBytes)).split(":").toList match {
case u :: p :: Nil if u == username && password == p => true
case _ => false
}
}.map(_ => action(request))
}.getOrElse {
Unauthorized.withHeaders("WWW-Authenticate" -> """Basic realm="Secured"""")
@hchoroomi
hchoroomi / fromScalaConsole.scala
Created August 25, 2012 10:56 — forked from anonymous/fromScalaConsole.scala
Post By ScalaConsole
trait Stringify {
val id: String
override def toString() = id
}
case class Username(id: String) extends Stringify
case class Password(id: String) extends Stringify
def login(u: Username, p: Password) = {
println("Login using u:" + u + " p:" + p)
@hchoroomi
hchoroomi / gist:3856435
Created October 9, 2012 03:39 — forked from plaurent/gist:3848586
Tent server
============================================================
Pakl's guide to a complete tentd and tentd-admin
and Nginx proxy:80 installation.
============================================================
Oct 7, 2012 -- Version 1.2 (adds missing commands for installing nginx)
History
Oct 7, 2012 -- Version 1.1 (adds missing nodejs repository)
Oct 7, 2021 - 1.0 initial release
@hchoroomi
hchoroomi / Application.scala
Created November 12, 2012 15:36 — forked from gre/Application.scala
Generate Zip on-the-fly with Play!> Framework (2.1+)
package controllers
import play.api._
import play.api.mvc._
object Application extends Controller {
def zip = Action {
import play.api.libs.iteratee._
import java.util.zip._
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
class Outer {
class Inner
type Type
}
trait Trait
object Object extends Outer {
val inner = new Inner
}
class OuterP[A] {
class InnerP[B]