Skip to content

Instantly share code, notes, and snippets.

View pcomans's full-sized avatar
🙈

Philipp Comans pcomans

🙈
  • Software Engineer at @1debit
  • Sacramento
View GitHub Profile
(defn throw-catch [f]
[(try
(f)
(catch ArithmeticException e "No dividing by zero!")
(catch Exception e (str "You are so bad " (.getMessage e)))
(finally (println "returning... ")))])
(throw (Exception. "Oh noes!"))
(defn throw-catch [f]
(try
(f)
(catch ArithmeticException e "Are you bad at math?")
(catch Exception e (str "That didn't work!" e))
(finally (println "returning..."))))
(defn xors
"Returns bitwise XORs"
[max-x max-y]
(for [x (range max-x)
y (range max-y)]
[x y (bit-xor x y)]))
(def frame (java.awt.Frame.))
(.setVisible frame true)
(.setSize frame (java.awt.Dimension. 512 512))
(defn mkframe []
(let [frame (java.awt.Frame.)]
(.setVisible frame true)
(.setSize frame (java.awt.Dimension. 512 512))
(let [gfx (.getGraphics frame)]
(.drawString gfx (.. (java.util.Date.) toString) 160 256))))
(defn frac-pp [x]
(let [rat (if (rational? x) x (rationalize x))
num (numerator rat)
den (denominator rat)]
(println num)
(println "-----")
(println den)))
(frac-pp 1.5)
(frac-pp (/ 3 2))
(ns lang-map
(:use [clojure.data.json :only (json-str write-json read-json)]))
(defn wiki-lookup [word]
(let [query (str "http://en.wikipedia.org/w/api.php?action=opensearch&search=" word "&namespace=0&format=json")]
(read-json (slurp query))))
(wiki-lookup "Scheme")
(defn acc-tail-merge
"Trololo"
[acc list1 list2 func]
(cond
(empty? list1) (concat acc list2)
(empty? list2) (concat acc list1)
:else (let [[first1 & rest1] list1
[first2 & rest2] list2
[small-first small-rest large-list] (if (func first1 first2) [first1 rest1 list2] [first2 rest2 list1])
new-acc (concat acc [small-first])]
@pcomans
pcomans / InstapaperVollkorn.user.js
Created March 9, 2012 16:29
Changes Georgia to Vollkorn on Instapaper
// ==UserScript==
// @name Instapaper Fonts
// @namespace http://www.philippcomans.de/userscripts
// @description Changes fonts on Instapaper
// @match http://www.instapaper.com/read/*
// ==/UserScript==
(function() {
var head = document.getElementsByTagName('head')[0];
var wf = document.createElement('link');
SITE TOTAL_VISITS CHARGE_FREE PERCENT_CHANGE
British Museum 5842138 F 4.90%
Tate Modern 5061172 F 7.00%
National Gallery 4954914 F 3.70%
Natural History Museum 4647613 F 13.20%
Science Museum (South Kensington) 2751902 F -0.50%
V&A (South Kensington) 2629065 F 16.00%
National Maritime Museum 2419802 F 2.19%
Tower of London (HRP) 2414541 C 1.04%
St Paul's Cathedral 1892467 F/C 4.00%