Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Jeremy Reimer

#1
Hey cool, I was about to come here and post that I had made this, but someone did it for me!



I'm testing it as a replacement for my old Drupal/PHPBB setup.  Obviously there are far fewer features (no search for example) but this is just a 0.2 product.. I've only put in 4-6 weeks of part-time work on it so far.



Please let me know what you think!  The home url is: http://jeremyreimer.com/monarch/main">http://jeremyreimer.com/monarch/main or just go to http://jeremyreimer.com">http://jeremyreimer.com redirects you there.
#2
Sorry, I had left this issue for a long time while I was working on other projects, but now I'm revisiting it and I'm still having the problem.  (In the meantime I did learn how to use ref to extract $POST data, heh)



I've filed an issue on github about it: https://github.com/taoeffect/dragonfly-newlisp/issues/issue/1">https://github.com/taoeffect/dragonfly- ... es/issue/1">https://github.com/taoeffect/dragonfly-newlisp/issues/issue/1



EDIT: In the mean time, I was able to use the following code to solve my problem with the missing binary data I talked about above.  Using the base64-enc and base64-dec functions seemed to work perfectly, and allowed me to upload a .JPG file successfully to the server:



(set 'encoded-data (base64-enc (last (($POST) (chop (ref '"uploaded_data" ($POST)))))))
(write-file "uploadedfile.jpg" (base64-dec encoded-data))


I still can't seem to grab the file name itself from ($POST) but this is at least some progress.



EDIT: My solution was to add the file name into an additional text box, and change it using a Javascript onChange event when the user clicks on the file dialog:



<form name='FileUpload' action='fileupload.cgi' method='POST' enctype='multipart/form-data'>
<input type='file' id='uploadName' name='uploaded_data' onChange='this.form.textname.value = this.value'>
<input type='text' name='textname'>
<input type='submit' value='Upload' name='submit'>
</form>


This will add the file name to the ($POST) data when you submit the form.  I could make the 'textname' field hidden if I wanted.  On some browsers/platforms it adds a "C:\fakepath\" to the name, but that's easy enough to strip out:



