Arc Forumnew | comments | leaders | submit | markkat's commentslogin

UPDATE

I got it to work! I believe akkartik was right. Using command (-c) did the trick, which I assume ensured disconnecting from the database.

  (system "psql -U root -d root -c 'SELECT * FROM items'")
returned

  item_id | name | type | description | created | location ---------+--------+------+-------------------------------------+----------------------------+---------------------------------------------------- 1 | marble | tool | A small, translucent orange bauble. | 2022-02-23 17:59:45.480545 | 0101000020E610000012C2A38D239A5EC040683D7C99E44240 (1 row)
Thanks!!!

-----


Thanks! So far no avail, but I'll try some more!

btw I caught a misspelled 'password' in postgresql-secure-connect:

  (mac postgresql-secure-connect (user db ssl-protocol (o passowrd nil))

-----

1 point by krapp 1032 days ago | link

>btw I caught a misspelled 'password' in postgresql-secure-connect:

oops. It's fixed, thanks.

-----

1 point by markkat 1031 days ago | link

btw, would this be the correct syntax for table-exists?

  (= dbconn (postgresql-connect "root" "root" password))
  (table-exists? dbconn "items")

-----

1 point by krapp 1031 days ago | link

yes.

-----


Hey Kartik!

It's a new project. However, Hubski has been using postgres for a few years, but it's currently an amalgam of Arc and Racket. I didn't write the db code, and am trying to start fresh. The Hubski racket connection looks like:

  (define db-conn
  (virtual-connection
   (connection-pool
    (lambda () (postgresql-connect
           #:user db-user
           #:password db-pass
           #:database db-database
           #:server db-server
           )))))
with

  (define db-user     "user")
  (define db-pass     "password")
  (define db-database "hubski")
  (define db-server   "localhost")
>Can you show what command you're running to check that you "can connect to the db from the Arc command line"?

Here's my test code that works in the command line, and the response. (I named my db "root" atm and will change that and the user once I get it working. I'm running the app as root.):

  arc> (tostring (pipe-to (system "psql -U root -d root") (prn "SELECT * FROM items WHERE name = 'marble';"))                                     )
  " item_id |  name  | type |             description             |          created           |                                                           
  location                      \n---------+--------+------+-------------------------------------+--                                     ------------ 
  --------------+----------------------------------------------------\n       1 | marble | tool | A small, translucent orange bauble. | 2022-02-23 
  17:59:45.480545 | 0101000020E610000012C2A38D239A5EC040683D7C99E44240\n(1 row)\n\n"
  arc>
But when I have that same code in the app, it times out. I tried to add (prn "\\q") at the end, but same result. Works in command line but hangs up in the app.

I even tried to specify the host and port:

  (pipe-to (system "psql -U root -h 159.203.186.97 -p 5432 -d root") (prn "SELECT * FROM items WHERE name = 'marble';"))
With this in my pg_hba.conf

  host    all             root            159.203.186.97:5432      trust
And the same result; returns in command, app times out. Checked the port:

  root@Xyrth:/home/xapp# netstat -tulnp | grep 5432
  tcp        0      0 159.203.186.97:5432     0.0.0.0:*               LISTEN      124232/postgres
Thanks for the quick reply!

BTW, I am using the domain xyrth.com with a nginx reverse proxy. I just had the thought it may be my nginx configuration. It probably needs to listen explicity on 5432? Here's my current sites-enabled:

  server {
    listen 80;
    server_name xyrth.com;
    return 301 https://xyrth.com$request_uri;
  }

  server {
    	listen              443 ssl;
    	server_name         xyrth.com;
        ssl_certificate "/etc/letsencrypt/live/xyrth.com/fullchain.pem";
        ssl_certificate_key "/etc/letsencrypt/live/xyrth.com/privkey.pem";
        ssl_session_cache shared:SSL:5m;
        ssl_session_timeout  10m;

        proxy_redirect      off;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    Host $http_host;

        location / {
                proxy_buffers 16 4k;
                proxy_buffer_size 2k;
                proxy_pass http://159.203.186.97:8080;
		proxy_set_header Host xyrth.com;
        }

        location ~* \.(png|jpg|tif|ico|ttf|woff|svg|eot|otf|mp3|ogg|wav)$ {
        root /home/xapp/static;
        expires max;
        }

        location ~ ^/(xyrth.css) {
                root /home/xapp/static;
                expires max;
        }

  }

-----

1 point by markkat 1032 days ago | link

Killing me. I don't think it's nginx..

Maybe it isn't disconnecting?

  (tostring (system "psql -V"))
