Search Results

Search found 3 results on 1 pages for 'dnolen'.

Page 1/1 | 1 

  • Is there a better way to write this URL Manipulation in Python?

    - by dnolen
    I'm curious if there's a simpler way to remove a particular parameter from a url. What I came up with is the following. This seems a bit verbose. Libraries to use or a more pythonic version appreciated. parsed = urlparse(url) if parsed.query != "": params = dict([s.split("=") for s in parsed.query.split("&")]) if params.get("page"): del params["page"] url = urlunparse((parsed.scheme, None, parsed.path, None, urlencode(params.items()), parsed.fragment,)) parsed = urlparse(url)

    Read the article

  • How would you write this Clojure snippet in Ruby and/or Haskell?

    - by dnolen
    I was working on a Rails template and was trying to write a bit of code that allows me to populate a table or multiple columns of ul tags "top-to-bottom" and "left-to-right" across however many columns I specify. I'm just getting the hang of Ruby so I couldn't figure this out. I'm also curious about an idiomatic Haskell version for this useful snippet. Improvements to Clojure version appreciated: (defn table [xs & {:keys [cols direction] :or {cols 1 direction 'right}}] (into [] (condp = direction 'down (let [c (count xs) q (int (/ c cols)) n (if (> (mod c q) 0) (inc q) q)] (apply map vector (partition n n (repeat nil) xs))) 'right (map vec (partition cols cols (repeat nil) xs))))) With this bit of code I can then do the following: (table (range 10) :cols 3) Printed out this would look like so: 0 1 2 3 4 5 6 7 8 9 And the trickier one: (table (range 10) :cols 3 :direction 'down) Looks like so: 0 4 8 1 5 9 2 6 3 7

    Read the article

  • CouchDB- basic grouping question

    - by dnolen
    I have a user document which has a group field. This field is an array of group ids. I would like to write a view that returns (groupid as key) - (array of user docs as val). This mapping operation seems like a good beginning. function(doc) { var type = doc.type; var groups = doc.groups; if(type == "user" && groups.length > 0) { for(var i = 0; i < groups.length; i++) { emit(groups[i], doc); } } } But there's obviously something very wrong with my attempt at a reduce: function(key, values, rereduce) { var set = []; var seen = []; for(var i = 0; i < values.length; i++) { var _id = values[i]._id; if(seen.indexOf(_id) == -1) { seen.push(_id); set.push(values[i]); } } return set; } I'm running CouchDB 0.10dev. Any help appreciated.

    Read the article

1