Skip to content

Instantly share code, notes, and snippets.

View zelark's full-sized avatar

Aleksandr Zhuravlёv zelark

View GitHub Profile
@zelark
zelark / fizzbuzz.clj
Last active October 7, 2020 10:28
#fizzbuzz
(defn fizzbuzz [n]
(let [fizzes (cycle ["" "" "Fizz"])
buzzes (cycle ["" "" "" "" "Buzz"])
pattern (map str fizzes buzzes)
numbers (map str (rest (range)))]
(take n (map #(some not-empty %&) pattern numbers)))) ;; another option would be `(partial max-key count)`
(run! println (fizzbuzz 100))
@zelark
zelark / jekyll.md
Last active May 10, 2020 15:24
#jekyll
$ bundle exec jekyll serve
https://jekyllrb.com/docs/installation/macos/#on-mojave-1014

sudo gem install bundler
sudo gem install -n /usr/local/bin/ jekyll

Lessons learned; The nice and accurate counsel of Alex Miller, programmer

TL:DR

  • Be intentional
  • Stay connected to the problem
  • Use tables to explore alternatives
  • Make a picture

1. Read the docs!

(defn eager-map [f coll]
(when-first [x coll]
(println "iteration")
(cons (f x)
(eager-map f (rest coll)))))
(defn lazy-map [f coll]
(lazy-seq
(when-first [x coll]
(println "iteration")
@zelark
zelark / clojure-programming-blog.md
Last active April 16, 2020 21:23
#clojure #clojurescript #blog #grumpy.website

Clojure Programming: Blog

  • Part 1: Начало статического блога. Immutant, Ring, Compojure, HTML rendering через Rum
  • Part 2: Forms, middlewares, redirects, 404 and error handling
  • Part 3: id generator, loops, cookies, sessions, authorization, working w/ files, macros
  • Part 4: Cookies, рефакторинг, неймспейсы, RSS фид
  • Part 5: Infinite Scroll на JS, sitemap.xml, robots.txt
  • Part 6: Настраиваем CLJS окружение
  • Part 7: Переделываем форму редактирования на Rum, клиент+сервер-сайд рендеринг, EDN-сериализация данных
  • Part 8: CLJS, drag-n-drop upload, browser API, Rum mixins, local state
@zelark
zelark / hashmap.c
Last active April 5, 2020 16:14
You can find the original example here https://youtu.be/wg8hZxMRwcw
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HASHMAP_SIZE 16
typedef struct entry_t {
char *key;
char *value;
struct entry_t *next;
@zelark
zelark / lispy.c
Last active April 2, 2020 10:49
Build your own LISP
#include "mpc.h"
#include <editline/readline.h>
#define LASSERT(args, cond, fmt, ...) \
if (!(cond)) { \
lval* err = lval_err(fmt, ##__VA_ARGS__); \
lval_del(args); \
return err; \
}
(def input [1,12,2,3, 1,1,2,3, 1,3,4,3, 1,5,0,3, 2,13,1,19, 1,5,19,23, 2,10,23,27, 1,27,5,31, 2,9,31,35, 1,35,5,39, 2,6,39,43, 1,43,5,47, 2,47,10,51, 2,51,6,55, 1,5,55,59, 2,10,59,63, 1,63,6,67, 2,67,6,71, 1,71,5,75, 1,13,75,79, 1,6,79,83, 2,83,13,87, 1,87,6,91, 1,10,91,95, 1,95,9,99, 2,99,13,103, 1,103,6,107, 2,107,6,111, 1,111,2,115, 1,115,13,0, 99,2,0,14, 0])
(defn add [m p1 p2 p3]
(let [a (get m p1)
b (get m p2)]
(assoc m p3 (+ a b))))
(defn mul [m p1 p2 p3]
(let [a (get m p1)
b (get m p2)]

Problem:

xcrun: error: invalid active developer path (/Applications/Xcode.app/Contents/Developer/), missing xcrun at: /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun

Solution:

xcode-select --install

# optional
@zelark
zelark / vm.py
Created April 4, 2014 14:41
python virtual machine
# http://tech.blog.aknin.name/2010/04/02/pythons-innards-introduction/
# http://tech.blog.aknin.name/category/my-projects/pythons-innards/
# http://akaptur.github.io/blog/2013/08/14/python-bytecode-fun-with-dis/
# from vm import VirtualMachine
# vm = VirtualMachine()
# vm.byte_LOAD_CONST('a')
# vm.byte_LOAD_CONST('b')
# vm.byte_BUILD_LIST(2)
# vm.byte_BUILD_LIST(0)