Skip to content

Instantly share code, notes, and snippets.

@airekans
airekans / flatten.scm
Last active August 17, 2017 08:54
Interestng Scheme Snippets
(define flatten (seq)
(cond (((null? seq) '())
((pair? (car seq)) (append (flatten (car seq))
(flatten (cdr seq))))
(else (cons (car seq) (flatten (cdr seq)))))))
(define append (l1 l2)
(if (null? l1)
l2
(cons (car l1) (append (cdr l1) l2))))
@tmoertel
tmoertel / gist:5798134
Last active April 8, 2024 21:34
How to transform the vanilla recursive fib function into the iterative DP version through a series of mechanical steps.
# Transforming the vanilla recursive fib into the iterative DP version
# through a series of mechanical steps.
#
# For more on converting recursive algorithms into iterative ones, see:
# http://blog.moertel.com/posts/2013-05-11-recursive-to-iterative.html
# original function
def fib(n):
@miyukino
miyukino / InsertionSort.scm
Created May 26, 2013 08:42
Scheme: Insertion Sort
;; same as the merge function in MergeSort.scm
(define (insert L M)
(if (null? L) M
(if (null? M) L
(if (< (car L) (car M))
(cons (car L) (insert (cdr L) M))
(cons (car M) (insert (cdr M) L))))))
;; another insert function
;; need to modify the first para in insertionsort function to (car L)
@avescodes
avescodes / Editing Clojure with Emacs
Last active July 5, 2022 13:32
Get started editing Clojure in Emacs with this basic config.
Check out README.md to get started editing Clojure with Emacs.
@RyanKung
RyanKung / app.rkt
Last active January 19, 2024 15:20
Demo: A simple MVC-web-framework implementation with PLT Scheme (Racket)
;;By Jhen Kung, [email protected]
;;app.rkt
#lang racket(require web-server/servlet
web-server/servlet-env
"router.rkt")
(serve/servlet mordor
#:port 8080
#:servlet-path "/"
;run in chez scheme 8.4
;http://programmingpraxis.com/2013/01/15/translate-csv-to-html/
;TODO: read csv file
; parse csv file to a list
(define (string-split sep str)
(define (f cs xs) (cons (list->string (reverse cs)) xs))
(let loop ((ss (string->list str)) (cs '()) (xs '()))
(cond ((null? ss) (reverse (if (null? cs) xs (f cs xs))))
((char=? (car ss) sep) (loop (cdr ss) '() (f cs xs)))
(else (loop (cdr ss) (cons (car ss) cs) xs)))))
@tototoshi
tototoshi / rownum.sql
Created December 26, 2012 01:14
Grouped LIMIT in PostgreSQL: show the first N rows for each group
-- http://stackoverflow.com/questions/1124603/grouped-limit-in-postgresql-show-the-first-n-rows-for-each-group
-- http://www.postgresql.jp/document/9.2/html/tutorial-window.html
CREATE TABLE empsalary (
depname varchar(10) not null
, empno integer not null
, salary integer not null
);
INSERT INTO empsalary (depname, empno, salary) VALUES ('develop', 11, 5200);
@practicingruby
practicingruby / mrdi.md
Created December 19, 2012 22:29
Models, Roles, Decorators, and Interactions -- A modest proposal for a toned done version of DCI that isn't as janky as Concerns.

Models, Roles, Decorators, and Interactions

A modest alternative to DCI that might be worth further thought

One of the problems with advancing the discussion on DCI is that we lack a comparable alternative pattern that has the same goals, but favors a low ceremony approach. The closest thing we have to that is Rails concerns, but they are more like distant relatives of the DCI concepts rather than first cousins, and that makes comparisions between the two approaches not especially fruitful.

I am considering the idea of experimenting with my own paradigm that captures the intent and purity of DCI, but with the convenience of concerns. Please note that this is just the starting point of a conversation, it is NOT a promise of comercially available cold fusion or a cure for cancer. It's just a gist with an idea on it I'd like to hear your thoughts on.

What if we had a top-level topology that was split into Models, **Rol

@keighl
keighl / application.rb
Created December 19, 2012 16:42
Faster Rails asset precompilation via Capistrano .. just do it locally!
# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false
@a-chernykh
a-chernykh / eager_loading.rb
Created December 13, 2012 10:17
Undocumented options of doing eager loading in ActiveRecord
# 1st way - do it automatically
# AR decides if it's better to use JOIN or separate query
User.includes(:profile)
# -> join or separate query
# 2nd way - always use JOIN
User.eager_load(:profile)
# -> SELECT `users`.`id` AS t0_r0, ..., `profiles`.`user_id` AS t1_r1, ... FROM `users` LEFT OUTER JOIN `profiles` ON `profiles`.`user_id` = `users`.`id`
# 3rd way - always do separate query