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 / 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 / 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 / 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'
]
(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)
(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))))))
(
#((if (odd? %2)
(conj %1 %2) ; а почему тут кложура пытается чо та эвалюэйтить? я ж всего навсего пытаюсь лист вернуть
%1))
'()
1)
; ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.IFn
; ды, не самый удачный пример) я фкурси про всякие та filter и т.д.,
@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>
// Here a cave in which live all runtime dragons and wizards
#include <objc/runtime.h>
// We can swap instance methods, they start with '-' minus sign, you know
static void instance_methods_swap(id object, SEL firstSel, SEL secondSel) {
method_exchangeImplementations(
class_getInstanceMethod(object, firstSel),
class_getInstanceMethod(object, secondSel));
}
- (void)presentPicker
{
[Flurry logEvent:@"Picker presented"];
self.picker =
[[[MPMediaPickerController alloc]
initWithMediaTypes: MPMediaTypeAnyAudio] autorelease];
[picker setDelegate:self];
[picker setAllowsPickingMultipleItems:NO];
picker.prompt = @"Choose sound to process";
@interface MediaPicker()
@property (nonatomic, retain) MPMediaPickerController *picker;
@end
@implementation PYSMediaPicker
@synthesize picker;
@synthesize delegate;