Skip to content

Instantly share code, notes, and snippets.

@kubek2k
kubek2k / sha256.clj
Last active October 23, 2022 19:42
SHA-256 in clojure
(defn sha256 [string]
(let [digest (.digest (MessageDigest/getInstance "SHA-256") (.getBytes string "UTF-8"))]
(apply str (map (partial format "%02x") digest))))
@kubek2k
kubek2k / quicksort.pl
Created January 26, 2012 12:05
Quicksort in prolog
pivot(_, [], [], []).
pivot(Pivot, [Head|Tail], [Head|LessOrEqualThan], GreaterThan) :- Pivot >= Head, pivot(Pivot, Tail, LessOrEqualThan, GreaterThan).
pivot(Pivot, [Head|Tail], LessOrEqualThan, [Head|GreaterThan]) :- pivot(Pivot, Tail, LessOrEqualThan, GreaterThan).
quicksort([], []).
quicksort([Head|Tail], Sorted) :- pivot(Head, Tail, List1, List2), quicksort(List1, SortedList1), quicksort(List2, SortedList2), append(SortedList1, [Head|SortedList2], Sorted).

Top picks from StrangeLoop 2016

These are the presentations, which I did like most (and had a chance to watch). Order matters:

  • Idealized commit logs - the best talk IMO. Andrew Shreve shows his approach to better understanding of programs by using technique called program slicing - the idea is to decompose program and its tests in way that every 'commit' contains the smallest part of the code that makes included test pass. This way you get a history of program, which aims at incremental development of understanding. Awesome stuff. https://www.youtube.com/watch?v=dSqLt8BgbRQ&index=4&list=PLcGKfGEEONaDvuLDFFKRfzbsaBuVVXdYa

  • Clojure spec - the technique that is built into the language, allowing you to express the constraints over values as a part of function signature definition. Having those, you are able to validate, auto-document and auto-test (genertively) code. While its not a super innovative idea - it's interesting to see something like this to be implemented as a part of the language (i

2 2016-11-08
12 2016-11-10
2 2016-11-21
2 2016-11-23
20 2016-11-24
10 2016-11-28
7 2016-11-29
1 2017-01-03
20 2017-01-23
8 2017-02-07
#!/usr/bin/env bash
"exec" "clojure" "-Sdeps" "{:deps
{clj-http {:mvn/version \"3.9.1\"}
org.seleniumhq.selenium/htmlunit-driver {:mvn/version \"2.34.0\"}}}" "$0" "$@"
;; usage
;; update/install clojure: brew install clojure
;; make the file executable: chmod +x
;; fill in below config values
;; run the file whenever you want
for a in `heroku list -t omni | tail -n +2 | awk '{ print $1 }'`; do
count=`heroku ps -a $a --json | jq '[.[] | select(.type == "web")] | length' | tr -d '\n'`
if [ "$count" == "1" ]; then
heroku features:enable preboot -a $a
fi
done
@kubek2k
kubek2k / simple-binary-lambda-tutorial.md
Created December 1, 2018 22:50
Short tutorial on how to run any statically linked binary on lambda

Preamble

The introduction of Custom Runtimes has opened up new possibilities when it comes to the spectrum of languages that can be used in Amazon Lambda. This short document will show how to run virtually any statically linked binary on it. The example will cover a stack built Haskell project.

Preparations

@kubek2k
kubek2k / upload-custom-vcl-and-activate.sh
Last active August 30, 2018 12:46
Upload custom vcl to fastly and activate it after successful validation
set -e
function callFastly() {
endpoint="$1"
shift
curl -f -s -H "Fastly-Key: ${FASTLY_TOKEN}" -H "Accept: application/json" "https://api.fastly.com$endpoint" $*
}
function getCurrentVersion() {
callFastly "/service/$SERVICE_ID/version" | jq '.[0].number'
aws rds describe-db-instances | jq '.DBInstances[] | "" + .DBInstanceIdentifier + " " + .MasterUsername + " " + .Endpoint.Address' -r | grep pro > hosts
@kubek2k
kubek2k / process.xslt
Last active July 23, 2018 19:43
The XSLT template to deal with some weird data output from some accountants program.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://www.insert.com.pl/GTSchemas/ListaPlac.xsd"
xmlns:gttns="http://www.insert.com.pl/GTSchemas/Typy.xsd">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<ListyPlac>
<xsl:apply-templates select="x:ListyPlac/x:ListaPlac" />