Skip to content

Instantly share code, notes, and snippets.

View n2o's full-sized avatar
🕵️‍♂️
...

Christian Meter n2o

🕵️‍♂️
...
View GitHub Profile
@n2o
n2o / re-frame-subscriptions.clj
Created March 29, 2021 13:23
Converted roman01la's script to babashka. But it does not find usages, where the subscription key is passed to, e.g., a function, where it is then subscribed.
#!/usr/bin/env bb
;; Code based on https://gist.github.com/roman01la/c6a2e4db8d74f89789292002794a7142
;; We converted it work with babashka. Start it with `bb re_frame_subscriptions.clj`
(ns re-frame-subscriptions
(:require [clojure.set :as set]
[babashka.pods :as pods]))
(pods/load-pod "clj-kondo")
@n2o
n2o / pdf-like-fax.md
Last active July 11, 2020 16:25
Babashka Script to make a PDF file look like a fax by using ImageMagick

Inspired by this Gist and @coryodaniel's solution, I put the script inside a babashka script, called pdf-like-fax.clj:

#!/usr/bin/env bb
(defn pdf-like-fax [input output]
  (let [sign (rand-nth ["+" "-"])
        rotation (rand-int 1000)
        cmd (format "convert -density 150 %s -rotate %s0.%s -attenuate 0.4 +noise Multiplicative -attenuate 0.03 +noise Multiplicative -sharpen 0x1.0 -colorspace Gray %s" input sign rotation output)
 prepared-cmd (str/split cmd #" ")]
@n2o
n2o / fizzbuzz-clojure.md
Last active February 20, 2020 09:01
FizzBuzz without conditions in Clojure

Just thought about a FizzBuzz solution written in frege which I saw on a meetup. This solution does not need any conditionals and is completely lazy, which is why I like this solution so much.

The rules are as follows:

  • print all numbers from 1 to n, but...
    • replace all numbers, which are smoothly divisible by 3, with "fizz"
@n2o
n2o / clojure-korma-minimal.md
Last active November 3, 2019 14:16
Minimal Clojure Korma example to read data from a postgresql database

Let's play around with a postgres database and Clojure. To query and insert a database, we need to create one:

docker run --rm --name eventdb -e POSTGRES_PASSWORD=foo -e POSTGRES_USER=foo -e POSTGRES_DB=foo -d -p 5432:5432 postgres

This creates a postgres database named foodb, with password, user and tablename also being foo. Ports are exposed to our local machine and we can access the database at localhost:5432.

Now, we need to connect to the database and create a table, which can be queried and filled with korma. You can use a library to do this, but for a minimal example this is not necessary:

user@host ~ % docker exec -it eventdb su postgres -c psql

Clojure Meetup Juni 2018

Wir haben ein wenig in der REPL gespielt und dabei ist dieser Code entstanden:

(ns intro.core)

(defn spielregeln
  "I don't do a whole lot."
 [x]
@n2o
n2o / New_StartSSL_Certs.md
Created December 31, 2015 14:01
Apache SSL Configuration with new StartSSL certificates

StartSSL reworked their homepage and some other stuff, which is why it now seems that sub.class1.server.ca.pem is unsupported. They now provide new certificates, which must be included into the Apache configuration. The new certificate is called 1_root_bundle.crt and provides all you need to complete the Chain of the certificates to enable trusted and secure communication with your webserver.

Therefore, you have to use the new root_bundle.crt instead of the old sub.class1.server.ca.pem. These lines have to be changed in your Apache configuration:

 SSLEngine on
@n2o
n2o / hands-on-spacemacs.md
Last active November 3, 2017 15:03
First steps with Spacemacs

Spacemacs

In Spacemacs wird die Philosophie verfolgt, dass es nicht den besten Editor gibt, sondern man bemüht sich die besten Funktionen von vim und emacs zu vereinen.

Dabei sind beide Keymappings möglich, vim oder emacs. Oder einfach beides (hybrid-mode). Wenn der emacs-mode gewählt wurde beim Keymapping, so sind die Tastaturkürzel mit M-x (also die Tasten ALT + x) oder M-m meistens zu erreichen. Unter vim-mode finden

@n2o
n2o / clojure-meetup-july-clojure.spec.md
Created July 7, 2017 21:33
Clojure Meetup July: clojure.spec

We played around with clojure.spec and followed the post Interactive Development with clojure.spec.

In the beginning, we started to get to know the semantics of clojure.spec and looked at some specs. After this, we solved the codebreaker-example and successfully defined some specs for it.

REPL Session from Clojure Meetup Düsseldorf, Germany, 6th July 2017

@n2o
n2o / professional-programming-summer-2017-week-12.md
Last active July 6, 2017 12:18
Professional Programming: Results of practical exercises, week 12: JavaFX + SceneBuilder + AnchorPanes

Today we extended the project from week 11 and created a base template. This base template contains an AnchorPane, where FX-elements from other FXML files can be appended to. Therefore, we can change on click our UI and load new elements to it.

// src/main/java/Main.java

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
@n2o
n2o / professional-programming-summer-2017-week-6.md
Last active June 30, 2017 17:06
Professional Programming: Results of practical exercises, week 6

Results (so far) from our practical exercises: Solving the Mars Rover Kata

// build.gradle

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'jacoco'

repositories {