Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 05 20:29
    Chemaclass closed #268
  • May 05 20:29
    Chemaclass commented #268
  • May 05 20:28
    Chemaclass labeled #271
  • May 05 20:28
    Chemaclass assigned #271
  • May 05 20:25
    Chemaclass review_requested #253
  • May 05 20:24
    Chemaclass synchronize #253
  • May 05 20:24

    Chemaclass on implementing-gacela-framework

    Handle errors in PhelConfig whe… (compare)

  • May 05 19:57
    mabasic commented #246
  • May 05 19:56
    mabasic opened #271
  • May 05 19:53
    mabasic synchronize #246
  • May 05 19:40
    jenshaase commented #270
  • May 05 19:33
    Chemaclass commented #270
  • May 05 19:32

    Chemaclass on documentation-data-structures

    (compare)

  • May 05 19:32

    Chemaclass on master

    Update documentation for data s… Minor improvements for the data… Merge pull request #270 from ph… (compare)

  • May 05 19:32
    Chemaclass closed #270
  • May 05 19:14
    jenshaase synchronize #270
  • May 05 19:14

    jenshaase on documentation-data-structures

    Minor improvements for the data… (compare)

  • May 05 17:37
    mabasic commented #246
  • May 05 17:35
    mabasic synchronize #246
  • May 05 17:26
    mabasic synchronize #246
Mario Bašić
@mabasic
In Laravel collections I would do foreach($itemSubset as $items->chunk(4)) and then inside that I would do another foreach $itemSubset to get the items in that subset
Jens Haase
@jenshaase
@mabasic partition is want you want.

partition

(partition n xs)

Partition an indexed data structure into tuples of size n. Returns a new array.

9 replies
Mario Bašić
@mabasic
Is there an equivalent to in_array in phel?
Mario Bašić
@mabasic
Also, how do I do double checks in a if statement: eg. if(something === x and something2 === y)?
I am looking for in_array to improve this code:
(defn is-reading [request]
  (let [method (get request :method)]
    (cond
      (= method "HEAD") true
      (= method "GET") true
      (= method "OPTIONS") true
      true false)))
Mario Bašić
@mabasic
Also, how do I do if statement with or eg. if(something === x or something2 === y)
Brain stuck at the moment xD
This is what I could think of atm:
(defn handle [request]
  (if (is-reading request)
    request
    (if (tokens-match request)
      request
      @{:status 302
        :headers @{"Location" "/csrf"}
        :body "CSRF token mismatch."})))
Jens Haase
@jenshaase
(and (= something x) (= something2 y)) (or (= something x) (= something2 y))
there is not in_arraycurrently but you can use find and check if it is not nil
Mario Bašić
@mabasic
Don't know if this is any better :
(defn is-reading [request]
  (let [result
        (find (fn [method]
                (= (get request :method) method)
                ["HEAD" "GET" "OPTIONS"]))]
    (nil? result)))
This looks good:
(defn handle [request]
  (if
    (or
     (is-reading request)
     (tokens-match request))
    request
    @{:status 302
      :headers @{"Location" "/csrf"}
      :body "CSRF token mismatch."}))
Correction:
(defn is-reading [request]
  (let [result
        (find
         (fn [method]
           (= (get request :method) method)
           ["HEAD" "GET" "OPTIONS"]))]
    (not (nil? result))))
Mario Bašić
@mabasic
Thank you Jens for the help. My brain was broken this morning :) I've manage to implement a very basic router, csrf protection and global middleware
Mario Bašić
@mabasic
Next steps: sending emails with aws ses, using a database (probably sqlite or some experimental php database I've read about recently)
Mario Bašić
@mabasic
Is there a way to check if a key exists in a table?
Mario Bašić
@mabasic
I found keys, and then i do find, but is there a simpler option?
Jens Haase
@jenshaase
Currently there isn't. But that would be a helpful function. Can you add a issue, then I can implement such a function.
Mario Bašić
@mabasic
Sure thing.
Mario Bašić
@mabasic
When destructuring a table, can I get the key and value? In the docs there are only examples of getting the value.
Found it in for using :pairs
Mario Bašić
@mabasic
Is there a way to dynamically create a table?
with a for loop maybe
Jens Haase
@jenshaase
(put table key value) (e.g. (put @{:a 1 :b 2} :c 3))
Mario Bašić
@mabasic
Thank you. I had to use foreach loop with put, because for always returns an array.
Mario Bašić
@mabasic
@jenshaase :parsed-body in a request is not working for me.
I know that we have a test for this, and that it passed
Mario Bašić
@mabasic
It's not a Phel issue after all. Even PHP does not see anything with $_POST
Mario Bašić
@mabasic
Found the data here (def data (json/decode (php/file_get_contents "php://input"))) xD since I was using application/json content-data xD
Should we place that in the request somewhere?
When the content-data is set to application/json should we place the above as :parsed-body instead of using $_POST?
Mario Bašić
@mabasic
There is a issue with my phel-json library. It converts strings to keywords for table keys. I should probably add an option to have it return either keywords or strings. This caused me a couple of minutes to work out.
Mario Bašić
@mabasic
Is there a strlen in Phel? For some reason I can't use count on a string.
Jens Haase
@jenshaase:matrix.org
[m]
php/strlen
Mario Bašić
@mabasic
I expected to find a (strlen x) function. But php/strlen does the job.
Mario Bašić
@mabasic
Is there a Phel function for explode ? It would seem that most of php functions for strings and arrays and to be used with (php/.. I was also looking for str_replace.
Jens Haase
@jenshaase
There are so many Php function. I will not wrap every function in phel.
Jose Maria Valera Reales
@Chemaclass
I would also say that. I think it's ok to use the native PHP functions for most of the common things such as strlen or similar.
But well, in case anyone find/does some interesting functions for phel that might get an additional advantage of having them in phel and not in native-php, then feel free and welcome to create a PR with it :)
Mario Bašić
@mabasic
It kind of makes sense. Making a 1 to 1 conversion is a big job, and the benefits are not really there, because (php/strlen "") instead of (strlen "") is trivial.
Mario Bašić
@mabasic
I'm really excited to share my code with you guys. Just a few things left before doing so.
Mario Bašić
@mabasic
Believe it or not, the website is complete: https://mariobasic.com/
The source code is here: https://github.com/mabasic/mariobasic-n7
Let me know what you think :)
There are some bugs that I need to polish like mobile experience etc.
Jose Maria Valera Reales
@Chemaclass
Pretty cool, @mabasic! 👌🏻👏
Jose Maria Valera Reales
@Chemaclass

Adding re-seq phel function 👉 phel-lang/phel-lang#259

Returns a sequence of successive matches of pattern in string.

lonelos
@lonelos

Let me know what you think :)

Nice job my fellow countryman. Just started exploring Phel and found this gem, thank you :)