Skip to content

Instantly share code, notes, and snippets.

View vjache's full-sized avatar

Vyacheslav Vorobyov vjache

View GitHub Profile
@vjache
vjache / SRB
Last active August 29, 2015 14:07
Deadly simple Shared Ring Buffer in Erlang.
%% Shared Ring Buffer
-module(srb).
-export([new/2, push/2, pop/2, pop/1]).
-compile(export_all).
-record(counters,
{ clock :: non_neg_integer(),
max_size :: non_neg_integer() }).
@vjache
vjache / FlumeAppendBatch
Created March 30, 2015 11:24
Batch append to Flume via Avro API.
appendBatch(SomeDir, Events) ->
ProtoFile = filename:join(SomeDir, "flume.avpr"),
{ok, P} = eavro_rpc_fsm:start_link(Host, Port, ProtoFile),
AvroEvents = encode_events_to_eavro_api_events(Events),
{ok, Result} = eavro_rpc_fsm:call(Conn, appendBatch, _Args = [ AvroEvents ]).
encode_events_to_eavro_api_events(Events) ->
[
[ [ {<<"timestamp">>,
@vjache
vjache / codec.erl
Created November 24, 2015 21:27
Encode/Decode problem on Erlang.
-module(codec).
-export([encode/1, decode/1]).
encode(Ss) ->
encode(Ss, "").
encode([], Enc) ->
lists:reverse(Enc);
@vjache
vjache / PipeForward.kt
Created November 18, 2016 15:11
Pipe forward operator
operator fun <T,T1> ((T) -> T1).unaryPlus(): (T.()->T1) {
val f = this
return {
f(this)
}
}
fun mkStr(t:Int) : String {
return ""
}
@vjache
vjache / util.erl
Created November 28, 2017 14:59
Flatten algorithm on Erlang.
%%
%% Util module which contains a simple 'flatten list'
%% implementation which is not fastest but most comprehent.
%%
-module(util).
-export([flatten/1]).
%% Flatten empty list is an empty list.
flatten([]) ->
import time
from typing import Optional, cast, List
import brickpi3
from brickpi3 import BrickPi3
RGB = (int, int, int)
Percent = int
@vjache
vjache / sim.py
Last active February 14, 2020 16:01
Pool inflation simulation.
from random import randint
from time import sleep
target = .1
def proxy_id_gen():
c = 1
while True:
def to_base(number, base):
res = []
while True:
k = number % base
number = number // base
res.append(k)
if number == 0:
break
# res.reverse()
return res
curl --http1.1 --no-keepalive --no-sessionid --insecure --ipv4 --tlsv1 --silent --show-error --path-as-is --proto '=http,https' --connect-timeout 20 --max-time 80 --request POST --data-raw 'do=query&queryMap.M_PARTNO=DXTN26070CY-13&queryMap.RESULT=Y' -H 'Content-Length: 59' -H 'Accept-Language: en-GB,en-US' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Crawlera-Profile: desktop' -H 'X-Crawlera-Cookies: disable' -H 'Accept-Encoding: gzip,deflate' -H 'Host: www.wpgdadago.com' -U 50cb462fae5d4be4aab8df78c79008bb: -x localhost:8010 'https://www.wpgdadago.com/ProductList?do=query'
curl --http1.1 --no-keepalive --no-sessionid --insecure --ipv4 --tlsv1 --silent --show-error --path-as-is --proto '=http,https' --connect-timeout 20 --max-time 80 --request POST --data-raw 'do=query&queryMap.M_PARTNO=IRG4PSC71UDPBF&queryMap.RESULT=Y' -H 'Content-Length: 59' -H 'Accept-Language: en-GB,en-US' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Crawlera-Profile: desktop' -H 'X-Crawlera-Cookies: disable'
import subprocess
import sys
from queue import Queue
from subprocess import Popen
from threading import Thread
curls = Queue(10)
def do_curl():