Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Build Logo using Flickr alphabet pictures in newLISP

// it uses my FLICKR context for newLISP
// demo available at http://terpri.com
(define (alphabet-flickr myletter, alph y myurl)
    (setq alph (xml-digest (FLICKR "flickr.groups.pools.getPhotos" nil
                  (append "group_id=27034531@N00&tags=" myletter))))
    (setq alph (clean nil? (map (lambda(x) (if (= myletter ((x (chop(ref 'title x))) 1)) x)) (\
2 -1 (alph 0 2)))))
    (setq y (first (randomize (sequence 0 (length alph)))))
    (setq y (alph y 1))
    (setq myurl (format "http://static.flickr.com/%s/%s_%s_s.jpg"
                       (lookup 'server y)(lookup 'id y)(lookup 'secret y)))
    (println "<img src=" myurl " border=0>"))

    (if (= page-name "Home")
      (begin
            (println {<div class="flickr_banner">})
            (map (lambda (x) (alphabet-flickr x)) '("T" "E" "R" "P" "R" "I"))
            (println "</div>")))

Alphabetical sorter

// This function sorts an array of objects that include this code, alphabetically
// That's nothing new, except this sorts strings starting with a number correctly!

  # ---
  # Sorting
  # ---
def <=>(other)
    regex = /^[\d]+/
    if self.title =~ regex
      our_num = Regexp.last_match[0].to_i
      if other.title =~ regex
        other_num = Regexp.last_match[0].to_i
        return our_num <=> other_num
      end
    end
    self.title <=> other.title
  end
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS