<commit_before>(ns foreclojure.social
  (:use foreclojure.utils
        compojure.core
        hiccup.page-helpers
        somnium.congomongo)
  (:require [clj-github.gists :as gist]
            [sandbar.stateful-session :as session])
  (:import java.net.URLEncoder))

(defn tweet-link [status & [anchor-text]]
  (str "<a href=\"http://twitter.com/home?status="
       (URLEncoder/encode status) "\">"
       (or anchor-text "Twitter")
       "</a>"))

(defn gist!
  "Create a new gist containing a user's solution to a problem and
  return its url."
  [user-name problem-num solution]
  (let [user-name (or user-name "anonymous")
        {name :title} (fetch-one :problems
                                 :where {:_id problem-num})
        filename (str user-name "-4clojure-solution" problem-num ".clj")
        text (str ";; " user-name "'s solution to " name "\n"
                  ";; http://4clojure.com/problem/" problem-num
                  "\n\n"
                  solution)]
    (try
      (->> (gist/new-gist {} filename text)
           :repo
           (str "https://gist.github.com/"))
      (catch Throwable _ nil))))

(defn tweet-solution [id gist-url & [link-text]]
  (let [status-msg (str "Check out how I solved http://4clojure.com/problem/"
                        id " - " gist-url " #clojure #4clojure")]
    (tweet-link status-msg link-text)))

(def-page share-page []
  (if-let [[id code] (session/session-get :code)]
    (let [user (session/session-get :user)
          gist-url (gist! user id code)
          gist-link (if gist-url
                      [:div {:id "shared-code-box"}
                       [:div.code
                        [:h3 "Your Solution"]
                        [:pre {:class "brush: clojure;gutter: false;toolbar: false;light: true"} code]]
                       [:br]
                       [:div.share
                         "Share this " (link-to gist-url "solution")
                         " on " (tweet-solution id gist-url) "?"]]<commit_msg>https links<commit_after>(ns foreclojure.social
  (:use foreclojure.utils
        compojure.core
        hiccup.page-helpers
        somnium.congomongo)
  (:require [clj-github.gists :as gist]
            [sandbar.stateful-session :as session])
  (:import java.net.URLEncoder))

(defn tweet-link [status & [anchor-text]]
  (str "<a href=\"http://twitter.com/home?status="
       (URLEncoder/encode status) "\">"
       (or anchor-text "Twitter")
       "</a>"))

(defn gist!
  "Create a new gist containing a user's solution to a problem and
  return its url."
  [user-name problem-num solution]
  (let [user-name (or user-name "anonymous")
        {name :title} (fetch-one :problems
                                 :where {:_id problem-num})
        filename (str user-name "-4clojure-solution" problem-num ".clj")
        text (str ";; " user-name "'s solution to " name "\n"
                  ";; https://4clojure.com/problem/" problem-num
                  "\n\n"
                  solution)]
    (try
      (->> (gist/new-gist {} filename text)
           :repo
           (str "https://gist.github.com/"))
      (catch Throwable _ nil))))

(defn tweet-solution [id gist-url & [link-text]]
  (let [status-msg (str "Check out how I solved https://4clojure.com/problem/"
                        id " - " gist-url " #clojure #4clojure")]
    (tweet-link status-msg link-text)))

(def-page share-page []
  (if-let [[id code] (session/session-get :code)]
    (let [user (session/session-get :user)
          gist-url (gist! user id code)
          gist-link (if gist-url
                      [:div {:id "shared-code-box"}
                       [:div.code
                        [:h3 "Your Solution"]
                        [:pre {:class "brush: clojure;gutter: false;toolbar: false;light: true"} code]]
                       [:br]
                       [:div.share
                         "Share this " (link-to gist-url "solution")
                         " on " (tweet-solution id gist-url) "?"]]
{'fraction_non_alphanumeric': 0.14848031888390634, 'fraction_numerical': 0.002491280518186348, 'mean_word_length': 1.75, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2821227', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1241, 'n_words': 311}