Skip to content

Instantly share code, notes, and snippets.

View tzach's full-sized avatar

Tzach Livyatan tzach

View GitHub Profile
@tzach
tzach / trace-transducer.clj
Created September 24, 2014 10:35
play around with a trivial trace transducer
;; play around with a trivial trace transducer
;; base on https://gist.github.com/ptaoussanis/e537bd8ffdc943bbbce7#file-transducers-clj
(defn trace-tran
"print the new input on any iteration.
Combine with other transducers for tracing"
[reducing-fn]
(fn new-reducing-fn
([] (reducing-fn))
([accumulation] (reducing-fn accumulation))
@tzach
tzach / backup-repos.py
Created July 7, 2015 07:05
Backup user repos from github, including wiki
#!/usr/bin/env python
# prerequisites
# sudo pip install pyopenssl ndg-httpsclient pyasn1 gitpython --upgrade
#
# Usage: ./backup-repos.py user
#
import requests
console.log('Loading function');
var aws = require('aws-sdk');
var region = 'us-west-2';
var ec2 = new aws.EC2({region: region});
var topicArn = "arn:aws:sns:us-west-2:797456418907:cloudius_running_ec2_instances";
function push(payload, context) {
var sns = new aws.SNS();
# Even Fibonacci numbers
# https://projecteuler.net/problem=2
# Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
# By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
(defn fib
([] (fib 1))
([a] (fib 1 a))
@tzach
tzach / gist:3506717
Created August 29, 2012 04:07
Clojure Dojo Tuesday, August 28, 2012
(ns dojo.core
(use clojure.string))
(def *input*
" _ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|")
(def *zeros*
" _ _ _ _ _ _ _ _ _
@tzach
tzach / gist:3697720
Created September 11, 2012 11:29
Solution to KataBankOCR in Clojure
;; Almost a full solution to KataBankOCR
;; taken from http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR
(ns dojo.core
(:require
[clojure.string :as str]
[clojure.set :as set]))
;; User Story 1
(def *dic*
@tzach
tzach / gist:4131498
Created November 22, 2012 14:40
Two solution to the Coin Change Kata in Clojure
(ns coins.core)
;;; Solution I
;;; recursive, with coin hash as a parameter
(defn make-coins-rec [coins amount h] ;; all possible solutions in a nested list
"return all valid solutions"
(cond
(zero? amount) h
(pos? amount) (map #(make-coins-rec coins (- amount %) (update-in h [%] inc)) coins)))
@tzach
tzach / gist:4140002
Created November 24, 2012 15:00
hello
(ns hello.core)
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
(defn -main []
(foo "Yes, "))
@tzach
tzach / gist:4239925
Created December 8, 2012 11:37
first-enlive input
<!DOCTYPE html>
<html>
<head>
<title>tab title</title>
</head>
<body>
<h2 class="header">header</h2>
<div class="container">
@tzach
tzach / gist:4239938
Created December 8, 2012 11:39
first-enlive output
<!DOCTYPE html>
<html>
<head>
<title>Clojure example!</title>
</head>
<body>
<h2 class="header"> Shouts </h2>
<div class="container">