Deploy public racket website - racket

I am trying to deploy a website that others can access in Racket to my school's server, but I am not sure what to do. For HTML files just having index.html in a public_html does the job. I can get the program below to work on my local machine (it deploys at localhost:8000/test.rkt), but I can't find any tutorial mentioning how to not use localhost.
#lang racket
(require web-server/servlet)
(provide/contract (start (request? . -> . response?)))
(define (start request)
(response/xexpr
`(html
(head (title "TEST"))
(body (p "1 2 3")))))
(require web-server/servlet-env)
(serve/servlet start
#:launch-browser? #f
#:quit? #f
#:listen-ip #f
#:port 8000
#:servlet-path
"/test.rkt")

Related

ox-hugo github actions : Debugger entered--Lisp error: (void-function org-hugo-export-wim-to-md) Error: Process completed with exit code 255

Im trying to deploy my hugo site on github actions. Im using the following github action which does the following :
1.On Ubuntu
2.Setup up emacs
3.git clone ox-hugo package
4.ox-hugo package should convert my .org files to .md
setup and build using Hugo and deploy
https://gist.github.com/shwetarkadam/d890b7054b65fe21b63609ca03650bdc
I'm facing an issue on step 4 where I encounter the following error on GitHub action :
Run emacs ./config.org --batch -L ./ox-hugo -L ox-hugo.el --eval="(org-hugo-export-wim-to-md t)" --kill
Debugger entered--Lisp error: (void-function org-hugo-export-wim-to-md)
(org-hugo-export-wim-to-md t)
eval((org-hugo-export-wim-to-md t) t)
command-line-1(("./config.org" "-L" "./ox-hugo" "-L" "ox-hugo.el" "--eval=(org-hugo-export-wim-to-md t)" "--kill"))
command-line()
normal-top-level()
Approaches tried till now :
Changing (org-hugo-export-wim-to-md t) to (org-hugo-export-wim-to-md :all-subtrees)
Adding the expression (org-hugo-export-wim-to-md :all-subtrees) in single quotes and double quotes.
I happened to be working on a similar problem today. I had searched for guidance on it and I stumbled across Batch export of org-mode files from the command line which led me to fniessen/orgmk and in orgmk.el in particular.
After experimenting in my *scratch* buffer and asking Emacs' various help facilities a few questions, I bludgeoned my way to a standalone file containing Emacs Lisp code that appears to work independently of my initialization files.
$ touch export.el
$ emacs -q --batch -l export.el
Designating package sites
Designating package site melpa-stable => https://stable.melpa.org/packages/
Designating package site melpa => https://melpa.org/packages/
Designating package site gnu => https://elpa.gnu.org/packages/
Installing package ox-hugo
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
‘ox-hugo’ is already installed
Exporting org subtrees to hugo from content.org
1 files scanned, 0 files contains IDs, and 0 IDs found.
[ox-hugo] 1/ Exporting ‘Redacted site title’ ..
[ox-hugo] 2/ Exporting ‘Posts’ ..
[ox-hugo] 3/ Exporting ‘Redacted post title’ ..
[ox-hugo] Exported 3 subtrees from content.org in 0.510s (0.170s avg)
Exporting all org subtrees in all files in /redacted/directory
$ find content -newer export.el
content
content/_index.md
content/posts
content/posts/redacted-post-title.md
content/posts/_index.md
(Some names have been changed to protect the guilty er um I mean innocent.)
The file export.el contains:
(defvar my/package-archives
(list
(cons "melpa-stable" "https://stable.melpa.org/packages/")
(cons "melpa" "https://melpa.org/packages/")
(cons "gnu" "https://elpa.gnu.org/packages/")))
(defvar my/packages-to-install '(ox-hugo))
(defun my/designate-package-site (site)
(message "Designating package site %s => %s" (car site) (cdr site))
(add-to-list 'package-archives site t))
(defun my/designate-package-sites ()
(message "Designating package sites")
(mapcar #'my/designate-package-site my/package-archives))
(defun my/install-package (pkg)
(message "Installing package %s" pkg)
(ignore-errors (package-install pkg)))
(when (locate-library "package")
(require 'package)
(my/designate-package-sites)
(package-initialize)
(unless package-archive-contents (package-refresh-contents))
(mapcar #'my/install-package my/packages-to-install))
(defun my/batch-ox-hugo-file (file)
(message "Exporting org subtrees to hugo from %s" file)
(let ((all-subtrees t)
(any-visibility nil))
(with-current-buffer (find-file-noselect file)
(org-hugo-export-wim-to-md all-subtrees any-visibility))))
(defun my/batch-ox-hugo-directory (directory)
(message "Exporting all org subtrees in all files in %s" directory
(let ((default-directory (expand-file-name directory)))
(mapcar #'my/batch-ox-hugo-file
(file-expand-wildcards "*.org")))))
(my/batch-ox-hugo-directory default-directory)
The execution environment where I developed this is Emacs 28.2 on FreeBSD 13.1.
I haven't tried it out with Github Actions yet, but that's my next step.

Run `create-react-app` from within Common Lisp

Assuming that a local system has create-react-app installed (npm i -g create-react-app), I want to run it with parameters from within a Common Lisp file. What's the best way to do this?
as far as i know, the potrable solution is uiop:run-program, since your cl distribution probably has the asdf included.
CL-USER> (uiop:run-program "create-react-app" :output t :error-output t)
;;Please specify the project directory:
;; create-react-app <project-directory>
;;For example:
;; create-react-app my-react-app
;;Run create-react-app --help to see all options.
;;; Debugger entered on #<UIOP/RUN-PROGRAM:SUBPROCESS-ERROR {10018B83A3}>
this one reports error, as the create-react-app itself does for no args.
(uiop:run-program "create-react-app my-new-shiny-app" :output t :error-output t)
succeeds, and creates app in your cwd.
you can wrap it into a function like this, for example:
(defun create-react-app (app-path &key verbose info scripts-version template use-npm use-pnp typescript)
(let ((cmd (format nil "create-react-app ~a ~
~#[--verbose~*~] ~
~#[--info~*~] ~
~#[--scripts-version ~a~] ~
~#[--template ~a~] ~
~#[--use-npm~*~] ~
~#[--use-pnp~*~] ~
~#[--typescript~*~]"
app-path verbose info scripts-version template use-npm use-pnp typescript)))
(format t "executing shell command: ~a~%" cmd)
(uiop:run-program cmd :output t :error-output t)))
(create-react-app "my-new-shiny-app" :template "cra-template-quickstart-redux" :use-npm t)
havent thoroughly tested it, but it should work.

Racket web server write file error

I write a web program to write file,and read file.And it failed.
And the program code is following:
#lang web-server/insta
(define (start request)
(index-wrap request))
(define (index-wrap request)
(define (response-generator embed/url)
(response/xexpr
`(html
(head (title "test"))
(body
(h1 "Test Write")
(form ((action ,(embed/url write-handler)))
(input ((type "submit"))))))))
(define (write-handler request)
(call-with-output-file "write_file"
#:exists 'truncate
(lambda (out) (print "hello,world" out)))
(index-wrap request))
(send/suspend/dispatch response-generator))
And when you click the button,it occurs an error:
call-with-output-file: cannot open output file
path: /usr/share/racket/pkgs/web-server-lib/web-server/default-web-root/htdocs/write_file
system error: Permission denied; errno=13
And I also write a test program to test the call-with-output-file function,and it write file successful.And my test program code are following:
#lang racket
(call-with-output-file "write_other"
#:exists 'truncate
(lambda (out) (print "hello,racket" out)))
So what's the problem about it?
Try
(define (write-handler request)
(displayln (list "HERE" (current-directory)))
(call-with-output-file "write_file"
#:exists 'truncate
(lambda (out) (print "hello,world" out)))
(index-wrap request))
(send/suspend/dispatch response-generator))
to see which directory you are trying to write to. I suspect the web-server has changed directory to something else than you expect.
EDIT
Now you know that the path is
/usr/share/racket/pkgs/web-server-lib/web-server/default-web-root/htdocs/
you have two options.
Change the permissions of the folder
Start the web-server somewhere else
The easiest is to change the permissions:
cd /usr/share/racket/pkgs/web-server-lib/web-server/default-web-root/
chmod +w htdocs
sudo chmod +w htdocs
Hopefully one of the two last lines work. If not you need to
google how to set file permissions to write on your OS.

