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

Topics - hilti

#1
Anything else we might add? / Lisp badge
January 11, 2019, 02:15:01 AM
Happy New Year everyone! This is a nice project:



http://www.technoblogy.com/show?2AEE">//http://www.technoblogy.com/show?2AEE
#2
That's an interesting approach.

http://ceramic.github.io">//http://ceramic.github.io



Discussion on HackerNews over here

https://news.ycombinator.com/item?id=9877314">//https://news.ycombinator.com/item?id=9877314
#3
Hi!



Maybe this help's, if someone needs to send data in CSV format to a browser.

In this example a Dragonfly Route "http://www.mysite.com/csvexport">www.mysite.com/csvexport" is called, a SQLite dump is produced on the fly and send out to the browser.



I needed this quick workaround in an Admin-Interface.



Cheers

Marc





(new Resource 'Resource.Csvexport)
(context 'Resource.Csvexport)

(define (Resource.Csvexport:Resource.Csvexport)
(catch-all)
)

(define (catch-all action)
(Response:header "Content-Description" "File Transfer")
(Response:header "Content-Type" "text/csv")
(Response:header "Content-Disposition" "attachment; filename=out.csv")
(Response:header "Pragma" "public")
(Response:header "Expires" "0")

(change-dir (append DF_SELF_DIR))
(change-dir "..")
(change-dir "databases")

;; Now we're running sqlite3 binary directly on the server ...
(setq cmd-dump {sqlite3 -header -csv -separator ';' db.sqlite "select * from data;" > out.csv})
(exec cmd-dump)

;; Sending it out ...
(print (read-file "out.csv"))
)

(context MAIN)
#4
I don't get it ... since two hours I'm trying to train some website data, but don't get the expected results.

(bayes-query) returns 0.5 or 1



I'm using the complex pattern in (parse) to split up german texts, too.



Here's my code:


(setq textdata "Now think about your brain. It's a long running program running on very complex and error prone hardware. How does your brain keep itself sane over time? The answer may be found in something we spend a third of our lives doing. Sleep.")

(setq text (parse (lower-case textdata) "[^a-z0-9äöüß]+" 0))
(bayes-train text 'DICT)
(bayes-query (parse (lower-case "dsd skjsd ksdjkds sdkj") "[^a-z0-9äöüß]+" 0) 'DICT)


And the result


"Now think about your brain. It226128153s a long running program running on very complex and error prone hardware. How does your brain keep itself sane over time? The answer may be found in something we spend a third of our lives doing. Sleep."
("now" "think" "about" "your" "brain" "it" "s" "a" "long" "running" "program" "running"
 "on" "very" "complex" "and" "error" "prone" "hardware" "how" "does" "your" "brain"
 "keep" "itself" "sane" "over" "time" "the" "answer" "may" "be" "found" "in" "something"
 "we" "spend" "a" "third" "of" "our" "lives" "doing" "sleep" "")
(45)
(0.5)


I'm expecting 0, because this phrase doesn't exist in my training data.



Am I missing some switch?
#5
Hi!



Does anyone have experience in parsing large OSM (Openstreetmap) files? I'm trying to parse them with (xml-parse) but I get an error from newLISP telling me that there's not enough memory for (read-file)



The file is 32GB (gigabytes!).



Here's the error message:



newlisp -m 4096 -s 10000 parse.lsp
newlisp(18433) malloc: *** mmap(size=4258476032) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

ERR: not enough memory in function read-file


Thanks for any suggestion.

Marc
#6
newLISP in the real world / newLISP and big data?
May 08, 2013, 04:49:15 AM
Hi!



I've just come across this blog post and wondered if the Gist shown there is newLISP? Because the use of (nth) looks pretty familiar to me.



http://blog.bugsense.com/post/49924755479/bigdata-in-motion-building-a-real-time-android">//http://blog.bugsense.com/post/49924755479/bigdata-in-motion-building-a-real-time-android



What Do You think?



(load "stdlib.lql")
(load "dblib.lql")
 
(timespace "day")
 
(define string-row *stream*)
 
(let ((row (reverse
            (string-split (str string-row) ":"))))
  (if (= (length row) 4)
    (begin
      (let ((os-ver (nth row 0))
            (phone-model (nth row 1))
            (error-class (nth row 2)))
      (incdb "sessions" 1)
      (incdb (session-by "osver" os-ver) 1)
      (incdb (session-by "device" phone-model) 1)
      (incdb (session-by "error" error-class) 1)
      (incdb (session-by-crash "os_ver_class" os-ver error-class) 1)
      (incdb (session-by-crash "device_class" phone-model error-class) 1)
 
      (push! (unique "os_ver") os-ver)
      (push! (unique "device") phone-model)
      (push! (unique "error_class") error-class)))
      #f))




Update:
QuoteA full blown custom LISP language written in C to implement queries, which is many times faster that having a VM (with a garbage collector) online all the time

http://highscalability.com/blog/2012/11/26/bigdata-using-erlang-c-and-lisp-to-fight-the-tsunami-of-mobi.html">//http://highscalability.com/blog/2012/11/26/bigdata-using-erlang-c-and-lisp-to-fight-the-tsunami-of-mobi.html
#7
Hi newLISPers



here comes a quick hack for the weekend. I needed a way to authenticate against the Dropbox API for one of my projects. Unfortunately the API uses oAuth and needs "https" so I have to use the CURL library instead of newLISP build-in (get-url).



At first You need to create Your own Dropbox API keys. That's very easy.



  • Login to Dropbox

    Open this URL https://www.dropbox.com/developers/apps">//https://www.dropbox.com/developers/apps

    Click "Create an app" and follow the guide

  • [/list]

    Now You need this little script to get the authentication tokens.



    #!/usr/bin/env newlisp

    ;; BEGIN SETTINGS

    ;; Set Your own Dropbox API keys
    ;; You can create these keys here: https://www.dropbox.com/developers/apps
    (set 'oauth-consumer-key "this-is-your-app-key") ;; this is the App key
    (set 'oauth-signature "this-is-so-secret") ;; this is the App secret
    (set 'curl "curl") ;; set path to curl executable

    ;; END SETTINGS


    (set 'post-request (append {'Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="} oauth-consumer-key {", oauth_signature="} oauth-signature {&"'}))
    (set 'post-target "https://api.dropbox.com/1/oauth/request_token")

    ;; GET TOKEN SECRET
    (set 'curlpost (append curl " --silent --header " post-request " " post-target))
    (set 'response (first (exec curlpost)))
    (set 'oauth_token_secret  (first (parse response "&")))
    (set 'the-secret (last (parse oauth_token_secret "=")))
    (set 'oauth_token (last (parse response "&")))

    ;; AUTH BY USER
    (set 'authurl "https://www.dropbox.com/1/oauth/authorize?")
    (set 'callbackurl "&oauth_callback=http://localhost/auth_complete")
    (set 'curlauth (append curl " --silent " authurl oauth_token callbackurl))
    (exec curlauth)
    (println "Opening browser for authorization ... please follow further steps in Your browser.")
    (set 'launchcmd (append "open " authurl oauth_token callbackurl))
    (exec launchcmd)

    (println "When authorization on Dropbox.com was successful press the 'a' key: ")
    (while (!= (set 'key (read-key)) 97)
    (println "When authorization on Dropbox.com was successful press the 'a' key: ")
    )

    ;; GET ACCESS TOKEN
    (set 'access-request (append {'Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="4n1wccbr1cyx3la", } oauth_token {", oauth_signature="xppxoa9rpqoviwc&} the-secret {"'}))

    (set 'access-target "https://api.dropbox.com/1/oauth/access_token")
    (set 'curlaccess (append curl " --silent --header " access-request " " access-target))
    (set 'access_response (first (exec curlaccess)))
    (println "Access response (JSON): " access_response)

    (set 'access_token (parse access_response "&"))
    (println "Access token: " access_token)
    (set 'oauth_token (last (parse (nth 1 access_token) "=")))
    (println "OAuth token: " oauth_token)
    (write-file "oauth-token.txt" (string oauth_token))

    (set 'access_token_secret (last (parse (first (parse access_response "&")) "=")))
    (println "Access token secret: " access_token_secret)
    (write-file "token.txt" (string access_token_secret))
    (exit)


    ---- LAUNCH the script ---- :-)



    Beware: I've just tested it on OSX.



    When You run this script in OSX terminal it'll automatically open Your default browser and asks if newLISP get's access to Your Dropbox. Grant access now.



    Now go back to terminal and press the "a" key to go on with the script. We need to pause, because we've to wait for user interaction (grant access) in the browser.



    Finally You should see the Dropbox API response with OAuth Token and Access Token Secret.



    ----- Use the Dropbox API ----- :-) :-)



    With these tokens/keys we can use the Dropbox API. Here's a little snippet to get the account information.



    #!/usr/bin/env newlisp

    ;; BEGIN SETTINGS

    ;; Set Your own Dropbox API keys
    ;; You can create these keys here: https://www.dropbox.com/developers/apps
    (set 'oauth-consumer-key "this-is-your-app-key") ;; this is the App key
    (set 'oauth-signature "this-is-so-secret") ;; this is the App secret
    (set 'curl "curl") ;; set path to curl executable

    ;; END SETTINGS

    (set 'access_token_secret (read-file "token.txt"))
    (set 'oauth_token (read-file "oauth-token.txt"))
    (set 'header (append {'Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="} oauth-consumer-key {", oauth_token="} oauth_token {", oauth_signature="} oauth-signature {&} access_token_secret {"'}))

    (define (json2list response)
    (json-parse (first response))
    )

    (define (accountinfo)
    (set 'endpoint "https://api.dropbox.com/1/account/info")
    (set 'url (append curl " --silent --header " header " " endpoint))
    (set 'response (exec url))
    (json2list response)
    )

    (println (accountinfo))
    (exit)


    Hopefully everything works and You have some fun with the Dropbox API. When I find some time, maybe I'll write a complete Dropbox module.



    Cheers

    Marc
#8
newLISP in the real world / Using MaxMind's GeoIP.js
February 12, 2013, 06:51:59 AM
This one might become useful in your web projects. It calls an external javascript file on MaxMinds geolocation servers and returns your browsers location.



I'm using it in a Dragonfly project to detect the users location and serving current weather condition.



(set 'jsdata (get-url "http://j.maxmind.com/app/geoip.js"))
(set 'location (find-all [text]'(.*)'[/text] jsdata))
(print location)


And something cool - it's free if you put a link on your website :-)



http://dev.maxmind.com/geoip/javascript">http://dev.maxmind.com/geoip/javascript

Free use of the service is allowed with attribution in the following form:



This website uses <a href="http://www.maxmind.com/en/javascript%22%3EGeoIP">http://www.maxmind.com/en/javascript">GeoIP Javascript from MaxMind</a>
#9
Whither newLISP? / How to get newLISP popular?
January 08, 2013, 08:04:01 AM
Over three years now I'm using newLISP for several projects, most of them were web projects. During these years I've experimented with other LISPs like clisp, clojure and so on, but always coming back to newLISP because it's more fun and easier to solve my computing tasks.



So how will get newLISP more popular - what do we have to do in 2013?



I've written down some ideas I'd like to share with You:



1. Make newlisp.org more sexy - I'm working on some styles Lutz can easy use with his wiki

2. Write an ebook for children about "Programming with newLISP on the Raspberry Pi"

=> The internet of things is right around the corner and I think children like to influence their world via a computer. With newLISP it's easy to access the GPIO Pins from the Raspberry Pi to read out sensors or do some home automation.

3. Developing a portable, embedded social network device. Something like "Facebook to Go" using newLISPs networking functions, because I think the discussions about personal data and privacy will become more active.



What are you thinking?



Cheers

Marc
#10
newLISP in the real world / newLISP on Rockets
October 23, 2012, 12:39:01 PM
Hi!



Does anyone know who's behind "Dragonfly reloaded" ;)

http://newlisponrockets.com/">//http://newlisponrockets.com/



bye

Marc
#11
newLISP in the real world / Socket webserver
September 10, 2012, 10:15:09 PM
Hi!



I don't understand why I can't access an established socket connection via my browser or telnet? I'm trying to build a simple socket-based webserver.



server.lsp
#!/usr/bin/env newlisp

;; SET IP and PORT
(set 'ip "127.0.0.2")
(set 'port 8080)

;; BUILD UP SOCKET
(set 'connection (net-listen port ip "multi"))
(if connection
(println "LispIO webserver started on " ip ":" port)
    (println (net-error))
)

;; ENTER LOOP
(while (not (net-error))
(set 'msg (net-receive-from connection 1024))
;(println "->" msg)
(set 'response [text]
"HTTP/1.0 200 OKrn"
"Server: LispIOrn"
"Content-Type: text/htmlrn"
"rn"
[/text]
)
(net-send-to (nth 1 msg) (nth 2 msg) response connection)
(println "Hello World")
)

(exit)




client.lsp

#!/usr/bin/newlisp

(set 'socket (net-listen 8081 "" "multi"))
(if (not socket) (println (net-error)))
(while (not (net-error))
(print "Enter something -> ")
(net-send-to "localhost" 8080 (read-line) socket)
(net-receive socket buff 255)
(println "=> " buff)
)


Starting up server.lsp and client.lsp in two different terminal windows. Entering some text in the client window is immediately pushed to the server, which response with:



Enter something -> hello
=>
"HTTP/1.0 200 OKrn"
"Server: LispIOrn"
"Content-Type: text/htmlrn"
"rn"


But why can I not access http://127.0.0.2:8080">http://127.0.0.2:8080 in my browser?



Thanks for help.

-Hilti
#12
Hi newLISPers!



Today my first bootstrapped website project launched. DESBUY http://www.desbuy.com">//http://www.desbuy.com. It's a platform for finding local design furniture. Currently is backed by eBay, local dealers coming soon.



It's entirely based on newLISP Code and runs on Amazon EC2 (micro instance). Geolocation is done by passing (env "REMOTE_ADDR") to a webservice.

Dynamic translation is provided by a list and lookup - no database required there ;-)



More newLISP projects are on the way.



Cheers

Hilti
#13
newLISP in the real world / Amazon.lsp module
August 27, 2012, 11:40:12 AM
Hi!



Does anyone successfully used the amazon.lsp library? I get an error when trying to list all my S3 buckets with


(amazon:list-all-buckets 1000)

The error  code is



ERR: server code 400: HTTP/1.1 400 Bad Request
<Error><Code>InvalidArgument</Code><Message>AWS authorization header is invalid.  Expected AwsAccessKeyId:signature</Message>


Any help is appreciated.



- Marc
#14
Hi Guys!



I'm providing my script to install newLISP on an Amazon EC2 instance. It installs all depending libraries and automatically installs newLISP. Tested on EC2 micro instance with Ubuntu AMI.



Cheers

Hilti



#!/bin/bash
# Simple bash script for installing newLISP on Amazon EC2, Ubuntu 12.04 AMI
# Author: Marc Hildmann, July 2012
#

read -p "Install necessary default building libraries (y/n)?" CONT
if [ "$CONT" == "y" ]; then
  sudo apt-get install libffi-dev build-essential libreadline-dev
else
  echo "No libraries were installed.";
fi

read -p "Now changing to /tmp and download newLISP (y/n)?" CONT
if [ "$CONT" == "y" ]; then
  cd /tmp
wget http://www.newlisp.org/downloads/newlisp-10.4.3.tgz
tar xvfz newlisp-10.4.3.tgz
cd newlisp-10.4.3
else
  echo "Nothing happened.";
fi

read -p "Build and install newLISP (y/n)?" CONT

if [ "$CONT" == "y" ]; then
make
sudo make install
echo "### Installation finished ###"
else
  echo "Nothing happened.";
fi
#15
Hi Guys!



I've just pushed two new libraries to my Github.



GeoTools

Using the Google Maps API You are able to get an address by given latitude and longitude (vice versa) and calculate distance between two points.

https://github.com/marchildmann/newlisp-geotools">//https://github.com/marchildmann/newlisp-geotools



GooglePlaces

This is the world's first newLISP wrapper to the Google Places API ;) Have fun.

https://github.com/marchildmann/newlisp-googleplaces">//https://github.com/marchildmann/newlisp-googleplaces



More to come soon.



Cheers

Hilti
#16
Anything else we might add? / Scheme on the iPad
April 05, 2012, 08:18:42 AM
I'm wondering if this way a newLISP iPad App is possible? I always thought, that scripting languages and interpreter are not allowed in an app.



http://slidetocode.com/2012/04/05/lisping-released/">//http://slidetocode.com/2012/04/05/lisping-released/



- Hilti
#17
Sooner or later they'll all come to newLISP :)



http://shinkirou.org/blog/2010/06/s-expressions-the-fat-free-alternative-to-json/">//http://shinkirou.org/blog/2010/06/s-expressions-the-fat-free-alternative-to-json/
#18
Hi Guys!



Is it possible to setup a multi-threaded webserver with net-eval? I've studied the "mapreduce example" where a worker node splits up a task to several worker nodes by using net-eval.



But I can't figure out the starting point in splitting up http requests.



Your help is needed, please.



All the best

Hilti
#19
Hi Guys!



I'm currently working part-time on a visual search project written in newLISP. Now it's time to scale some images.



Does anyone have experiences in accessing GDLib or ImageMagick?

A full example including picture upload, scaling and saving to disk would be great. :-)



Thanks so much!

Hilti
#20
Hi!



I'm stucked in generating auto increment keys for a hash tree. Here's my approach:



(new Tree 'products)

(define (highest-key tree)
(if-not (empty? (tree))
(begin
(println "Tree is not empty.")
(string (inc (integer (first (last (sort (tree)) <)))))
)
(begin
(println "Tree is empty.")
(string (integer 1))
)
)
)

(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")
(products (highest-key products) "hello")

(products)


The thing is: hash keys have to be strings, right? And that's why I get in troubles on sorting this list, which (products) returns.



(("1" "hello") ("10" "hello") ("2" "hello") ("3" "hello") ("4" "hello") ("5" "hello")
 ("6" "hello")
 ("7" "hello")
 ("8" "hello")
 ("9" "hello"))


Is there another approach for hash keys? What are You guys using?



Cheers

Hilti