Skip to content

Instantly share code, notes, and snippets.

View gist:fac512ac534cefc7ab4ae5421e4d4917
import trio
async def sleeper():
try:
await trio.sleep(30)
except KeyboardInterrupt:
print("KBInterrupt")
async def test():
with trio.open_cancel_scope() as cancel_scope:
@remleduff
remleduff / gist:1876575
Created Feb 21, 2012
Simplified AST processing code from CinC
View gist:1876575
(use '[clojure.walk :only [walk]])
(def ^:dynamic ^:private *frame*)
(defn- new-frame [] (atom {}))
(defn- collect-frame [ast]
(case (:op ast)
:constant
{:constants [{:value (:form ast)}]}
View gist:415019
(use 'clojure.java.io)
(def string-url "http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html")
(defonce text (let [writer (java.io.StringWriter.)]
(copy (-> (java.net.URL. url) .openStream) writer) writer))
(defonce jdoc-pattern #"(?s)<A NAME=\"(\w*)\((.*?)\).*?</A>.*?<PRE>(.*?)</PRE>(.*?)<HR>")
(def html-entities
View gist:414786
GtkOffscreenWindow* offscreenWindow;
GtkPixmap* snapshotWidget(GtkWidget* widget) {
// Caching doesn't work, must create a new one every time (the widget parameter is gtk_widget_destroy'ed by the caller)
// if (!offscreenWindow)
offscreenWindow = gtk_offscreen_window_new();
gtk_container_add(offscreenWindow, widget);
gtk_widget_show(offscreenWindow);
force_draw(widget);
View gist:410416
(defprotocol Base
(test-foo [o]))
(deftype Impl []
Base
(test-foo [_] "test"))
(defprotocol Base)
(defprotocol Base
View gist:388872
(defmulti url (fn [key &_] key))
(defmethod url :username [_ user] (str "/" user))
(defmethod url :home [_ _] "/")
(defmethod url :item [_ item] (str "/media/" item))
View gist:387448
(doto (javax.swing.JFrame.)
(.setSize 100 100)
(.addKeyListener (proxy [java.awt.event.KeyAdapter] [] (keyPressed [e] (println "hello"))))
(.setVisible true))
View Fixed main.clj
; Also need to add (java.io StringReader) to :import at the top of the file
(defn- eval-opt
"Evals expressions in str, prints each non-nil result using prn"
[str]
(let [eof (Object.)
reader (LineNumberingPushbackReader. (StringReader. str))]
(loop [input (read reader false eof)]
(when-not (= input eof)
(let [value (eval input)]
View gist:336731
(ns leiningen.repl
"Starts a REPL using the project's classpath."
(:use [leiningen.compile :only [eval-in-project find-lib-jars]])
(:require [clojure.main])
(:import [java.net URL URLClassLoader]
[java.io File FilenameFilter]))
(def *project*)
(def *classpath*)
View gist:336602
(defn files-in-dir
([dir]
(let [dirFile (File. dir)]
(.list dirFile)))
([dir suffix]
(let [dirFile (File. dir)
fileFilter (proxy [FilenameFilter] []
(accept [dir name] (.endsWith name suffix)))]
(.list dirFile fileFilter))))
You can’t perform that action at this time.