Skip to content

Instantly share code, notes, and snippets.

@hchoroomi
hchoroomi / config.ru
Created March 1, 2012 13:50
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
require "rails"
@hchoroomi
hchoroomi / workers.rake
Created March 19, 2012 10:16 — forked from karmi/workers.rake
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
@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>
# ~/.osx — http://mths.be/osx
###############################################################################
# General UI/UX #
###############################################################################
# Set computer name (as done via System Preferences → Sharing)
scutil --set ComputerName "MathBook Pro"
scutil --set HostName "MathBook Pro"
scutil --set LocalHostName "MathBook-Pro"
@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