Returned

  psql (PostgreSQL) 12.9 (Ubuntu 12.9-0ubuntu0.20.04.1)
just fine from the app.

-----

2 points by markkat 4427 days ago | link | parent | on: Libraries suck

If you don't identify as a programmer, if that isn't your core strength, if you just program now and then because it's expedient, then treating libraries as services may make more sense. If a major issue pops up you'll need to find more expert help, but you knew that already.

I did. :)

Even so, I think it's also worth considering that libraries also represent learning opportunities for some (like myself). For whatever reason, perhaps because it isn't my core strength, the only approach to programming that I have found to work for me is to continually try to do something. I seem only to be able to truly absorb the finer points when they are encountered in the context of a whole.

For a long time this kept me from programming altogether.

-----

4 points by markkat 4736 days ago | link | parent | on: Best way to implement a HN themed site?

Hi darjeeling. I run http://hubski.com Glad you like it! Unfortunately, I don't think there are any quick answers to your questions. Most of this requires writing new code. I'll take a shot at them, to get you started, however:

how difficult would it be to add open-id, facebook, twitter, g+ integration?

That depends on how integrated you want to get. It's fairly trivial to be able to add a 'like' or '+1' button, but if you want deeper integration, you'd have to be specific about what you want to do. I haven't tried open-id. I'm sure it's doable.

how does hubski distinguish text submissions vs videos and so on? How do I group/categorize all of them?

For videos, it is a matter of identifying the url as a video url, etc. For example with findsubseq, you can pick out if contains "youtube" "youtu.be", etc. Text submissions are those that lack a url, and don't have an empty text field, etc. No quick fix here. news.arc wasn't made to sort them that way, I had to do that.

how do I add tags to submissions or allow admins to add tags?

There are a number of ways you might go about that. I added the tag as an additional story key/value pair. Depending on your tagging structure, you might want to make each tag it's own template, containing the ids of stories carrying that tag.

how do i decrease the karma required to downvote?

I think there is downvote-threshold* in news.arc, -just change the value. I don't use karma or downvotes with Hubski. So I don't have that code anymore. :)

how do i mimic HN's job page, ie: no name of the poster and no comment field- just link and text. How to group all such posts?

Shouldn't be too difficult. Each story could have a 'job' key with a value of nil or t. If it is t, then opt not to show the comment tree, name, etc.

From the range of your questions, it seems that you haven't messed with the code too much yet. If you really want to use news.arc, just get in there and start tweaking. I was totally green to Arc when I started. Good luck!

-----

1 point by darjeeling 4736 days ago | link

Hi Markkat, thank you very much for your detailed reply. If you don't mind, I'd like to ask more questions.

- If I want to start hacking into the news code, is news.arc the only file I start with? I would also like to change the css, make email field compulsory, send email confirmation and so on. If you could show me some direction, it would be very helpful.

- by integration with other services, I mean allowing likes, +1, commenting, log-in etc. I think I will have to look into the code to start understanding this more, so it is related to the above point.

- about identifying video URLs- how would you recommend expanding something like, say a bit.ly link?

- Yes, I haven't done anything with the code yet because it looks a little unfamiliar at this point. But I'd love to.

Thank you very much for your help.

-----

2 points by markkat 4739 days ago | link | parent | on: Best way to implement a HN themed site?

Getting a HN clone up and running isn't too bad, and the version of news.arc available is very stable as is. Also, the folk in this forum are very friendly and willing to answer questions. I don't think that getting your HN clone up and running would be much more difficult than any other forum.

Tip: if you are looking to customize news.arc, I would start by working it out of the table formatting and into CSS. If not, it's a pretty rigid beast. It's worth the effort, and would also be a good way to get familiar with the code.

-----

2 points by markkat 4739 days ago | link | parent | on: Best way to implement a HN themed site?

No plans to change either! :)

-----

2 points by markkat 4790 days ago | link | parent | on: How to Pick a Language

You want a 100 year language and you’re willing to wait that long.

Oh, come on now. :)

-----

2 points by markkat 4790 days ago | link | parent | on: Arc noob

Welcome! I started with Arc3.1 but have been adding anarki features piecemeal.

-----

1 point by markkat 4887 days ago | link | parent | on: Sorting a list by most common elements.

Oh, and by the way, it did make sense of the zoo:

  (sort-by-c­ommonest '(dog­ dog cat fox fox dog fish)­)
  (dog dog dog fox fox cat fish)
I went with the first since it serves my purpose, but actually, it might be more future-looking to use the second.

Thanks again!

-----

More