Skip to content

Instantly share code, notes, and snippets.

@kfyodor
kfyodor / schema_exlpain.clj
Last active May 9, 2016 23:04
Transform nested Prismatic's Schema errors into a flat vector of self-explanatory "error keys".
(ns schema-explain
"Provides a function to transform Prismatic's Schema
errors into a flat readable vector of `error keys`."
(:require [schema.core :as s]
[schema.utils :as u]
[clojure.string :as str])
(:import [schema.utils ValidationError NamedError]))
(defn- flatten-tree
"Flattens a tree.
(ns util.db-mapper
(:require [clojure.java.jdbc :refer :all]
[clojure.string :as str])
(:import [java.sql ResultSet] ))
(comment
"mapping should be something like this:"
{:rel [:oauth_access_tokens :users]
:fkey :user_id
@kfyodor
kfyodor / autopager.js
Last active January 17, 2016 06:44 — forked from soemarko/autopager.js
tumblr infinite scroll
/**
A slight variant of http://rocketshake.tumblr.com/post/424849450/infinite-scroll
This file has been uploaded to http://static.tumblr.com/fpifyru/F4wm4bbxj/autopager.js
**/
var tumblrAutoPager = {
url: "http://proto.jp/",
ver: "0.1.7",
rF: true,
gP: {},
@kfyodor
kfyodor / .netrc
Last active August 29, 2015 14:21
machine git.heroku.com
login this_will_be_ignored_so_you_could_write_anything_here
password: heroku_api_key
(ns pixels.core
(:require [reagent.core :as reagent :refer [atom]]))
(def size 20)
(def point
;; Компонент для реагента.
[:div.pixel])
(def white-point
stop on (stopping puma-manager or runlevel [06])
setuid dev
setgid dev
respawn
respawn limit 3 30
normal exit 0 TERM
script
(comment ; Fun with transducers, v2
;; Still haven't found a brief + approachable overview of Clojure 1.7's new
;; transducers in the particular way I would have preferred myself - so here goes:
;;;; Definitions
;; Looking at the `reduce` docstring, we can define a 'reducing-fn' as:
(fn reducing-fn ([]) ([accumulation next-input])) -> new-accumulation
;; (The `[]` arity is actually optional; it's only used when calling
;; `reduce` w/o an init-accumulator).
; ====== Core ======
(ns learning.core
"Main class"
(:require [learning.listutils :as l] :verbose))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(time
def merge_sort_rec(_list):
def sort(_list):
if len(_list) == 0 or len(_list) == 1:
return _list
else:
(left, right) = split(_list)
return merge(sort(left), sort(right))
def merge(left, right):
if len(left) == 0 or len(right) == 0:
@kfyodor
kfyodor / retina.coffee
Created February 22, 2013 09:13
Helper for retina support with Rails 3 Assets Pipeline.
$ ->
if window.devicePixelRatio? and window.devicePixelRatio is 2
$("img.retinaReady").each ->
$(@).attr('src', retinaUrl) if (retinaUrl = $(@).data 'retina_path')?