Skip to content

Instantly share code, notes, and snippets.

View yuriyzubarev's full-sized avatar

Yuriy Zubarev yuriyzubarev

View GitHub Profile
@yuriyzubarev
yuriyzubarev / lein4clojure.txt
Last active December 11, 2015 06:58
List of problems with special instructions for lein4clojure.
36,173,112,115,116

Clojure and Groovy side-by-side

Clojure Groovy
map
@yuriyzubarev
yuriyzubarev / question 1
Created September 8, 2012 06:05
Algorithms, Part 1, Union Find
(def l [0 1 2 3 4 5 6 7 8 9])
(defn union-qf[p q l]
(let [pid (nth l p)]
(map #(if (= % pid) (nth l q) %) l)))
(println (union-qf 6 7 (union-qf 2 8 (union-qf 0 5 (union-qf 7 1 (union-qf 4 3 (union-qf 2 3 l)))))))
@yuriyzubarev
yuriyzubarev / common.clj
Created June 2, 2012 06:49
Twitter Bootstrap example "Fluid layout" in Hiccup
(ns list-soup.views.common
(:use [noir.core :only [defpartial]]
[hiccup.page-helpers :only [include-css include-js html5]]))
(defpartial layout [& content]
(html5
[:head
[:title "list-soup"]
(include-css "/css/bootstrap.css")
[:style {:type "text/css"}
@yuriyzubarev
yuriyzubarev / the_little_schemer.ss
Created May 8, 2012 19:15
Exercises from "The Little Schemer". Taking a break before hacking again on chapters 8-10.
#lang scheme
(define (atom? x)
(and (not (pair? x)) (not (null? x))))
(define lat?
(lambda (l)
(cond
((null? l) #t)
((atom? (car l)) (lat? (cdr l)))
@yuriyzubarev
yuriyzubarev / categories_languages.textile
Created April 10, 2012 23:29
Categories of programming languages
@yuriyzubarev
yuriyzubarev / secret_santa.py
Created April 3, 2012 22:37
Given a list of people, pick secret santa for everyone. People form the same family shouldn't be santas for each other.
def parse(people):
"""
returns a list of tuples; first element in tuple - last name; second element - a dict
"""
people_dicts = [dict(zip(("first", "last", "email"), person.split())) for person in people.splitlines()]
return [(d["last"], d) for d in people_dicts]
def santafy(l):
def index(i):
@yuriyzubarev
yuriyzubarev / shunting_yard.py
Created March 23, 2012 21:03
From infix notation to Reverse Polish notation using Shunting-yard algorithm
#
# simplified version of http://en.wikipedia.org/wiki/Shunting-yard_algorithm
# no error checking for mismatched parentheses
# letters used instead of numbers
#
def shunting_yard(s):
output_queue = []
operator_stack = []
operators = dict({
@yuriyzubarev
yuriyzubarev / props2xml.py
Created March 21, 2012 22:01
Script to convert .properties files to Sun's XML property files
import os
from os.path import splitext
def xml_start():
return """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
"""
def xml_end():
return "</properties>"
@yuriyzubarev
yuriyzubarev / gist:1904053
Created February 24, 2012 21:58
Literal notations
JavaScript Python
Object {}; new Object(); new function() {}
Array []; new Array()
List []; list()
RegExp //