You Can't "Vibe Code" Love
5 hours ago
This site is now archived. My new coding posts are here http://justinhj.github.io
brew install postgresql svn checkout http://rpostgresql.googlecode.com/svn/trunk/ rpostgresql-read-only cd rpostgresql-read-only R CMD INSTALL --preclean RPostgreSQL
$ [sudo] gem install terminal-notifier
ORbrew install terminal-notifier
Then you can send notifications using a command like this:select `table_schema`, `table_name`, `create_time` FROM information_schema.tables where engine = 'InnoDB' order by create_time desc ;
| Pic from ajc1 on Flikr |
brew install gnutls
touch ~/.authinfo
chmod 600 ~/.authinfo
machine smtp.mail.me.com port 587 login YOURNAME@icloud.com password YOURPASSWORDStep 3. Configure emacs
mdfind -name gnutls-cliStep 4. Testing
(require 'cl) ;; uses lexical-let
(defun make-xml-izer(name)
"Given a symbol NAME this makes a function that outputs an xml string for that
symbol and using fset binds it to the same symbol so it becomes executable.
This pollutes the global function namespace so be careful with which names you
pass in"
(lexical-let ((sym-name name))
(fset (intern name)
(lambda(&rest input)
"returns a string representing the xml encoding of the input sexp"
(let ((res (format "<%s>" sym-name)))
(dolist (item input)
(if (listp item)
(setf res (concat res (eval item)))
(setf res (format "%s%s" res item))))
(setf res (format "%s" res sym-name))
res)))))
;; executing this makes all the symbols in the list below executable
(mapcar (lambda(s)
(make-xml-izer
(symbol-name s)))
'(record date millis sequence logger level class method thread emessage exception frame line))
;; the sample record
(record
(date "2005-02-21T18:57:39")
(millis 1109041059800)
(sequence 1)
(logger nil)
(level 'SEVERE)
(class "java.util.logging.LogManager$RootLogger")
(method 'log)
(thread 10)
(emessage "A very very bad thing has happened!")
(exception
(emessage "java.lang.Exception")
(frame
(class "logtest")
(method 'main)
(line 30))))



# The path to mysql_config.# Only use this if mysql_config is not on your PATH, or you have some weird# setup that requires it.mysql_config = /opt/local/bin/mysql_config5
rottentomatoes.core> (pmap-get-movie-ratings "lord of the rings")
movie url: http://www.rottentomatoes.com/m/lord_of_the_rings_the_return_of_the_king/
Audience 83
Critics 94
movie url: http://www.rottentomatoes.com/m/lord_of_the_rings_the_fellowship_of_the_ring/
Audience 92
Critics 92
movie url: http://www.rottentomatoes.com/m/lord_of_the_rings_the_two_towers/
Audience 92
Critics 96
movie url: http://www.rottentomatoes.com/m/lord_of_the_rings/
Audience 74
Critics 50
movie url: http://www.rottentomatoes.com/m/master_of_the_rings_the_unauthorized_story_behind_jrr_tolkiens_the_lord_of_the_rings/
Audience 34
Critics null
movie url: http://www.rottentomatoes.com/m/jrr-tolkien-and-the-birth-of-the-lord-of-the-rings/
Audience 93
Critics null
movie url: http://www.rottentomatoes.com/m/jrr_tolkien_and_the_birth_of_the_lord_of_the_rings/
Audience 32
Critics null
movie url: http://www.rottentomatoes.com/m/more_at_imdbpro_creating_the_lord_of_the_rings_symphony_a_composers_journey_through_middle_earth/
Audience 100
Critics null
nil
(defproject rottentomatoes "1.0.0-SNAPSHOT"
:description "Clojure code to grab movie ratings from Rotten Tomatoes"
:dependencies [
[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[http.async.client "0.2.1"]
]
:main rottentomatoes.core
:dev-dependencies [
[swank-clojure "1.2.1"]
]
)
(ns rottentomatoes.core
(:gen-class)
(:require
[clojure.contrib.str-utils2 :as s]
[http.async.client :as c]))
(import [java.net URLEncoder]
[java.lang.Character])
(def *base-url* "http://www.rottentomatoes.com")
(def *search-end-point* "/search/full_search.php?search=")
(defn first-match-after [re1 re2 seq]
"Splits the sequence SEQ using RE1 then searches after the first match and before the next match for the first occurence of RE2"
(let [[_ _ after] (s/partition seq re1)]
(re-find re2 after)))
(defn response-status-code [resp]
(:code (c/status resp)))
(defn scoop-url [url]
"Use the http client to do a GET on the url"
(let [resp (c/GET url)]
(c/await resp)
[(response-status-code resp) (c/string resp)]))
;; Get movie urls
;; Does a search of Rotten Tomatoes for the search text, then scrapes the results
;; for the page for each movie. Returns a collection of the movie urls
(defn get-movie-urls [search-text]
(let [encoded-search-text (URLEncoder/encode search-text)
[code body] (scoop-url (str *base-url* *search-end-point* encoded-search-text))
]
(when (= code 200)
(let [[_ _ after] (s/partition body #"<span>Title</span>")]
(let [[_ & results] (s/partition after #"\"(/m/.*/)\"")]
(map #(str *base-url* (second %)) (take-nth 2 results)))))))
;; Given a movie url GET the page then scrape it for the citic and audience rating
(defn get-movie-rating [movie-url]
(let [[code body] (scoop-url movie-url)]
(if (= code 200)
{:critics (second
(first-match-after #"class=\"critic_side_container" #">([0-9]+)<" body))
:audience (second
(first-match-after #"class=\"fan_side" #">([0-9]+)<" body))})))
;; Finds the ratings for all Rotten Tomatoes movies that match the search string and prints them out
(defn get-movie-ratings [search-str]
(let [urls (get-movie-urls search-str)]
(when (> (count urls) 0)
(doseq [url urls]
(let [ratings (get-movie-rating url)]
(printf "movie url: %s\n\tAudience %s\n\tCritics %s\n" url (:audience ratings) (:critics ratings)))))))
;; Slight variant on above that uses pmap so that the requests are done in parallel
(defn pmap-get-movie-ratings [search-str]
(let [urls (get-movie-urls search-str)]
(when (> (count urls) 0)
(let [ratings (pmap #(get-movie-rating %) urls)
url-and-ratings (map vector urls ratings)]
(doseq [[url ratings] url-and-ratings]
(printf "movie url: %s\n\tAudience %s\n\tCritics %s\n" url (:audience ratings) (:critics ratings)))))))