Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'rake'
module FileWatchHandler
def execute
EM.stop_event_loop
end
alias :file_modified :execute
alias :file_moved :execute
(define-syntax b
(syntax-rules ()
((b) 1)))
(define-syntax a
(syntax-rules ()
((a) (b))))
(define-syntax b
(syntax-rules ()
(define-syntax forever
(syntax-rules ()
((_) (forever))))
; (forever) ; don't return ...
(define-syntax a
(syntax-rules ()
((_) (if #t 1 (forever)))))
(define-syntax l
(syntax-rules ()
((_ P Q ...) (lambda (P) Q ...))))
(define c 1)
(define-syntax macro
(syntax-rules ()
((_ P) ((l c (list c P)) c))))
(define-syntax macro
(syntax-rules ()
((_ (A ...) (B ...)) (list '(A B) ...))))
(macro (1 2 3) (4 5)) ;; => ((1 4) (2 5))
@draftcode
draftcode / partial-continuation.scm
Created May 28, 2011 09:27
shift/reset implementation by macro
(define resetcont #f)
(define-syntax reset
(syntax-rules ()
((_ F ...)
(let/cc c
(set! resetcont c)
(let ((r (begin F ...)))
(resetcont r))))))
@draftcode
draftcode / expr_parser.cpp
Created June 12, 2011 13:23
四則演算の構文解析
// 四則演算の構文解析
// http://algorithms.blog55.fc2.com/blog-entry-154.html
// http://www.prefield.com/algorithm/string/parser.html
// を見ながら書いてみた.
#include <iostream>
#include <string>
using namespace std;
typedef pair<int, int> result;
#define value first
#import <Cocoa/Cocoa.h>
@interface MyController : NSObject
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
@end
@implementation MyController
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSUInteger winStyle = (NSTitledWindowMask | NSClosableWindowMask
#include <Carbon/Carbon.h>
int main(void) {
CTFontCollectionRef collection = CTFontCollectionCreateFromAvailableFonts(NULL);
if (collection) {
CFArrayRef array = CTFontCollectionCreateMatchingFontDescriptors(collection);
CFIndex arrayNum = CFArrayGetCount(array);
for (CFIndex i = 0; i < arrayNum; i++) {
CFStringRef attribute = CTFontDescriptorCopyAttribute(
fib := method(n,
if (n == 1 or n == 2, return 1)
p1 := 1
p2 := 1
for (i, 3, n,
temp := p1
p1 := p1 + p2
p2 := temp)
return p1