<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Frontera000's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 16:00:45 GMT</pubDate>
    <description>DZone Snippets: Frontera000's Code Snippets</description>
    <item>
      <title>sha1</title>
      <link>http://snippets.dzone.com/posts/show/2816</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(setq SHA1 (import "libssl.so.4" "SHA1"))&lt;br /&gt;&lt;br /&gt;(join (map (lambda (x) (format "%02x" (&amp; x 0xff))) (unpack (dup "c" 20) (get-string (SHA1 "abc" 3 0)))))&lt;br /&gt;&lt;br /&gt;;; produces "a9993e364706816aba3e25717850c26c9cd0d89d"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 14 Oct 2006 09:10:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2816</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>int-&gt;hexstr  and  hexstr-&gt;int</title>
      <link>http://snippets.dzone.com/posts/show/2815</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(set 'hextab "0123456789abcdef")&lt;br /&gt;&lt;br /&gt;(define (int-&gt;hexstr num)&lt;br /&gt;  (set 'hexstr "")&lt;br /&gt;  (for (i 0 63 4)&lt;br /&gt;       (push (hextab (&amp; (&gt;&gt; num i) 0xf)) hexstr))&lt;br /&gt;  (append "0x" hexstr))&lt;br /&gt;&lt;br /&gt;(define (hexstr-&gt;int str)&lt;br /&gt;  (set 'num 0)&lt;br /&gt;  (set 'str (pop str 2))&lt;br /&gt;  (for (i 0 15 1)&lt;br /&gt;       (| (&lt;&lt; (find (str i) hextab) (* 4 i)) num)))&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 14 Oct 2006 09:07:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2815</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>pairlis</title>
      <link>http://snippets.dzone.com/posts/show/2814</link>
      <description>// common LISP compatible pairlis for newLISP&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;;; &lt;br /&gt;;;(pairlis '(1 2 3) '("one" "two" "three") '((4 "four"))) &lt;br /&gt;;;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;(define (pairlis keys data alist) &lt;br /&gt;  (setq data2 data) &lt;br /&gt;  (setq newlist '()) &lt;br /&gt;  (dolist (x keys) &lt;br /&gt;          (push (list x (pop data2)) newlist -1)) &lt;br /&gt;  (append newlist alist)) &lt;br /&gt;&lt;br /&gt;;; newLISPy way&lt;br /&gt;&lt;br /&gt;(define (pairlis keys data alist) &lt;br /&gt;  (append (map (lambda (x y) (list x y)) keys data) alist)) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 14 Oct 2006 08:30:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2814</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>Amazon REST API for newLISP</title>
      <link>http://snippets.dzone.com/posts/show/2812</link>
      <description>&lt;code&gt;&lt;br /&gt;;; (amazon-op "Operation=ItemSearch&amp;SearchIndex=Books&amp;ItemPage=1&amp;Keywords=Cloud+Atlas&amp;Respon\&lt;br /&gt;seGroup=Request,Small")&lt;br /&gt;;;&lt;br /&gt;;; (amazon-op "Operation=SimilarityLookup&amp;ItemId=1400063795,0812966929&amp;SimilarityType=Random\&lt;br /&gt;&amp;ResponseGroup=Request,Large")&lt;br /&gt;;; (amazon-op "Operation=SimilarityLookup&amp;ItemId=1400063795,061873516X,0812966929&amp;Similarity\&lt;br /&gt;Type=Random&amp;ResponseGroup=Request,Small")&lt;br /&gt;&lt;br /&gt;;;  (setq x (xml-digest (amazon-op "Operation=ItemLookup&amp;ItemId=0375507256&amp;ResponseGroup=Req\&lt;br /&gt;uest,Similarities,ListmaniaLists")))&lt;br /&gt;;; Using x get a list of listmanias for an item&lt;br /&gt;;;  (map (lambda (x) (x 1 2 2)) (1 -1 (x (chop (ref 'ListmaniaLists  x)))))&lt;br /&gt;&lt;br /&gt;;; (setq y (amazon-op "Operation=ListLookup&amp;ListType=Listmania&amp;ListId=R21LV6VJEZ794O&amp;Respons\&lt;br /&gt;eGroup=ListFull"))&lt;br /&gt;;; Using y get a list of ISBNs from a listmania&lt;br /&gt;;; (map (lambda(x) (x 4 1 2 )) (8 -1 ( (y (chop (ref 'Lists y)) ) 2))) ; gives list of ISBNs\&lt;br /&gt; from the listmania&lt;br /&gt;&lt;br /&gt;;; get a list of listmania details from a list of listmanias.&lt;br /&gt;;;  (setq z   (map (lambda (x) (xml-digest (amazon-op (append "Operation=ListLookup&amp;ListType\&lt;br /&gt;=Listmania&amp;ListId=" x "&amp;ResponseGroup=ListFull"))))  (map (lambda (x) (x 1 2 2)) (1 -1 (x (c\&lt;br /&gt;hop (ref 'ListmaniaLists  x))))))  )&lt;br /&gt;;;&lt;br /&gt;;; get a list of ISBNs from all of the listmanias for the item&lt;br /&gt;;; (setq z (flat (map (lambda(y) (map (lambda(x) (x 4 1 2 )) (8 -1 ( (y (chop (ref 'Lists y)\&lt;br /&gt;) ) 2))) ) z)))&lt;br /&gt;;;&lt;br /&gt;&lt;br /&gt;;; get item info for all the ISBNs from all listmanias related to the original item&lt;br /&gt;;; (setq w (map (lambda (x) (xml-digest (amazon-op (append "Operation=ItemLookup&amp;ItemId=" x)\&lt;br /&gt;)))  (unique z)))&lt;br /&gt;&lt;br /&gt;;; get a list of pair (title,author) from w above.&lt;br /&gt;;; (map (lambda (x) (list ((x (chop (ref 'Title x))) 1)  (if (ref 'Author x)((x (chop (ref '\&lt;br /&gt;Author x)))1) "???"))) w)&lt;br /&gt;&lt;br /&gt;(define (amazon-op params)&lt;br /&gt;  (get-url (append &lt;br /&gt;"http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&amp;&amp;AWSAccessKeyId=YOUROWNKEY&amp;" params)))&lt;br /&gt;&lt;br /&gt;(define (xml-digest result)&lt;br /&gt;  (xml-type-tags nil nil nil nil)&lt;br /&gt;  (setq xresult (xml-parse result (+ 1 2 4 8 16))))&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 13 Oct 2006 10:16:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2812</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>infinite loop or stack overflow</title>
      <link>http://snippets.dzone.com/posts/show/2790</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(define (x x) (x x))&lt;br /&gt;&lt;br /&gt;(x x)&lt;br /&gt;&lt;br /&gt;;; Or&lt;br /&gt;&lt;br /&gt;((lambda (x) (x x)) (lambda (x) (x x)))&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 06 Oct 2006 00:42:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2790</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>Build Logo using Flickr alphabet pictures in newLISP</title>
      <link>http://snippets.dzone.com/posts/show/2789</link>
      <description>// it uses my FLICKR context for newLISP&lt;br /&gt;// demo available at http://terpri.com&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(define (alphabet-flickr myletter, alph y myurl)&lt;br /&gt;    (setq alph (xml-digest (FLICKR "flickr.groups.pools.getPhotos" nil&lt;br /&gt;                  (append "group_id=27034531@N00&amp;tags=" myletter))))&lt;br /&gt;    (setq alph (clean nil? (map (lambda(x) (if (= myletter ((x (chop(ref 'title x))) 1)) x)) (\&lt;br /&gt;2 -1 (alph 0 2)))))&lt;br /&gt;    (setq y (first (randomize (sequence 0 (length alph)))))&lt;br /&gt;    (setq y (alph y 1))&lt;br /&gt;    (setq myurl (format "http://static.flickr.com/%s/%s_%s_s.jpg"&lt;br /&gt;                       (lookup 'server y)(lookup 'id y)(lookup 'secret y)))&lt;br /&gt;    (println "&lt;img src=" myurl " border=0&gt;"))&lt;br /&gt;&lt;br /&gt;    (if (= page-name "Home")&lt;br /&gt;      (begin&lt;br /&gt;            (println {&lt;div class="flickr_banner"&gt;})&lt;br /&gt;            (map (lambda (x) (alphabet-flickr x)) '("T" "E" "R" "P" "R" "I"))&lt;br /&gt;            (println "&lt;/div&gt;")))&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 06 Oct 2006 00:39:41 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2789</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>Ping technorati using xml-rpc in newLISP</title>
      <link>http://snippets.dzone.com/posts/show/2788</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(setq technorati-request [text] &lt;br /&gt;&lt;methodCall&gt; &lt;br /&gt;  &lt;methodName&gt;weblogUpdates.ping&lt;/methodName&gt; &lt;br /&gt;  &lt;params&gt; &lt;br /&gt;    &lt;param&gt; &lt;br /&gt;      &lt;value&gt;%s&lt;/value&gt; &lt;br /&gt;    &lt;/param&gt; &lt;br /&gt;    &lt;param&gt; &lt;br /&gt;      &lt;value&gt;%s&lt;/value&gt; &lt;br /&gt;    &lt;/param&gt; &lt;br /&gt;  &lt;/params&gt; &lt;br /&gt;&lt;/methodCall&gt; &lt;br /&gt;[/text]) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; (XMLRPC:execute  "http://rpc.technorati.com/rpc/ping" (format technorati-request "terpri.com" "http://terpri.com")) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 06 Oct 2006 00:35:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2788</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>library mashup</title>
      <link>http://snippets.dzone.com/posts/show/2737</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;;; combine APIs and other web available bibliographic data.&lt;br /&gt;;; Use amazon, LibraryThing, and OCLC Worldcat.&lt;br /&gt;;; Get ISBN numbers for a book by searching author and title.&lt;br /&gt;;; Get the list of available ISBNs from different sources.&lt;br /&gt;;; Get "tags" available for a book from LibraryThing for&lt;br /&gt;;; a given book.&lt;br /&gt;;; etc.&lt;br /&gt;;;&lt;br /&gt;;; N.B. A person from LibraryThing.com posted a comment&lt;br /&gt;;; regarding this program, indicating that the tag cloud data&lt;br /&gt;;; is copyrighted. &lt;br /&gt;;;&lt;br /&gt;;; Here's the quoted message:&lt;br /&gt;;;&lt;br /&gt;;; Tim's message: "And it's fine here, as a test, and probably in other &lt;br /&gt;;; contexts where it could be considered "fair use" under copyright. &lt;br /&gt;;; But--unlike the thingISBN service and some other LibraryThing &lt;br /&gt;;; APIs--LibraryThing's tag clouds are not free for public use, &lt;br /&gt;;; outside of the RSS feeds and widgets we provide. &lt;br /&gt;;; We're not sure how and under what license to &lt;br /&gt;;; release them when we do."&lt;br /&gt;;;&lt;br /&gt;;; So, I wrote this for fun.  If I were you I wouldn't run it, just read&lt;br /&gt;;; the code.  :-)&lt;br /&gt;;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(define (search-worldcat title author)&lt;br /&gt;  (setq title (replace " " title "+"))&lt;br /&gt;  (setq author (replace " " author "+"))&lt;br /&gt;  (get-url (append "http://worldcatlibraries.org/search?q=ti:" title "+au:" author "&amp;qt=advanced")))&lt;br /&gt;&lt;br /&gt;(setq oclc-url-1-pattern {&lt;div class="name"&gt;&lt;a href=})&lt;br /&gt;&lt;br /&gt;(define (oclc-url-1 str)&lt;br /&gt;  (setq loc (find oclc-url-1-pattern str))&lt;br /&gt;  (setq loc (+ loc (length oclc-url-1-pattern)))&lt;br /&gt;  (setq loc (+ 1 loc))&lt;br /&gt;  (setq loc-end (find "&gt;" (loc -1 str)))&lt;br /&gt;  (setq loc-end (- loc-end 1))&lt;br /&gt;  (setq loc-url (loc loc-end str))&lt;br /&gt;  (println (append "http://worldcatlibraries.org" loc-url))&lt;br /&gt;  (get-url (append "http://worldcatlibraries.org" loc-url)))&lt;br /&gt;&lt;br /&gt;(setq oclc-isbn-pattern "&lt;strong&gt;ISBN: &lt;/strong&gt;")&lt;br /&gt;&lt;br /&gt;(define (find-isbn str)&lt;br /&gt;  (setq loc (find oclc-isbn-pattern str))&lt;br /&gt;  (setq loc (+ loc (length oclc-isbn-pattern)))&lt;br /&gt;  (setq loc-end (find "&lt;/li&gt;" (loc -1 str)))&lt;br /&gt;  (loc loc-end str))&lt;br /&gt;&lt;br /&gt;(define (thing-isbn isbn)&lt;br /&gt;  (xml-type-tags nil nil nil nil)&lt;br /&gt;  (setq isbn-data &lt;br /&gt;      (xml-parse (get-url  &lt;br /&gt;          (append "http://www.librarything.com/api/thingISBN/" isbn)))))&lt;br /&gt;&lt;br /&gt;(define (get-isbn-list isbn-data)&lt;br /&gt;  (setq indexer (ref "isbn" isbn-data))&lt;br /&gt;  (nth-set 2 indexer 2)&lt;br /&gt;  (setq num-isbns (length  (isbn-data 0)))&lt;br /&gt;  (setq isbn-list '())&lt;br /&gt;  (for (idx (first (1 indexer))  (- num-isbns 1))&lt;br /&gt;        (push (isbn-data (first (0 indexer)) idx (first (2 indexer))) isbn-list -1))&lt;br /&gt;   isbn-list)&lt;br /&gt;&lt;br /&gt;(define (add-explorer-path)&lt;br /&gt;   (env "PATH" (append (env "PATH" ) ";c:\\program files\\internet explorer")))&lt;br /&gt;&lt;br /&gt;(define (show-amazon-isbn isbn)&lt;br /&gt;   (process (append "iexplore " "http://www.amazon.com/exec/obidos/ASIN/"&lt;br /&gt;           isbn )))&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(define (get-librarything-isbn isbn)&lt;br /&gt;    (get-url (append "http://librarything.com/isbn/" isbn)))&lt;br /&gt;&lt;br /&gt;(define (get-librarything-tagsection str)&lt;br /&gt;    (setq loc (find "Tags used" str ))&lt;br /&gt;    (setq mystr (loc -1 str))&lt;br /&gt;    (setq loc-end (find "&lt;/div&gt;" mystr))&lt;br /&gt;     (0 loc-end mystr))&lt;br /&gt;&lt;br /&gt;(define (get-librarything-taglist mystr)&lt;br /&gt;    (setq tags-list '())&lt;br /&gt;    (while (setq tag-loc (find "/tag/" mystr))&lt;br /&gt;        (setq tag-loc-end (find "target=" (tag-loc -1 mystr)))&lt;br /&gt;        (push ((+ tag-loc 5) (- tag-loc-end 7) mystr) tags-list -1)&lt;br /&gt;        (setq mystr ((+ tag-loc tag-loc-end ) -1 mystr)))&lt;br /&gt;    tags-list)&lt;br /&gt;&lt;br /&gt;(define (show-librarything-tag tag)&lt;br /&gt;   (process (append "iexplore " "http://www.librarything.com/tag/"&lt;br /&gt;           tag )))&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 30 Sep 2006 03:52:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2737</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>car cdr cons from little LISPer</title>
      <link>http://snippets.dzone.com/posts/show/2733</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(define cons&lt;br /&gt; (lambda (u v)&lt;br /&gt;   (lambda (b)&lt;br /&gt;     (cond (b u)&lt;br /&gt;     (#t v)))))&lt;br /&gt;(define lunch (cons 'apple '()))&lt;br /&gt;(define car (lambda (l) (l #t)))&lt;br /&gt;(define cdr (lambda (l) (l #f)))&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 29 Sep 2006 19:32:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2733</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>the applicative-order Y-combinator</title>
      <link>http://snippets.dzone.com/posts/show/2732</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(define Y&lt;br /&gt;  (lambda (f)&lt;br /&gt;    (let ((future&lt;br /&gt;            (lambda (future)&lt;br /&gt;              (f (lambda (arg) &lt;br /&gt;                   ((future future) arg))))))&lt;br /&gt;      (future future))))&lt;br /&gt;&lt;br /&gt;((Y (lambda (factorial)&lt;br /&gt;      (lambda (n)&lt;br /&gt;        (if (= n 0)&lt;br /&gt;            1&lt;br /&gt;            (* n (factorial (- n 1)))))))&lt;br /&gt; 42)&lt;/code&gt;</description>
      <pubDate>Fri, 29 Sep 2006 19:32:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2732</guid>
      <author>frontera000 (bob bae)</author>
    </item>
  </channel>
</rss>