; take out stupid fake path if it's there
(set 'file-name (replace "C:\fakepath\" file-name ""))

(println "<p>File name..." file-name)

(write-file file-name (base64-dec encoded-data))

(println "<P>Uploading file... complete.  File is at <a href=" file-name ">" file-name "</a>")


Anyway this seems to work.  I can upload files now from Dragonfly!  Woo!
#3
Just a quick revisit to this topic:



I put the giant list in a SQLite database for the project I was working on, and it works great.  SQLite is just as awesome as everyone says it is, and it works really really well with newLISP.  Also, it has a feature where it can store the database in-memory if really fast response times are required.
#4
I figured it out!  



I had to Google some PHP solutions to get the answer.  Apparently, you have to specify a few things:



1. The cookie should be set originally with the right domain, so



(Response:cookie "monarch" username (date-value 2011 12 12) "/" "jeremyreimer.com") ; open a cookie to say we are signed in


2. When you delete the cookie, you have to keep all the parameters the same, only change the date to some time in the past, AND, set the value to "0" (nil won't work, despite the documentation saying it will)



(Response:cookie "monarch" "0" (date-value 2009 12 12) "/" "jeremyreimer.com") ; delete cookie


Then the cookie is deleted properly.  I've tested this a bit with different names for the cookie and it seems to work.  So hopefully if anyone else has this problem they can get the answer. :)
#5
Hi again,



I'm building a simple web application in newlisp using the Dragonfly framework, which I really like using.  However I can't seem to delete cookies using the (Response:cookie) command.



I can set the cookie easily using this code:



(Response:cookie "monarch" username (date-value 2011 12 12) "/") ; open a cookie to say we are signed in


That makes a cookie and I can check for the presence of the cookie by searching for it in ($COOKIES), and even by searching cookies in my web browser.  It's definitely there.  The problem is that I can never get rid of it!



According to the Dragonfly reference manual, the way to get rid of the cookie is to reference it and assign it a value of "nil":



(Response:cookie "monarch" nil) ; delete cookie


But this doesn't work!  The cookie is there forever (well, until it expires in 2011).  How can I get rid of it?



I'm using newLISP 10.2.8 and Dragonfly 0.70 on Apache on Linux.
#6
Thanks for your quick reply.  I'm running under Apache on Linux.  I took the size attribute out but the same issue still exists.  I'll fiddle around with it a bit and try it on another Linux server I have and see if I can get it to work.
#7
Hey, that's great!  I'm a bit unsure on what to do with ($FILES), however.  When I try to see what's in it with (println ($FILES)), it just comes back "()".  (length ($FILES)) returns 0.  There's lots of data in ($POST) but nothing in ($FILES).  Am I doing something wrong?  I'm using the same upload HTML as before:



<form name="FileUpload" action="upload-10.cgi"
                        method="POST" enctype="multipart/form-data">
<input type="file" name="uploaded_data" size="40">
<input type="submit" value="Upload" name="submit">
</form>


Thanks for your help!
#8
Okay, I am having some problems parsing the $POST data.  Basically, I can extract the raw text inside the [text] brackets using this code:



 (setq posted (rest (rest (rest (rest (rest (rest (rest (chop (string (rest (last ($POST)))) 8)))))))))


But the main problem is that as soon as it gets converted to a string, all sorts of blank characters are gone.  So my original file (in binary) looks something like this:



ÿØÿà JFIF  ` `  ÿá hExif  II*         >      


But once it gets translated into a string, it looks more like this:



ÿØÿàJFIF``ÿáhExifII*>


How can I keep these characters from dropping?
#9
Something must be draining the stdin pipe, because (read-buffer (device) buffer 1024) returns nil. :(   I suppose I could parse the data in $POST, but it looks like this:



(("submit" "Upload") ("uploaded_data" [text] ----binary data here--- [/text]))


Which might work for saving a file if I could parse it correctly, but it doesn't contain the file name.
#10
Hmm.. I tried using your exact scripts, with the same permissions, and got the same problem.



I'm running under Dragonfly, and both files live under the /views/ sub-directory, could this be causing the problem?



EDIT: I checked by changing the code to:



(set 'infile (open "./upload-file" "write"))
  (println "<p> Writing file...")
(while (read-buffer (device) buffer 1024)
   (println "<p>DOOD WE ARE IN YUR FILEZ WRITINGSZ" infile buffer))
(close infile)


And it never prints out the "DOOD" message, so there is something about the (while (read-buffer (device) buffer 1024) statement where it is never true.  The uploaded file is there when I print $POST, however (I've checked with both text and image files) so the data is being sent somewhere, but maybe just isn't being stored in the buffer?



EDIT: I'm still trying to figure out what's going on, but I'm not sure what's happening in this code:



; read data into intermediate file
(set 'infile (open "upload-file" "write"))
(while (read-buffer (device) buffer 1024)
   (write-buffer infile buffer))


According to the manual, (device) is a shorthand for whatever file handle was recently opened (which I assume is (open "upload-file" "write)).  But this is a temporary file, so there is nothing in it.  The manual says that (read-buffer) works like this:



Reads a maximum of int-size bytes from a file specified in int-file into a buffer in sym-buffer.


But if there is nothing in the file, why would it loop here at all?  Isn't it reading from "upload-file" and copying everything in that file to the symbol "buffer"?  But there is nothing in "upload-file" in the first place...



I mean, obviously the code works on your site, so the issue is somewhere else, like maybe my server configuration.  But I don't understand what the code is trying to do here.
#11
Hi folks,



I'm trying to get the upload.cgi script to work from this thread:



http://newlispfanclub.alh.net/forum/viewtopic.php?f=2&t=2585">http://newlispfanclub.alh.net/forum/vie ... f=2&t=2585">http://newlispfanclub.alh.net/forum/viewtopic.php?f=2&t=2585



I'm running Apache 2 on Ubuntu Linux.  I've used the version of the script for newLISP 10 but no matter what I do I get the error "wrong upload format" when the code reaches this point:



(if (not (find ".*filename="(.*)".*" disposition 1))
(throw-error "Error: wrong upload format"))


I've set permissions for the upload directory to 755 and upload.cgi to 777.  When I check my server, it seems like the script is creating the temporary file "upload-file", but never populating it with anything, as it always ends up as 0 bytes.  Since there is never anything in the temporary file, the symbol "disposition" which is set as (read-line "upload-file"), ends up being nil, and thus the script throws the error at the above point.



Is there something wrong with the script?  Does it have to be updated for newlisp 10.2.8?  It seems to me that it is never executing this while loop:



(while (read-buffer (device) buffer 1024)
   (write-buffer infile buffer))


And thus the file "upload-file" never gets written with anything.  



Thanks for your help!
#12
Well, that isn't really possible in this case, as the text the user would most want to see comes from the list itself.  Also, without using AJAX it isn't possible to delay loading of any part of the page until the list has loaded.



Doesn't Dragonfly itself have to keep all of its context in memory when it runs?
#13
Hi folks,



Say I have a large list (say, 40,000 records) that takes about five seconds to load with the load("40klist.lsp") command.  I'd like to keep this list in memory when the user navigates to another web page on the same site, so that each page that needs to reference the list won't have the same five second delay.  Is this at all possible?  



Thanks!
#14
Thanks, I upgraded to 10.2.8 and the problem went away.  Sweet!
#15
Hi all! Thanks for your incredible help so far.



I've come across a puzzler: I am using xml-parse to extract data from an XML feed and into a newLISP list.  This is the function I'm using:



(define (parse-xml-data str)
   (xml-type-tags nil nil nil nil)
      (let ((xml (xml-parse str 15 'Yamato)))
        (or xml (throw-error (xml-error)))))


I'm using "'Yamato" to try and save the resulting list in a different context, so that any symbols that are created don't conflict with existing symbols in newLISP's MAIN context, or in the Dragonfly context.  However, this doesn't seem to work, as I get the resulting SXML list back:



((Yamato:document (Yamato:element ((Yamato:name "First") (date "4/23/2010")) (Yamato:data "This is the first element")) (Yamato:element ((Yamato:name "Second") (date "4/23/2010")) (Yamato:data "This is the second element"))))


Every symbol is now in the "Yamato" context, except for "date".  "date" is a symbol in the Dragonfly context.  I want it also to be in the Yamato context, but it seems like the Dragonfly context is overriding this when xml-parse converts the XML element names into symbols.  How can I stop this and force every element into the Yamato context?  



Thanks for your help!