Skip to content

Instantly share code, notes, and snippets.

View podviaznikov's full-sized avatar
🗽
NYC, hacking, thinking, observing, feeling

anton podviaznikov

🗽
NYC, hacking, thinking, observing, feeling
View GitHub Profile
@podviaznikov
podviaznikov / clojure-logs-beanstalk.clj
Created May 15, 2013 05:33
to make clojure clojure.tools.logging work on amazon beanstalk past following code somewhere in the app. In case of ring/compojure project on top of handler.
(alter-var-root
#'clojure.tools.logging/*logger-factory*
(constantly (clojure.tools.logging.impl/jul-factory)))
@podviaznikov
podviaznikov / clojure-require-https.clj
Created May 17, 2013 04:57
how to force https traffic in clojure web app
(defn https-url [request-url]
(str (str (str (str "https://" (:server-name request-url) ":") "443")) (:uri request-url)))
(defn require-https
[handler]
(fn [request]
(if (= (:scheme request) :http)
(ring.util.response/redirect (https-url request))
(handler request))))
@podviaznikov
podviaznikov / big-o-links
Last active December 17, 2015 23:48
Some links with Big O related information and algorithms articles in general
@podviaznikov
podviaznikov / clojure-articles-to-read.md
Last active December 18, 2015 00:19
Some useful links to read about Clojure and related staff.
@podviaznikov
podviaznikov / jobs-sites.md
Last active December 18, 2015 02:59
Sites that lists some good jobs.
@podviaznikov
podviaznikov / contract-work-sites.md
Last active December 18, 2015 02:59
List with some interesting sites for freelance and contract jobs.
@podviaznikov
podviaznikov / get-day-name.clj
Created June 11, 2013 00:45
Get day name from date represented as string in "YYYY-MM-DD" format.
(:require [clj-time.format :as clj-time-format]))
(defn get-day [date-str]
(let [date (clj-time-format/parse (clj-time-format/formatter "YYYY-MM-dd") date-str)
day (clj-time-format/unparse (clj-time-format/formatter "EEEE") date)]
day))
(get-day "2013-06-09")
"Monday"
@podviaznikov
podviaznikov / bubblesort.clj
Last active December 25, 2015 13:09
Bubble sort implementation in Clojure.
(defn bubble-step [coll was-changed less?]
(if (second coll)
(let [[x1 x2 & xs] coll
is-less-than (less? x1 x2)
smaller (if is-less-than x1 x2)
larger (if is-less-than x2 x1)
is-changed (or was-changed (not is-less-than))
[sorted is-sorted] (bubble-step (cons larger xs) is-changed less?)]
[(cons smaller sorted) is-sorted])
[coll (not was-changed)]))
var sumBTree = function(tree){
if(!tree || tree.length == 0) return 0
return tree[0] + sumBtree(tree[1]) + sumBtree(tree[2])
}
var tree = [1, [2, [1], [6]], [3, [1]]]
sumBTree(tree) // 14
@podviaznikov
podviaznikov / insertionsort.go
Created October 21, 2013 20:21
Insertion sort implemented with Go
func insertionSort(data []int) []int {
for n := 1; n < len(data); n++ {
v := data[n]
for k:=n - 1; k >= 0; k-- {
if v < data[k] {
// swap
data[k+1] = data[k]
data[k] = v
}
}