This demonstrates the math used to create the "seating chart"-style shapes on our House Outlook page.
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 'tidy' | |
| #Tidy.path = '/opt/local/lib/libtidy.dylib' # or where ever your tidylib resides | |
| Tidy.path = '/usr/lib/libtidy.A.dylib' | |
| def generate(files) | |
| tidy = Tidy.open(:show_warnings=>true) do |tidy| | |
| tidy.options.indent = 'auto' | |
| tidy.options.show_body_only = true | |
| tidy.options.output_xhtml = true |
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
| # comments example for .dat or .ledger files | |
| @smallexample | |
| ; This is a single line comment, | |
| # and this, | |
| % and this, | |
| | and this, | |
| * and this. | |
| # If you have a deeply nested tree of accounts, | |
| # it may be convenient to define an alias, for example: |
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
| BEGIN { | |
| int visited[node_t]; | |
| int visit(node_t n, edge_t e) { | |
| if (visited[n] == 0) { | |
| visited[n] = 1; | |
| for (e = fstin(n); e; e = nxtin(e)) { | |
| visit(e.tail, NULL); | |
| } |
Domain model is an effective tool for software development. It can be used to express really complex business logic, and to verify and validate the understanding of the domain among stakeholders. Building rich domain models in Rails is hard. Primarily, because of Active Record, which doesn't play well with the domain model approach.
One way to deal with this problem is to use an ORM implementing the data mapper pattern. Unfortunately, there is no production ready ORM doing that for Ruby. DataMapper 2 is going to be the first one.
Another way is to use Active Record just as a persistence mechanism and build a rich domain model on top of it. That's what I'm going to talk about in this article.
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
| (define (even lst) | |
| (cond | |
| [(empty? lst) empty] | |
| [else (cons (car lst) (odd (cdr lst)))] | |
| ) | |
| ) | |
| (define (odd lst) | |
| (cond | |
| [(empty? lst) empty] |
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
| # Here's a contrived example of a LEFT JOIN using ARel. This is an example of | |
| # the mechanics, not a real-world use case. | |
| # NOTE: In the gist comments, @ozydingo linked their general-purpose ActiveRecord | |
| # extension that works for any named association. That's what I really wanted! | |
| # Go use that! Go: https://gist.github.com/ozydingo/70de96ad57ab69003446 | |
| # == DEFINITIONS | |
| # - A Taxi is a car for hire. A taxi has_many :passengers. | |
| # - A Passenger records one person riding in one taxi one time. It belongs_to :taxi. |
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 'base64' | |
| require 'cgi' | |
| def show_session(cookie) | |
| Marshal.load(Base64.decode64(CGI.unescape(cookie.split("\n").join).split('--').first)) | |
| 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
| (define (return v) (lambda (s ks kf) (ks v s))) | |
| (define fail (lambda (s ks kf) (kf))) | |
| ; >>= | |
| (define (bind a f) | |
| (lambda (s ks kf) | |
| (a s | |
| (lambda (av s1) ((f av) s1 ks kf)) | |
| kf))) |
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
| ;;;; S-expression to SECD instruction Compiler ;;;; | |
| ;;; 2012 Minori Yamashita <[email protected]> ;;add your name here | |
| ;;; | |
| ;;; reference: | |
| ;;; http://www.geocities.jp/m_hiroi/func/abcscm33.html | |
| ;;; | |
| (load "./SECD.scm") | |
| ;;; Helpers ;;; |