Skip to content

Instantly share code, notes, and snippets.

View jartur's full-sized avatar

Ilya 'jartur' Pavlenkov jartur

View GitHub Profile
@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)
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class Client {
public static void main(String[] argv)
{
PrintWriter out;
BufferedReader in;
#include "erl_nif.h"
// aes.h & aes_core.c & couple of other files are from openssl
#include "aes.h"
#include <memory.h>
#include <string.h>
static ERL_NIF_TERM aes_ecb_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary in, out, key;
unsigned char* to_encode;
-module(geometry).
-export([startN/1]).
ringAgent(Next) ->
receive
{next, N} when Next =:= undefined ->
ringAgent(N);
kill -> Next ! kill;
M ->
io:format("~p received ~p~n", [self(), M]),
pipeline.addLast("encoder", new OneToOneEncoder() {
@Override
protected Object encode(ChannelHandlerContext channelHandlerContext, Channel channel, Object o) throws Exception
{
Server.getStatisticator().increaseResponses();
Response response = (Response) o;
byte[] bytes = response.getXML().getBytes();
if (Server.isUseEncoder())
(define-syntax (lexer-src-pos-kw s)
(define (char->ci-pattern c)
(list ':or (char-downcase c) (char-upcase c)))
(define (string->ci-pattern s)
(if (symbol? s)
(string->ci-pattern (symbol->string s))
(cons ':: (map char->ci-pattern (string->list s)))))
(define (token-name s)