Skip to content

Instantly share code, notes, and snippets.

@orendon
orendon / humanize-schema-errors.clj
Created February 12, 2017 01:02 — forked from rauhs/humanize-schema-errors.clj
Translate prismatic's schema.core errors to a human readable form. Use this for presenting validation errors to users. Don't use this for programming errors like a missing map key etc.
(ns x.y
(:use [plumbing.core]) ;; Just for the map-vals
(:require [clojure.walk :refer [postwalk prewalk prewalk-demo postwalk-demo]]
[clojure.core.match :refer [match]]
[schema.utils :refer [named-error-explain validation-error-explain]]
[schema.core :as s])
(:import (schema.utils NamedError ValidationError)))
;; Partially FROM:
;; https://github.com/puppetlabs/clj-schema-tools
@orendon
orendon / mini.clj
Created December 21, 2016 16:03 — forked from sarcilav/mini.clj
(defn permutations [s]
(lazy-seq
(if (seq (rest s))
(apply concat (for [x s]
(map #(cons x %) (permutations (remove #{x} s)))))
[s])))
(defn cost [proposoals s]
{:permutation s
:cost (apply + (map-indexed (fn [project candidate-str]
@orendon
orendon / cp-env-to-properties.sh
Created October 19, 2016 20:54 — forked from danielgomezrico/cp-env-to-properties.sh
Gradle / Bash - copy all env variables to app/gradle.properties (used to copy secret env vars from travis or circle CI to build android projects)
#!/usr/bin/env bash
#
# Copy env variables to app module gradle properties file
#
set +x // dont print the next lines on run script
echo $(printenv) | tr ' ' '\n' > app/gradle.properties
set -x
@orendon
orendon / query-syntax.md
Last active October 11, 2016 22:03
clojars query syntax docs proposal

Hi! Today I'll walk you through Lucene search engine syntax to make the best use of clojars website.

We can see a search query as a bunch of terms and operators, let's explore several ways to use our search engine:

Terms

There are 2 types of terms:

  • A term is a single word such as oauth or sql
  • A phrase is just a bunch of words grouped by quotes, like "sql builder"

Boolean operators

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <SPI.h>
char ssid[] = "NULL_INDUS"; // your network SSID (name)
char pass[] = "90046686"; // your network password
@orendon
orendon / ports.sh
Last active September 14, 2016 20:28
which ports are listening
# https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/3/html/Security_Guide/s1-server-ports.html
# sample target port 834
nmap -sT -O localhost
cat /etc/services | grep 834
netstat -anp | grep 834
lsof -i | grep 834
@orendon
orendon / raspi_setup.sh
Last active September 22, 2016 21:32
Raspberry Pi 3 setup raspi
# sd formatter and overwrite sd card
# https://www.sdcard.org/downloads/formatter_4/eula_mac/
# or gparted on linux
diskutil list
diskutil unmountDisk /dev/disk[2]
sudo dd bs=1m if=~/Downloads/software/iot/2016-05-27-raspbian-jessie.img of=/dev/rdisk[2]

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x

(my response to https://twitter.com/apotonick/status/717105889845624832)

I haven't yet came across readily available resources for large-scale application architecture for Elixir apps. I found Programming Phoenix to be a good start for that though. And there's ~30 years of knowledge in the Erlang land :)

For web apps, I found the abstractions that Elixir/Phoenix provides to be really helpful. Indeed, the list below is somewhat ORM focused.

In the small, Ecto.Schema, Ecto.Query, Ecto.Changeset, and Phoenix.View allow me to build highly composable and side-effect free modules. I can have many schemas, changesets and queries all interacting with the same underlying DB table(s) if I want to. Most of the side-effects (through Ecto.Repo for DBs) are usually in the Phoenix.Controller (or other Plugs).