Skip to content

Instantly share code, notes, and snippets.

View elfenlaid's full-sized avatar
🐧
Slow Distillation ⚗️💭

Egor Mihnevich elfenlaid

🐧
Slow Distillation ⚗️💭
View GitHub Profile
@elfenlaid
elfenlaid / private.xml
Created August 13, 2013 12:08
KeyRemap4MacBook shifts to parentheses tune
<?xml version="1.0"?>
<root>
<item>
<name>Shifts to Parentheses</name>
<appendix>Shifts, when pressed alone, type parentheses. When used with other keys they're normal shifts.</appendix>
<identifier>private.shifts_to_parens</identifier>
<!-- This is the basic mapping. -->
<autogen>--KeyOverlaidModifier-- KeyCode::SHIFT_R, ModifierFlag::SHIFT_R | ModifierFlag::NONE, KeyCode::SHIFT_R, KeyCode::KEY_0, ModifierFlag::SHIFT_L</autogen>
(
#((if (odd? %2)
(conj %1 %2) ; а почему тут кложура пытается чо та эвалюэйтить? я ж всего навсего пытаюсь лист вернуть
%1))
'()
1)
; ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.IFn
; ды, не самый удачный пример) я фкурси про всякие та filter и т.д.,
(defn one-or-no-letter-diff? [a b]
(loop [xs (seq a)
ys (seq b)]
(cond
(= xs ys) true
(and (empty? xs) (= (count ys) 1)) true
(and (empty? ys) (= (count xs) 1)) true
(= (first xs) (first ys)) (recur (rest xs) (rest ys))
:else (or (= (rest xs) ys) (= (rest ys) xs) (= (rest xs) (rest ys))))))
(defn board-step [board]
(let [live-cell \#
dead-cell \space
live-cell? (fn [cell] (= cell live-cell))
transit-cell (fn [cell live-neib]
(if (live-cell? cell)
(cond
(< live-neib 2) dead-cell
(> live-neib 3) dead-cell
:else live-cell)
@elfenlaid
elfenlaid / async_request.py
Created October 23, 2013 09:50
Sync/async diff
import grequests
urls = [
'http://www.heroku.com',
'http://python-tablib.org',
'http://httpbin.org',
'http://python-requests.org',
'http://kennethreitz.com'
]
@elfenlaid
elfenlaid / hcache.clj
Last active December 29, 2015 20:59
trying to get some fun with clojure
(ns hcache.core
(:require [clj-http.lite.client :as client]
[clojure.string :as string]
[clojure.core.async :as async :refer [>! <! >!! <!! go chan]])
(:import (java.io File)))
(def h {"User-Agent" "Mozilla/5.0 (Windows NT 6.1;) Gecko/20100101 Firefox/13.0.1"})
(defn page [url]
(:body (client/get url {:headers h})))
@elfenlaid
elfenlaid / lazy_file.clj
Last active December 31, 2015 15:28
lazy file
(defn lazy-open [file]
(letfn [(helper [rdr]
(lazy-seq
(if-let [line (.readLine rdr)]
(cons line (helper rdr))
(do (.close rdr) (println "closed") nil))))])
(do (println "opening")
(helper (clojure.java.io/reader file))))
@elfenlaid
elfenlaid / cvs_parse.clj
Last active December 31, 2015 17:19
clojure file processing
(defn lazy-open [file]
(letfn [(helper [rdr]
(lazy-seq
(if-let [line (.readLine rdr)]
(cons line (helper rdr))
(do (.close rdr) (println "closed") nil))))]
(do (println "opening")
(helper (clojure.java.io/reader file)))))
(defn parse-cvs [seq]
@elfenlaid
elfenlaid / user.el
Last active January 3, 2016 12:29
Move region up\down
;;; Move region
(defun selected-text ()
(let ((text (if (region-active-p)
(vector (buffer-substring-no-properties (region-beginning) (region-end))
(region-beginning) (region-end))
nil)))
(if (null text) (unit-at-cursor 'line) text)))
(defun move-line (start end n)
@elfenlaid
elfenlaid / translate.clj
Created March 24, 2014 13:47
first useful script on clojure :)
(ns translate.core
(:use clojure-csv.core))
(defonce store (parse-csv (slurp "resources/trans.csv")))
(def lang-shortcuts { "Russian" "ru"
"French" "fr"
"Italian" "it"
"German" "de"
"Spanish" "es"