Connect emacs to a remote ensime server

How can I connect to an ensime server on a remote host? My netbook is a bit slow for that kind of stuff. I copied the data over and use tramp to edit the files remotely. I ran bin/server to create the server and an ssh forwarding to be able to connect to it. I use ensime-connect to connect to the port on localhost. The ensime server on the remote server answers with Got connection, creating handler..., but that's about it. Ensime is in [ENSIME: wtf] mode in the emacs status line. How do I fix this?
The problem is the ensime can not find "config" of the connection (made through ensime-connect).
and then following line will throws error:
(if (and loose (ensime-file-in-directory-p file project-root))
because project-root is nil.
By setting the connection to ensime-buffer-connection, the problem can be fixed.
try adding following function to your ensime.el
and using the ensime-stackoverflow-connect to connect.
(defun ensime-stackoverflow-connect (host port)
(interactive (list
(read-from-minibuffer "Host: " ensime-default-server-host)
(read-from-minibuffer "Port: " (format "%d" ensime-default-port)
nil t)))
(let ((c (ensime-connect host port))
(config (ensime-config-load "/Users/whunmr/lab/scala/.ensime")))
(ensime-set-config c config)
(setq ensime-buffer-connection c))
)
remember to change the config path in the code: "/Users/whunmr/lab/scala/.ensime"
EDIT1:
the ".ensime" file was created by M-x ensime command, in your scala project folder.
actually, by just hardcode the config, you can ignore the file.
(defun ensime-my-connection (host port)
(interactive (list
(read-from-minibuffer "Host: " ensime-default-server-host)
(read-from-minibuffer "Port: " (format "%d" ensime-default-port)
nil t)))
(let ((c (ensime-connect host port))
(config '(:project-name "test" :project-package "com.whunmr" :sources ("./src") :compile-jars ("./" "../../apps/scala/lib/") :target "./bin" :root-dir "/Users/twer/lab/scala/")))
(ensime-set-config c config)
(setq ensime-buffer-connection c))
)

cl-pdf output error

I'm trying to use cl-pdf for some fairly basic PDF generation, but I'm getting tripped up at the examples (which is embarassing to say the least).
When I run the first example included in the package
(defun example1 (&optional (file #P"/tmp/ex1.pdf"))
(pdf:with-document ()
(pdf:with-page ()
(pdf:with-outline-level ("Example" (pdf:register-page-reference))
(let ((helvetica (pdf:get-font "Helvetica")))
(pdf:in-text-mode
(pdf:set-font helvetica 36.0)
(pdf:move-text 100 800)
(pdf:draw-text "cl-pdf: Example 1"))
(pdf:translate 230 500)
(loop repeat 150
for i = 0.67 then (* i 1.045)
do (pdf:in-text-mode
(pdf:set-font helvetica i)
(pdf:set-rgb-fill (/ (random 255) 255.0)
(/ (random 255) 255.0)
(/ (random 255) 255.0))
(pdf:move-text (* i 3) 0)
(pdf:show-text "cl-typesetting"))
(pdf:rotate 13)))))
(pdf:write-document file)))
by running (example1 #P"/home/inaimathi/Desktop/ex1.pdf") it gives me this error
#<SB-SYS:FD-STREAM for "file /home/inaimathi/Desktop/test.pdf"
{CF9D931}> is not a binary output stream.
[Condition of type SIMPLE-TYPE-ERROR]
Restarts:
0: [ABORT] Exit debugger, returning to top level.
The same thing happens when I call (example1), or when I do
(with-open-file
(test-file #P"/home/inaimathi/Desktop/ex1.pdf"
:direction :output :if-does-not-exist :create)
(example1 test-file))
Finally, if I try
(with-open-file
(test-file #P"/home/inaimathi/Desktop/ex1.pdf"
:direction :output :if-does-not-exist :create
:element-type '(unsigned-byte 8))
(example1 test-file))
I get the error
#<SB-SYS:FD-STREAM for "file /home/inaimathi/Desktop/test.pdf"
{D197C99}> is not a character output stream.
[Condition of type SIMPLE-TYPE-ERROR]
Restarts:
0: [ABORT] Exit debugger, returning to top level.
Is there a way to declare a binary character stream? How do I get simple output out of cl-pdf? I'm using SBCL straight out of the debian repos (which is 1.0.29, I think), in case it matters.
(setf pdf:*compress-streams* nil) should help. It's trying to write binary data to a character stream, and while that works on LispWorks and some other systems, it doesn't work everywhere and particularly not on SBCL.
EDIT 2: asdf-install is unmaintained and deprecated. It is best to use Quicklisp. To install Quicklisp, you'll need to download it:
$ curl -O https://beta.quicklisp.org/quicklisp.lisp
Then add cl-pdf to your lisp installation:
$ sbcl --load quicklisp.lisp
* (quicklisp-quickstart:install)
* (ql:quickload "vecto")
* (ql:add-to-init-file)
* (exit)
Now all you need to do is add
(load "~/quicklisp/setup.lisp") ; if it installed in the default location
to your .lisp file, and you can then add
(ql:quickload "cl-pdf")
EDIT: This is what I ended up doing. The solution by xach above would also work.
In the end I had to wget http://www.fractalconcept.com/download/cl-pdf-current.tgz and install that.
For the newbs (since I remember how frustrating it is for someone new to Common Lisp to hear "just do a checkout and install it"):
1.Do the checkout as above (I assume you've done this in your home directory from now on)
2.Type in tar xvzf cl-pdf-current.tgz (the point is to get a tarball of the folder. You can do this through the GUI too, it makes no difference)
3.Hop into your SBCL prompt and enter
(require 'asdf)
(require 'asdf-install)
4.If you already installed cl-pdf using (asdf-install:install 'cl-pdf), then you'll need to enter (asdf-install:uninstall 'cl-pdf)
5.Type (asdf-install:install "/home/[your home folder name]/cl-pdf-current.tgz")
I got one compilation error throughout this process, which I just selected [Accept] for. It still seems to work fine.
Hopefully the upcoming release of quicklisp will reduce the need for this sort of package hunting.