The newLISP on Rockets Blog

Currently running newLISP on Rockets version: 0.48

Cookie Conundrum Continues...


Post #: 23
Date: 2012-09-25 22:06:13.000
Author: Rocket Man

I've been thinking about the Cookie Conundrum and I think it goes beyond just Cookies...

If I want to do a redirect on a page, as Dragonfly does with Response:redirect (something I use all the time) I have to set the headers to be a 302 Redirect. Again, these headers have to be sent before any other text is shown, so it has to be printed at the beginning.

I have changed the way Rockets works to use the Dragonfly model of just loading everything into a big global variable called STDOUT, then delaying printing until the end where you print the headers first and then STDOUT. Only I can't force the delay because there isn't a main program in charge of loading each page, so you have to remember to add the new function (display-page) at the end of your pages for it to work.

Hmm. Not sure about this. I'll think about it some more.



Views: 2062


Thinking about cookies...


Post #: 22
Date: 2012-09-25 00:07:42.000
Author: Rocket Man

In order to get separate users to sign on and post messages, I need to set some cookies. This leads me to what I call a Cookie Conundrum.

I can define a function to set cookies that is executed somewhere in the page (like rockets-main.lsp) But cookies are set in the header, using the line Set-Cookie. The header is the first thing printed out by the script, and I won't know what the cookie is until later in the script.

What Dragonfly does is caches everything being (print)ed and (println)ed into a big old global variable called STDOUT. Then at the very end of the script it prints the headers (which have already been calculated by the script) followed by STOUT. This involves overriding (changing the default behavior) of (print) and (println). I could do that, but is there a way to do it differently? Can you set a cookie and somehow have it remember to print that cookie in the next header on the following page?

It's something to think about...



Views: 2015


It's fast enough...


Post #: 21
Date: 2012-09-21 06:49:09.000
Author: Rocket Man

Said Han Solo.

No, I'm totally going to add that stuff. Very cool.



Views: 2232


numbies5


Post #: 20
Date: 2012-09-21 00:01:21.000
Author: Rocket Man

There's no millisecond thingy to say how fast this or how many resources were used in its making.

Comments (1)

Views: 2178


foursies


Post #: 19
Date: 2012-09-18 00:17:03.000
Author: Rocket Man

you see, that's why I can't be left alone with a programming language, I don't know shit.

Since we all live as RocketMan - numbies will be my sig



Views: 2056


Spell check


Post #: 18
Date: 2012-09-18 00:14:30.000
Author: Rocket Man

That service would be provided by your web browser... :)



Views: 2113


threesies


Post #: 17
Date: 2012-09-18 00:12:14.000
Author: Rocket Man

Well, tried to just enter something in the top box and got sent away but now I am back about to make a non historical supporting post. There's spell check in here too?

How cool is that?



Views: 2120


Where's the Code?? WHERE'S THE CODE???


Post #: 15
Date: 2012-09-17 23:28:59.000
Author: Rocket Man

This, apparently, being the first thing that gets asked.

Well, it's not much, but it's here:
https://github.com/newlisponrockets/newLISP-on-Rockets

Comments (1)

Views: 2106


testing


Post #: 14
Date: 2012-09-17 21:53:14.000
Author: Rocket Man

Encoding fun...

What happens if someone puts in a URL? The framework should translate the special characters, but it is the blog software itself that should translate it into a clickable link.

Of course, that doesn't mean I can't make a function to turn URLs into links automatically (and do other post-entry formatting of blog post text) and include it in Rockets...
http://arstechnica.com/science/2012/09/curiosity-rolls-on-as-instrument-checkout-continues-on-mars/



Views: 2557


Utilizing the power of LISP macros


Post #: 13
Date: 2012-11-02 17:24:39.000
Author: Rocket Man

Today's function turned out to be well suited for a macro. (create-record) takes a couple of arguments. The first is a string which holds the name of the table you are updating. The rest is kind of cool. You put in a bunch of variable names--any number is fine--and what you do is make the variable name the same as the FIELD name in your table. Then the macro takes the names and values of these variables and constructs a valid SQL statement (after filtering each value for SQL injection issues)

So, for example, to add a post in this blog, I just have to write:

(create-record "Posts" Id PosterId PostDate PostSubject PostContent)

and it generates a valid SQLite query to insert the values into the field names that are the variables Id, PosterId, etc.

The magic comes from newLISPs (sym) function, which converts a string into a valid symbol, and the (args) feature of newLISP macros, which allow a dynamic number of arguments to be passed to the macro.

Here's the code that converts the variable names into symbols:

(dolist (s (rest (args)))
(set 'temp-index-num (string 'idx)) ; we need to number the symbols to keep them in the correct order
(if (= (length temp-index-num) 1) (set 'temp-index-num (string "0" temp-index-num))) ; leading 0 keeps the max at 100.
(sym (string temp-index-num s) 'DB))


I have to prepend a numeric value to the symbols to ensure they get posted into the list (symbols 'DB) in the correct order-- right now the limit is 100 fields but I could easily bump this to 1000 if I need to, or even higher... I want to keep this limit in here for now as a kind of sanity check though.

So, the C part of CRUD is done.. just three more parts to go!

Comments (1)

Views: 2171