- The best tutorials are in the introductory books. See below.
- Getting Started with Clojure - A detailed tutorial on getting a modern (as of Jan 2013) Clojure workflow going.
- Emacs Live is a nice development environment based on Emacs.
- Understanding The Clojure Development Ecosystem
- Clojure Docs Site is a community-driven doc site with good tutorials, and reference material going somewhat deeper than individual API docs.
- Functional Programming for the Rest of Us is a classic introduction to functional thinking
- [A comprehensive article on namespaces and different ways of requiring them](http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'riemann.common) | |
(require 'clojure.pprint) | |
(let [host "0.0.0.0"] | |
(graphite-server :host host | |
:port 5559) | |
(tcp-server :host host) | |
(udp-server :host host | |
:max-size 65000) | |
(repl-server :host host) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The MIT License (MIT) | |
# Copyright (c) 2014 Dave Clark | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Migrator | |
def migrate(&block) | |
current = migrations.detect { |m| m.version == current_version } | |
target = migrations.detect { |m| m.version == @target_version } | |
if target.nil? && @target_version && @target_version > 0 | |
raise UnknownMigrationVersionError.new(@target_version) | |
end | |
start = up? ? 0 : (migrations.index(current) || 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SignPendingOrdersService | |
def initialize(visit, user) # service context | |
@visit, @user = visit, user | |
end | |
def call # or execute | |
Order.for_visit(visit).pendings.each do |order| | |
order.activate! | |
OrderTemplate.find_or_create_template_for_order_and_record_template_usage!(order) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# naive implementation | |
class TwoWayDelegate | |
attr :_subject | |
def initialize(subject) | |
@_subject = subject | |
end | |
def inspect | |
"TwoWayDelegate <#{methods.sort}>" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Comments = Backbone.Collection.extend({ | |
url: function() { | |
return this.baseUrl + '/comments'; | |
}, | |
initialize: function(bootstrapData, options) { | |
this.baseUrl = options.baseUrl; | |
} | |
}), | |
Posts = Backbone.Collection.extend({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.9.3-p194-perf, rails, 10 unicorns | |
>siege -r 200 -c 10 -d 0 'http://localhost:9080/posts' | |
** SIEGE 2.72 | |
** Preparing 10 concurrent users for battle. | |
The server is now under siege.. done. | |
Transactions: 2000 hits | |
Availability: 100.00 % | |
Elapsed time: 117.59 secs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DATE=2012-06-01 | |
for version in `find $rvm_path/rubies/ -mindepth 1 -maxdepth 1 -type d -not -newermt $DATE | cut -d / -f 7`; do rvm remove $version; done |
In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.
A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval
.
You can find instance_eval
used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.
class Article < ActiveRecord::Base
NewerOlder