Skip to content

Instantly share code, notes, and snippets.

;; this file is a walkthrough of Moustache features, a web framework for Clojure
;; http://github.com/cgrand/moustache/tree/master
;; Moustache allows to declare routes, apply middlewares and dispatch on http methods.
;; Moustache is compatible with all frameworks built on Ring, including Compojure
(ns demo
(:use net.cgrand.moustache)
(:use [ring.adapter.jetty :only [run-jetty]])) ;; hmmm Ring without servlets
require 'rubygems'
require 'nokogiri'
require 'json'
minimal = {
'name' => 'minimal_vm',
'memory' => 512,
'hd' => '/var/lib/libvirt/images/fc10-x86-64-xen.img',
'cdrom' => '/home/bb/os_images/Fedora-10-x86_64-DVD.iso',
'boot' => ['hd', 'cdrom']
@minimal
minimal / jetty.clj
Created January 20, 2010 01:17
Websockets with clojure + jetty
;; Copyright (c) James Reeves. All rights reserved.
;; The use and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which
;; can be found in the file epl-v10.html at the root of this distribution. By
;; using this software in any fashion, you are agreeing to be bound by the
;; terms of this license. You must not remove this notice, or any other, from
;; this software.
(ns compojure.server.jetty
"Clojure interface to start an embedded Jetty server."
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)
(-> "?foo=1&bar=2&baz=3"
(.substring 1)
(.split "&")
(->>
(map #(vec (.split % "=")))
(into {})))
;=> {"foo" "1", "bar" "2", "baz" "3"}
;; (match [x y z]
;; [_ f# t#] 1
;; [f# t# _ ] 2
;; [_ _ f#] 3
;; [_ _ t#] 4)
(def pm2 (pattern-matrix [(pattern-row [wildcard (pattern false) (pattern true)] :a1)
(pattern-row [(pattern false) (pattern true) wildcard] :a2)
(pattern-row [wildcard wildcard (pattern false)] :a3)
(pattern-row [wildcard wildcard (pattern true)] :a4)]
@rottenbytes
rottenbytes / cookbooks-tests-libraries-noah.rb
Created October 23, 2011 18:21
Integrating noah into chef
module Noah
def noah_get_host(hostname)
require "net/http"
require "json"
noah_server="http://10.251.12.10:9292"
url = URI.parse("#{noah_server}/hosts/#{hostname}")
req = Net::HTTP::Get.new(url.path)
resp = Net::HTTP.new(url.host, url.port).start do |http|
@mklabs
mklabs / bootstrap-plugins.txt
Created December 2, 2011 11:23
h5bp + twitter bootstrap integration
bootstrap-tooltip.js
bootstrap-popover.js
bootstrap-alert.js
bootstrap-button.js
bootstrap-carousel.js
bootstrap-collapse.js
bootstrap-dropdown.js
bootstrap-modal.js
bootstrap-scrollspy.js
bootstrap-tab.js
@ulfmagnetics
ulfmagnetics / joyent-smartos.erb
Created February 6, 2012 18:42 — forked from benjaminws/joyent-smartos.erb
joyent-smartos.erb
# shove this in ~/.chef/bootstrap/joyent-smartos.erb
# run knife bootstrap <hostname> -d joyent-smartos
bash -c '
if [ ! -f /opt/local/bin/chef-client ]; then
cd /tmp
pkgin -y install gcc-compiler gcc-runtime gcc-tools-0 ruby19 scmgit-base scmgit-docs gmake
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.10.tgz
tar -xzf rubygems-1.8.10.tgz
cd rubygems-1.8.10
@jclulow
jclulow / 00_info.md
Created May 5, 2012 23:46
SmartOS rc.local

So, to get something like /etc/rc.local you can use the custom SMF import facility. (See the source for more information about how this actually works.)

/opt is mounted out of zones/opt by default. You can create a directory /opt/custom/smf and populate it with SMF manifests. Any manifests you put in there will be imported by SmartOS when it boots. Below is an example SMF manifest that simply starts /opt/custom/bin/postboot, a self-explanatory shell script that you can use like /etc/rc.local.

Note that it would likely be better to customise and respin your own images, as putting a bunch of platform state in the zones pool undoes some of the benefits of the ramdisk platform architecture that SmartOS has.