Skip to content

Instantly share code, notes, and snippets.

@rotaliator
rotaliator / file_cache.py
Created January 31, 2022 20:54
python file cache decorators
import os
import pickle
import hashlib
from functools import wraps, reduce
def default_filename_fn(args, kwargs):
base = reduce(lambda acc,x: acc + str(x), args, "")
return hashlib.sha1(base.encode()).hexdigest()
(require [meander.epsilon :as m])
(def test-data
{:root
{:first-child
[{:inner-child
[{:element "1"}
{:element "2"}]}
{:elements [{:element "3"}
{:element "4"}
(defn xml->map
"Konwertuje sparsowanego xml'a na mapę.
Uwaga, uwzględnia tylko tagi i zawartość. Ignoruje atrybuty"
[xml]
(walk/postwalk
(fn [e]
(let [content (:content e)]
(cond
(map? e) {(:tag e)
(if (<= (count content) 1)
(require '[clojure.java.io :as io])
(defn filter-files [path mask]
(let [matcher (.getPathMatcher
(java.nio.file.FileSystems/getDefault)
(str "glob:" mask))]
(->> path
io/file
file-seq
(filter #(.isFile %))
(ns soap-service.core
(:import (javax.jws WebMethod WebService WebParam)
(javax.xml.ws Endpoint)))
(definterface ITestService
(^int add [^int a ^int b]))
(deftype ^{WebService {:targetNamespace "http://service.test.com"}} TestService []
ITestService
(^int ^{WebMethod []} add [_
(defn crc32
"Calculates CRC32 checksum of string s"
[^String s]
(let [bytes (.getBytes s)]
(. (doto (new java.util.zip.CRC32)
(.update bytes 0 (alength bytes)))
getValue)))
@rotaliator
rotaliator / humanize_working_time.clj
Created January 28, 2021 20:27
Humanize working time
(import '(java.time LocalTime)
'(java.time.format DateTimeFormatter))
(defn humanize-working-time [time-in-sec]
(-> (LocalTime/parse "00:00:00")
(.plusSeconds time-in-sec)
(.format (DateTimeFormatter/ofPattern "HH:mm:ss"))))
from random import randrange
import sys
import time
def beep():
sys.stdout.write('\r\a')
def guess(min, max):
@rotaliator
rotaliator / cljapp-example.sh
Created July 17, 2020 19:29
SystemD startup file for Clojure deployment
[Unit]
Description=The Server
After=network.target
StartLimitIntervalSec=0
[Service]
User=the-server
Group=the-server
ExecStart=/usr/bin/java -Xms512m -Xmx512m -server -cp /path/to/the-server.jar clojure.main -m the-server.server 8090
Restart=always
(require '[clojure.java.io :as io])
(import '(java.nio.file FileSystems))
(defn glob [path match]
(let [file-system (FileSystems/getDefault)
path-matcher (-> file-system (.getPathMatcher match))]
(->> path io/file .listFiles
(map (fn [f] (.getPath file-system path (into-array String [(.getName f)]))))
(filter (fn [f] (.matches path-matcher f)))
(map (fn [f] (.toFile f))))))