Skip to content

Instantly share code, notes, and snippets.

View boutros's full-sized avatar

Petter Goksøyr Åsen boutros

  • Oslo Public Library
  • Oslo
View GitHub Profile
@boutros
boutros / gist:2983222
Created June 24, 2012 13:22 — forked from weavejester/gist:1001206
Clojure on Heroku
~/$ lein new ring-on-heroku
Created new project in: /home/jim/Development/ring-on-heroku
~/$ cd ring-on-heroku
~/ring-on-heroku$ echo 'web: lein run -m ring-on-heroku.core' > Procfile
~/ring-on-heroku$ cat > src/ring_on_heroku/core.clj
(ns ring-on-heroku.core
(:use ring.util.response
ring.adapter.jetty))
(defn app [req]
# Here's the example from rpsec-given
#
# Initially, I thought I'd like the Given/When/Then
# replacement for RSPec's cruddy "it", but I don't
# I find this test very hard to follow, as there are
# several statements that create state via variables
# in a subtle and unclear way. Further, we have some
# strange indirection with the "stack_with(initial_contents)".
# It seems like we're adding a lot of complexity just to save
# a simple variable assignment.
@boutros
boutros / Gemfile
Created July 7, 2012 18:29 — forked from ecuageo/Gemfile
goliath demo
source 'http://rubygems.org'
gem 'goliath', :git => 'https://github.com/postrank-labs/goliath.git'
gem 'yajl-ruby'
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git', :require => 'eventmachine'
gem 'em-http-request', :git => 'https://github.com/igrigorik/em-http-request.git'
gem "em-synchrony", :git => 'https://github.com/igrigorik/em-synchrony.git'
@boutros
boutros / api.rb
Created July 9, 2012 15:43 — forked from lucatironi/api.rb
Snippets for an API with grape
# Server App
# This file must be in lib/myapp/api.rb
module MyApp
module Entities
class Products < Grape::Entity
expose :id, :code, :name, :short_description
expose :description, :unless => { :collection => true }
expose (:category) { |model, options| model.category.name }
expose (:brand) { |model, options| model.brand.name }
end
@boutros
boutros / gist:3755497
Created September 20, 2012 12:01 — forked from gorsuch/gist:1418850
clojure uuid
(defn uuid [] (str (java.util.UUID/randomUUID)))
@boutros
boutros / callbacksarehard.js
Created September 24, 2012 09:49 — forked from isaacs/callbacksarehard.js
let's go shopping!
// before
mainWindow.menu("File", function(err, file) {
if(err) throw err;
file.openMenu(function(err, menu) {
if(err) throw err;
menu.item("Open", function(err, item) {
if(err) throw err;
item.click(function(err) {
if(err) throw err;
mainWindow.getChild(type('Window'), function(err, dialog) {
@boutros
boutros / uuid.rb
Created September 25, 2012 12:28
Generate uuid from ruby
"x_#{`uuidgen`.strip}"
@boutros
boutros / gist:3798492
Created September 28, 2012 07:40
Multiple Goliath WebSocket endpoints
require "rubygems"
require "bundler/setup"
require "goliath"
require "goliath/websocket"
class User < Goliath::WebSocket
def on_open(env)
env.logger.info("WS OPEN")
end
@boutros
boutros / addendum.markdown
Created October 1, 2012 15:40 — forked from geemus/addendum.markdown
API - Assumptions Probably Incorrect
@boutros
boutros / cl-graph.clj
Created October 11, 2012 18:21 — forked from martintrojer/cl-graph.clj
core.logic graph blog
(ns cl-graph
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
;; Directed Acyclic Graphs
(defrel edge a b)
;; a
;; |