Skip to content

Instantly share code, notes, and snippets.

View lokori's full-sized avatar

Antti Virtanen lokori

View GitHub Profile
@lokori
lokori / 00readme.md
Created June 6, 2016 08:32 — forked from indrora/00readme.md
DeadUpdate: Kickin' it bigtime.

... my first disclosure. Man, it feels weird doing this.

From the vendor that brought you a
                        vulnerable cloud storage platform comes
                        
           ___              ____  __        __     __ 
          / _ \___ ___ ____/ / / / /__  ___/ /__ _/ /____ 
         / // / -_) _ `/ _  / /_/ / _ \/ _  / _ `/ __/ -_)

//_/_,/_,/_/ ./_,/_,/_/_/

-- PostgreSQL does not have merge (insert if not exists). A pattern to easily insert multiple rows of data.
CREATE TABLE rahoitusmuoto_tmp
(
rahoitusmuotoid INT NOT NULL ,
rahoitusmuoto VARCHAR(80) NOT NULL
);
insert into rahoitusmuoto_tmp (rahoitusmuotoid, rahoitusmuoto) values (1, 'valtionosuus');
insert into rahoitusmuoto_tmp (rahoitusmuotoid, rahoitusmuoto) values (2, 'oppisopimus');
@lokori
lokori / partial-export.sql
Last active April 27, 2016 10:45
Exporting partial dataset from PostgreSQL
-- 1. Select the proper subset of data and create a new table.
-- Data types automatically inferred by PostgreSQL. Foreign keys and some other constraints are lost.
create table k_ryhma as
select * from kysymysryhma where valtakunnallinen = true;
-- Select referenced data using .. in (select ..)
create table k_kys as
select * from kysymys where kysymysryhmaid in (select kysymysryhmaid from k_ryhma);
@lokori
lokori / reflector.clj
Created December 16, 2015 08:02
clojure function arity reflector
(defn no-args?
"Returns true if f is a sym/var of a function with no arguments. False otherwise."
[f]
(cond (and
(seq? f)
(= 'fn* (first f)))
(empty? (second f))
(symbol? f)
(= '([]) (:arglists (meta (resolve f))))
@lokori
lokori / compojure-enterprise-auth
Created December 4, 2013 11:32
PoC on how to combine REST api with context sensitive authorization with Clojure. Using Compojure here, but that's not really interesting. Hairy macro magic. Too hairy, but brazilian waxing in progress.
(ns aitu.compojure-util
(:require [compojure.core :as c]
[aitu.toimiala.kayttajaoikeudet :as auth-map]
[clojure.tools.logging :as log]))
(def http-compojure {
:get 'compojure.core/GET
:post 'compojure.core/POST
:delete 'compojure.core/DELETE
:update 'compojure.core/UPDATE})
@lokori
lokori / ring-request-wrapper
Created November 27, 2013 11:29
Example of logging a Ring request with Ring. (I'm aware there are some existing alternatives for doing this.)
(ns aitu.infra.print-wrapper
(:require [clojure.tools.logging :as log]))
(def ^:private requestid (atom 1))
(defn http-method->str [keyword-or-str]
(clojure.string/upper-case (name keyword-or-str)))
(defn log-request-wrapper [ring-handler]
"Logging wrapper. Basic info + duration and additional unique id per request to enable performance analysis"