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 - csfreebird

#1
(sys-info 7)



:)



nobody talking here, so quite. :(
#2
I want to output current process id, save it as a file, the file content is all arguments of this process. e.g.



I have a test.lsp file, when running it with -a=b -c=d

I want to save a process id file: 16754,

cat 16754, I will see

-a=b -c=d
#3
recently, I observed my newlisp app reports timeout error when post message to rest server. We have a few different rest servers. The status of servers are fine when getting timeout error in newlisp. If I stop the newlisp process and restart it, all get back to work fine.



My friend who is using newlisp in her projects told me she ran into same trouble before, she used curl command to bypass this.



So I thinks it is a bug in newlisp post-url function.

To reproduce this, I suggest setting up a rest server and let newlisp code keep posting over one or more days.



For now, I have to call (exit) to quit the process when timeout occurs and re-launch it using jenkins or other monitor script.
#4
Thanks, ralph.

After replace until with if, it works.

(define (child-process)
  (setq ppid (sys-info 6)) ; get parent pid
  (setq cur-pid (sys-info 7))
  (while true
    (if (receive ppid msg)
(begin
 ;; get new message from queue
 (append-file (string cur-pid ".log") (string msg "n"))
 )
(begin
 ;; get nothing from queue, sleep 1 second
 (sleep 1000)
 )
)
    )
  )
#5
Hi,

  I am using cilk api, one parent process sends one message to 5 child processes. But each child process receives the message many times. Why?

Following is my code:

(load "args.lsp")
(parse-args)

(setq process-number (int (ArgsTree "--process-number")))

(define (child-process)
  (setq ppid (sys-info 6)) ; get parent pid
  (setq cur-pid (sys-info 7))
  (while true
    (until (receive ppid msg)
      (append-file (string cur-pid ".log") (string msg "n"))
      (sleep 1000)
      )
    )
  )

; parent starts child processes
(dotimes (i process-number)
  (spawn 'result (child-process) true)
  )

;; parent send one msg to each child process
(setf child-process-list (sync))
(println "child-process-list: " child-process-list)
(dolist (cpid child-process-list)
  (println "child process: " cpid)
  (send cpid "test msg")
  )

;; quit in 10 seconds
(sleep 10000)
(abort)
(exit)


to spawn 5 child processes, use this command

./run-task.lsp --process-number=5



Then in five child process log files, I have these
Quote
nil

test msg

test msg

test msg

test msg

test msg

test msg

test msg

test msg

test msg


My questions are:

1. why get nil message

2. why get one message repeatedly

3. why receive function needs parent process id(sender id) instead of child process id(receiver id)
#6
newLISP in the real world / logistic regression
July 05, 2016, 06:50:30 AM
I am in one project that using logistic regression to predict phone number from fraud. The engineers in my team are using python(maybe c++ later) library for logistic regression to do machine learning.

I wonder how to implement this in newlisp, any basic functions from newlisp can be used in this case.

I am new to machine learning, but want to have a try with newlisp myself.
#7
Thanks. It's my bad. I use wrong variable files, but should be file-list.

There is no bug in sort function. My bug.
#8
newLISP in the real world / sort in v10.7.0
June 29, 2016, 02:26:25 AM
1 description



I want to find oldest files when free space is not enough and delete them until free space is enough. Thus I find all files under one folder tree recursively and sort them by modified time.



2 code



2.1 find all files and save them into one list called file-list



(define (add-file-list f)

  (push f file-list -1)

  )



(define (find-all-files clean-folder)

  (setq file-list '())

  (recursive-access-dir clean-folder add-file-list)

  file-list

  )



;; @arg dir-path must be ended with /

(define (recursive-access-dir dir-path file-op)

  (dolist (nde (directory dir-path {^[^.]}))

    (if (directory? (append dir-path nde))

        (recursive-access-dir (append dir-path nde "/") file-op)

        (file-op (append dir-path nde)))))





2.2 sort file-list using compare function



(define (compare-time file1 file2)

  (letn (t1 (int ((file-info file1) 6))

            t2 (int ((file-info file2) 6))

            )

    (<= t1 t2)

    )

  )



  (sort files compare-time)

3 result



The following code print all files' modified time



(setq files (find-all-files clean-folder))

(dolist (f files)

   (println "files: " f ", time: " ((file-info f) 6))

The second file usa.sh is newer than jstc.sh, but it's in fron of jstc.sh. I check my code a few times, guess this is a bug of sort function.



files: /home/dean/sshclient/nj/delotto.sh, time: 1459176252

files: /home/dean/sshclient/nj/usa.sh, time: 1459176253

files: /home/dean/sshclient/nj/jstc.sh, time: 1459176252

files: /home/dean/sshclient/nj/test.sh, time: 1459176243

files: /home/dean/sshclient/nj/tunnel_gitlab_nanjing.sh, time: 1459176252

files: /home/dean/sshclient/nj/mongodb.sh~, time: 1459176252

files: /home/dean/sshclient/nj/root@/train.html~, time: 1461292073

files: /home/dean/sshclient/nj/root@/theme-readtheorg-local.setup, time: 1461292073

files: /home/dean/sshclient/nj/root@/package.sh, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/in/rec1.png, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/in/rec1.dot~, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/in/path1.dot, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/in/path1.dot~, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/in/path1.png, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/in/rec1.dot, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/newbie/colla/u1.dot, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/newbie/colla/u2.png, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/newbie/colla/u1.png, time: 1461292073

files: /home/dean/sshclient/nj/root@/imgs/newbie/colla/u2.dot, time: 1461292073

files: /home/dean/sshclient/nj/root@/js/bootstrap.min.js, time: 1461292073

files: /home/dean/sshclient/nj/root@/js/jquery.min.js, time: 1461292073

files: /home/dean/sshclient/nj/root@/package.sh~, time: 1461292073

files: /home/dean/sshclient/nj/root@/train.html, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/in_graph.dot, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/in_graph.dot~, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/ddl-to-dot.lsp~, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/ddl.sql, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/convert.lsp, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/graph.dot~, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/graph.png, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/in_graph.png, time: 1461292073

files: /home/dean/sshclient/nj/root@/graph-schema/convert.lsp~, time: 1461292073

files: /home/dean/sshclient/nj/root@/styles/lib/js/jquery.stickytableheaders.min.js, time: 1461292073

files: /home/dean/sshclient/nj/root@/styles/lib/js/stickytableheaders-license.txt, time: 1461292073

Created: 2016-06-29 Wed 17:23
#9
newLISP in the real world / url encode support
April 09, 2015, 09:26:28 PM
I want to use get-url to call one REST API, but the URL path of this REST API contains some Chiness words, like this:
Quote
http://localhost/wind_tunnel/clusters/%E8%B7%9F%E8%B8%AA%E7%B3%BB%E7%BB%9F/hosts">http://localhost/wind_tunnel/clusters/跟踪系统/hosts


when using browser, this url will be encoded by browser automatically:
Quote
http://localhost/wind_tunnel/clusters/%E8%B7%9F%E8%B8%AA%E7%B3%BB%E7%BB%9F/hosts">http://localhost/wind_tunnel/clusters/% ... B%9F/hosts">http://localhost/wind_tunnel/clusters/%E8%B7%9F%E8%B8%AA%E7%B3%BB%E7%BB%9F/hosts


I didn't find url encode/decode functions in newlisp manual, does anybody implement this before?
#10
In newlisp, I don't know use wich method or module to implement this?

Need your help.
#11
Hi, I got some DAG code from rickyboy. In these code, I can get a node object from dag(I  renamed it to Graph now) object, Graph and Node are FOOP object classes.

Then I try to modify this node, but find it's just a copy.

;; @syntax (Graph:get-node node-name)
;; @description
;; <p>If you want to get a Node out of the Graph (e.g. in order to extract
;; its properties), then use the following function to get it by name.</p>
;; @example
;; (println (:get-node my-dag "G")) ;;=> (Node "G" sad)
;; (println (:get-node my-dag "Does not exist")) ;;=> nil
(define (Graph:get-node node-name)
  (and (find (list 'Node node-name '*)
             (:nodes (self))
             match)
       $0))


My calling code is:

(setq product-node (:get-node my-dag "result"))
(push "2014-12-12 10:10" product-node -1)
(println product-node)
(println (:get-node my-dag "result"))


The output is:

(Node "result" "2014-12-12 10:10")

(Node "result")



I have no idea about returning a reference of Node object from Graph method.
#12
Thank yuu, johu. Your example is simple enough to understand.

Thank you rickyboy, you are so fast, I will learn your code carefully.
#13
newLISP in the real world / Can I create a DAG in newlisp
December 08, 2014, 09:59:20 PM
Hi, My task is to create a directed acyclic graph, I want to implement it using list.

Can any one make an example for me?

My simple case looks like:





A and B are start nodes. Each node has properities, each edge has properties too.

E, G and F are end nodes.



I also need a way to find all dependencies of one node.e.g.

If input is D, its dependencies are A, B and C.
#14
The existing C function is:

bson_t * bson_new_from_json (const uint8_t* data, ssize_t len, bson_error_t  *error);


I import it in newlisp:

(import bson-lib "bson_new_from_json" "void*" "void*" "unsigned int" "void*")
;; I also tried to use char* instead
;; (import bson-lib "bson_new_from_json" "void*" "char*" "unsigned int" "void*")

;; @syntax (mongo:bson-new-from-json json-str)
;; @return the pointer of bson_t
(define (bson-new-from-json json-str)
  (bson_new_from_json json-str (length json-str) 0)
  )


Now when I try to use bson_new_from_json function, always get 0 value returned.

(load "mongo.lsp")
(set 'cmd-str "{stats:true}")
"{stats:true}"
> (mongo:bson-new-from-json cmd-str)
0
#15
Thanks. I know to pass 0 as NULL argument now and how to use variadic function.

I still have some questions when developing mongodb.lsp based on mongodb c driver.

Will ask them in other threads.