Thursday, August 30, 2007
Key Changes
The band with the offensive name goes through a lot of key changes. This is just an extreme version of what rock does already. Where does the E-flat in F7 come from when you're playing in C? It sounds to me like they're going into the dominant more (playing the flat-five to imply a major second).
Wednesday, February 21, 2007
Two SQLServer SQL Tips
1) My transaction log file was gigantic (38GB). I fixed it by doing this:
deleting my log file and then doing this:
2) When I'm writing a script that creates tables, I often want to drop the table if it already exists. Instead of writing out the
Now that I think about it, I wonder whether T-SQL has the equivalent of Oracle's 'CREATE OR REPLACE'. That's basically what I've re-implemented here.
sp_detach_db MyDB,deleting my log file and then doing this:
exec sp_attach_db 'MyDB', '[pathToMDF]\MyDB.mdf'2) When I'm writing a script that creates tables, I often want to drop the table if it already exists. Instead of writing out the
if exists (select ...) drop table over and over again, I created a little stored procedure to do it:
CREATE PROCEDURE drop_table @tableName varchar(255) AS
if exists (select name from sysobjects where name=@tableName and type='U')
EXEC('DROP TABLE '+@tableName)
GO
Now I can drop a table like this: exec drop_table 'MyOldTable'. I created a similar procedure for dropping stored procedures. Now that I think about it, I wonder whether T-SQL has the equivalent of Oracle's 'CREATE OR REPLACE'. That's basically what I've re-implemented here.
Friday, January 26, 2007
FizzBuzz Exposes a Scheme Design Pattern?
I wrote a simple FizzBuzz in Scheme:
Then, inspired by Reg's "overthought" Ruby version, I did a Scheme version of his implementation:
The design pattern I'm talking about concerns multi-arg Scheme functions like
I've had to do this a few times writing Scheme functions, so maybe it's a design pattern! Mark Dominus has pointed out that patterns are a sign of weaknesses in programming languages. So, is this a real weakness in Scheme? Is there another way to recurse with a multi-argument function?
(define (number-interval f t)
(if (<= f t) (cons f (number-interval (+ f 1) t)) '()))
(define (fb n)
(cond
((eq? (remainder n 15) 0) 'FizzBuzz)
((eq? (remainder n 5) 0) 'Buzz)
((eq? (remainder n 3) 0) 'Fizz)
(else n)
)
)
(define (FizzBuzz m n) (map fb (number-interval m n)))
Then, inspired by Reg's "overthought" Ruby version, I did a Scheme version of his implementation:
(define (carbonate n name)
(lambda (x)
(if (and (number? x) (eq? (remainder x n) 0))
name
x
)
)
)
(define (compose . fns)
(define (compose-list functions)
(if (null? functions)
(lambda (x) x) ; identity function
(lambda (x)
(define (g y) ((compose-list (cdr functions)) y))
(g ((car functions) x))
)
)
)
(compose-list fns)
)
(define (FizzBuzz2 m n)
(map (compose (carbonate 15 'FizzBuzz) (carbonate 5 'Buzz) (carbonate 3 'Fizz)) (number-interval m n))
)
The design pattern I'm talking about concerns multi-arg Scheme functions like
compose, above. The composition of a list of functions is the composition of the first with the composition of the rest. But I can't see how Scheme's multi-argument-function syntax is amenable to the natural recursion. So I have to write the compose-list helper function.I've had to do this a few times writing Scheme functions, so maybe it's a design pattern! Mark Dominus has pointed out that patterns are a sign of weaknesses in programming languages. So, is this a real weakness in Scheme? Is there another way to recurse with a multi-argument function?
Subscribe to:
Comments (Atom)