Skip to content

Instantly share code, notes, and snippets.

@MrGung
MrGung / gist:710353
Created November 22, 2010 18:06
extract-regex
(defun extract-regex (regexp)
"Extracts all occurrences of regexp from the current buffer."
(interactive "sRegexp for extraction: ")
(setq result '())
(save-excursion
(beginning-of-buffer)
(while (re-search-forward regexp nil t)
(when (match-string 0) ; Got a match
(setq result (cons (match-string 0) result)))))
(let ((result-string (mapconcat 'identity result "\n")))
@MrGung
MrGung / clojure_macros_complex_objects.clj
Created April 19, 2011 15:48
Clojure macros don't work with complex objects
;; This will work as expected:
(defmacro create-task-with-out [& body]
(let [[code meta] (get-code-and-meta body)]
`(let [temp-file-out# (get meta :out-file-obj (create-temp-file))]
(Task. (future (wrap-with-out temp-file-out# ~@code))
(assoc ~meta :out-file (.getAbsolutePath temp-file-out#))))))
;; Whereas the following snippet won't work:
(defmacro create-task-with-out [& body]
(let [[code meta] (get-code-and-meta body)
@MrGung
MrGung / gist:972455
Created May 14, 2011 18:02
Automating InternetExplorer and some HTML-scraping with clojure (clr)
(ns zeitkonto)
(import '(System.Reflection Assembly))
(Assembly/LoadFrom "d:\\WatiN-2.1.0.1196\\bin\\net40\\WatiN.Core.dll")
(import '(System DateTime))
(import '(System.Threading ApartmentState Thread ThreadStart))
(import '(WatiN.Core IE Settings))
@MrGung
MrGung / VS_exceptions.fsx
Created August 27, 2011 17:47
Disable exceptions in Visual Studio programamtically using F#
// list of exceptions that will be disabled in the script.
// if an exception is not yet known to Visual Studio the exception will be added to VS's list of exceptions automatically.
let exceptionsToDisable = [|"Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException"
"System.Data.SqlClient.SqlException"
"System.IO.FileNotFoundException"
"System.IO.IOException"
"System.IO.PipeException"
"System.Net.WebException"
"System.NullReferenceException"
"System.Reflection.TargetInvocationException"
@MrGung
MrGung / combine_XPS_files.fsx
Created August 27, 2011 18:31
Combining/Merging XPS files with F#
#r "ReachFramework.dll"
#r "WindowsBase.dll"
#r "PresentationFramework.dll"
#r "PresentationCore.dll"
#r "System.Xaml.dll"
#r "System.Printing.dll"
open System.Windows.Xps.Packaging
open System.Windows.Documents
@MrGung
MrGung / config.clj
Created August 11, 2012 10:16
Configuration with macro
(configure-for-ns gf.job.project.datenbank.simple-patch-db
(extends [config.db-server
gf.job.datenbank.db-patch]
(let [
;; in dieses Verzeichnis werden die Trafo-Skripte generiert und von hier werden sie in das Project-Entwicklungsverzeichnis kopiert
trafo-gen-dir "c:\\Users\\me\\Documents\\Scratch\\Database\\Trafos\\1.0A_patches\\"
;; Hier landen die EXE-Patches.
patches-dst-dir "q:\\Current\\Job.Project\\Current\\Datenbank\\Dev-Patches\\"
db-patches-raw (:db-patches (from-ns-config 'gf.job.project.datenbank.db-patches))
@MrGung
MrGung / config.clj
Created August 11, 2012 10:16
Configuration with functions (and without macro)
(configure-for-ns 'gf.job.project.datenbank.simple-patch-db
(extends ['config.db-server
'gf.job.datenbank.db-patch]
(let [
;; in dieses Verzeichnis werden die Trafo-Skripte generiert und von hier werden sie in das Project-Entwicklungsverzeichnis kopiert
trafo-gen-dir "c:\\Users\\me\\Documents\\Scratch\\Database\\Trafos\\1.0A_patches\\"
;; Hier landen die EXE-Patches.
patches-dst-dir "q:\\Current\\Job.Project\\Current\\Datenbank\\Dev-Patches\\"
db-patches-raw (:db-patches (from-ns-config 'gf.job.project.datenbank.db-patches))
@MrGung
MrGung / cop_db.clj
Created August 12, 2012 11:41
Datenbankzugriff (netz/lokal) per Context Oriented Programming
;; ------------------------------------------------------------------------------------------ some context-oriented-programming-magic
(cop/deflayer local-layer)
(cop/deflayer net-layer)
;; make-writable
(cop/deflayered make-writable [& args] (apply du/make-writable args))
(cop/deflayered make-writable net-layer [& args] nil)
;; detach
(cop/deflayered detach [& args] (apply ad/detach args))
@MrGung
MrGung / gitlab.clone-group.clj
Created November 10, 2020 15:31
Gitlab: Clone all repositories in group
(ns gitlab.clone-group
(:require
[cheshire.core :as json]
[gitlab.api :refer [get-config]]
[babashka.curl :as curl]
[clojure.java.io :as io]
[clojure.tools.cli :refer [parse-opts]]
[babashka.process :refer [$]]))
(defn clone-all-repos-from-group [{:keys [gitlab-token gitlab-root group-id local-root]}]
@MrGung
MrGung / convert_remote_images_to_local.clj
Created April 16, 2022 08:33
download remote #logseq media and replace links to point to local assets. converting from #logseq web-app to desktop-app. written in #clojure, executable with #babashka.
(ns logseq.convert-remote-images-to-local
(:require
[babashka.fs :as fs]
[babashka.curl :as curl]
[clojure.java.io :as io]
[clojure.string :as str]))
;; download remote #logseq media and replace links to point to local assets.
;; converting from #logseq web-app to desktop-app.