Skip to content

Instantly share code, notes, and snippets.

View jartur's full-sized avatar

Ilya 'jartur' Pavlenkov jartur

View GitHub Profile
@jartur
jartur / y.java
Created March 25, 2015 11:53
Java Y Combinator
public class Y<T> implements Function<Function<Function<T, T>, Function<T, T>>, Function<T, T>> {
@FunctionalInterface
private interface FuncToFunc<F> extends Function<FuncToFunc<F>, F> {}
@Override
public Function<T, T> apply(Function<Function<T, T>, Function<T, T>> r) {
final FuncToFunc<Function<T, T>> funcToFunc = f -> f.apply(f);
return funcToFunc.apply(f -> r.apply(x -> f.apply(f).apply(x)));
}
@jartur
jartur / 0_reuse_code.js
Created June 13, 2014 13:53
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
Optional<User> user = users.get(id);
if(user.isPresent()) {
Optional<Account> account = accounts.get(user.get());
if(account.isPresent()) {
Optional<CreditCard> card = cards.get(user.get(), account.get());
if(card.isPresent()) {
card.get().destroy();
}
}
}
AtomicReference<Map> amap;
readOnlyMethod() {
// get immutable map reference
Map m = amap.get();
m.get(key);
...
m.get(key2);
...
}
@jartur
jartur / 00.env+conf
Created February 4, 2014 09:13
libgphoto2
==> Configuration
HOMEBREW_VERSION: 0.9.5
HEAD: 80e6a9cbed41cfe4e53bf0bf8711d92b2eb8f090
CPU: quad-core 64-bit sandybridge
OS X: 10.9.1-x86_64
Xcode: 5.0.2
CLT: 5.0.1.0.1.1382131676
X11: 2.7.5 => /opt/X11
==> ENV
HOMEBREW_CC: clang
class MyActor(ref: ActorRef) extends Actor {
def receive: Receive = {
case Bifurcate =>
context.actorOf(Props[MyActor](new MyActor(sender)))
}
}
@jartur
jartur / island.hs
Created October 31, 2013 19:51
Solution for an "island filled with rain" problem from Google or "walls filled with rain" from Twitter. Uses Data.Sequence to actually find a solution in one pass. http://b.ja.rtur.me/twitter-interview-question-solution/
module Main where
import Data.Sequence
-- *
-- *ww**w*
-- **w****
-- *******
sq = fromList [3,2,1,3,4,2,3]
@jartur
jartur / mem.hs
Created July 20, 2012 15:00
Memory hog + Stack overflow
module Main where
import System.IO
import qualified Data.Map as M
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import Data.List (foldl')
-- maybe Data.Text.Lazy maybe ByteString
(+++) = T.append
@jartur
jartur / mem.hs
Created July 20, 2012 13:27
Memory hog + Stack overflow
module Main where
import System.IO
import qualified Data.Map as M
main = do
inh <- openFile "text.txt" ReadMode
outh <- openFile "dict.txt" WriteMode
counts <- mainLoop inh M.empty
let excsPairs = M.assocs counts
@jartur
jartur / gist:2989312
Created June 25, 2012 15:37
java8 lambda overloading example
public class Wewe {
interface A {
int run(int x);
}
interface B {
int run(String x);
}
private void overloaded(A a)