Skip to content

Instantly share code, notes, and snippets.

View lildata's full-sized avatar

Programming is fun lildata

View GitHub Profile
@bayan
bayan / gist:3382884
Created August 17, 2012 21:27
Clojure DSL to generate static HTML
;; Generating static HTML using Clojure macros
;; It is possible to write a DSL in Clojure that generates HTML markup without the need to write a separate parser and compiler (e.g. HAML).
;; Our aim here would be to write code that converts the following Clojure code into the HTML below it
;; (html
;; (head)
;; (body
;; (h1 "An example")
@daveray
daveray / busy-cursor.clj
Created August 31, 2012 01:56
Clojure/Seesaw busy cursor example
(ns busy-cursor.core
(:use seesaw.core))
(defn long-running-task
[]
(Thread/sleep 5000)
"The result")
(defn run-task-with-busy-cursor
[c]
@weissjeffm
weissjeffm / jgraph.clj
Created February 22, 2013 17:06
repl session so i can remember how this works
; nREPL 0.1.7-preview
user> (use 'seesaw.core)
nil
user> (def myframe (frame :title "Hello" :on-close :exit))
#'user/myframe
user> (import com.mxgraph.view.mxGraph)
com.mxgraph.view.mxGraph
user> (def mygraph (mxGraph.))
#'user/mygraph
user> (defn display [content]
@gerritjvv
gerritjvv / gist:5866665
Last active July 19, 2024 13:29
Calling an external process from Clojure
(comment
This is the easiest and most concise way of calling an external process in Java. The inheritIO methods causes the command to output stdout and errout to the same place as your current process (which most of the times is the console), no need to create mechanisms for reading asynchronously from input streams to get at the information.
http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html
)
(def ret (.waitFor (-> (ProcessBuilder. ["gzip" "-t" "g.txt.gz"]) .inheritIO .start)))
(require '[clojure.core.async :as async :refer :all])
(defn fake-search [kind]
(fn [query]
(Thread/sleep (int (* (java.lang.Math/random) 1000)))
(str kind " result for " query)))
(def web (fake-search "Web"))
(def image (fake-search "Image"))
(def video (fake-search "Video"))
@aldonline
aldonline / gist:6959105
Created October 13, 2013 07:21
SQL string to Scala Stream[ResultSet] and common Loan pattern usages when dealing with SQL connections
object x {
// stream a sql query
def sql( str:String ):Stream[ResultSet] = withStatement { s =>
val rs = s executeQuery str
new Iterator[ResultSet] { def hasNext = rs.next ; def next = rs }.toStream
}
// loan a sql statement
@kawasima
kawasima / pdf2svg.clj
Created March 25, 2014 09:58
MS Excel to SVG by Clojure
(ns pdf2svg
(:require [clojure.java.io :as io])
(:import [org.apache.pdfbox.pdmodel PDDocument PDPageable]
[org.apache.batik.dom GenericDOMImplementation]
[org.apache.batik.svggen SVGGeneratorContext SVGGraphics2D]))
(let [document (PDDocument/load "hoge.pdf")
pageable (PDPageable. document)
dom-impl (GenericDOMImplementation/getDOMImplementation)
svg-document (.createDocument dom-impl "http://www.w3.org/2000/svg" "svg" nil)
@scramjet
scramjet / bench-list.comprehension.clj
Created September 3, 2015 02:26
Bench testing Clojure list comprehensions against map
user> (use 'criterium.core)
nil
user> (def sites (vec (for [i (range 1000)] {:stations (vec (for [j (range 10)] [{:id (str i "-" j)}]))})))
#'user/sites
user> (bench (doall (mapcat (fn [site] (map :id (:stations site))) sites)))
Evaluation count : 74280 in 60 samples of 1238 calls.
Execution time mean : 802.413222 µs
Execution time std-deviation : 10.087328 µs
Execution time lower quantile : 786.940250 µs ( 2.5%)
Execution time upper quantile : 823.245990 µs (97.5%)
@HarmJ0y
HarmJ0y / PowerView-2.0-tricks.ps1
Last active May 18, 2025 13:19
PowerView-2.0 tips and tricks
# NOTE: the most updated version of PowerView (http://www.harmj0y.net/blog/powershell/make-powerview-great-again/)
# has an updated tricks Gist at https://gist.github.com/HarmJ0y/184f9822b195c52dd50c379ed3117993
# get all the groups a user is effectively a member of, 'recursing up'
Get-NetGroup -UserName <USER>
# get all the effective members of a group, 'recursing down'
Get-NetGroupMember -GoupName <GROUP> -Recurse
# get the effective set of users who can administer a server
@jackrusher
jackrusher / webview-for-martin.clj
Last active December 29, 2016 22:24
An example boot-ified Swing app that contains a JavaFX WebView (Webkit instance).
#!/usr/bin/env boot
;; -*- mode: Clojure;-*-
(set-env! :dependencies '[[seesaw "1.4.5"]])
(use 'seesaw.core)
(import '(javafx.scene.web WebView)
'(javafx.scene SceneBuilder)
'(javafx.scene.layout VBoxBuilder))