Skip to content

Instantly share code, notes, and snippets.

View seriyps's full-sized avatar

Sergey Prokhorov seriyps

View GitHub Profile
@seriyps
seriyps / l2tp-downloader.py
Last active October 6, 2015 17:38
Python script, that downloads "network-manager-l2tp" packet and all its dependencies and packs them to archive.
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2012-06-03
@author: Sergey Prokhorov <me@seriyps.ru>
Скрипт для создания архива, содержащего все пакеты, необходимые для оффлайн
установки l2tp плагина NetworkManager на Ubuntu.
'''
@seriyps
seriyps / server.py
Created September 24, 2012 01:16
TornadoWEB streaming file server
# -*- coding: utf-8 -*-
'''
Created on 2012-09-24
@author: Sergey <me@seriyps.ru>
How to test:
$ head -c 100M /dev/urandom > static_file.bin
$ python
@seriyps
seriyps / tornado_shortgen.py
Created October 7, 2012 18:48
AST transformation for tornado.gen.Task
# -*- coding: utf-8 -*-
'''
Created on 2012-10-07
@author: Sergey <me@seriyps.ru>
Альтернативный вариант решения из статьи http://habrahabr.ru/post/153595/
на базе модификации AST
@asynchronous
@seriyps
seriyps / walker_alias.erl
Last active February 15, 2022 14:07
Walker alias method implemented in Erlang
%%% @author Sergey Prokhorov <me@seriyps.ru>
%%% @copyright (C) 2013, Sergey Prokhorov
%%% @doc
%%% @license Apache License Version 2.0
%%%
%%% Walker alias method - efficient random selection with defined probabilities.
%%% <http://en.wikipedia.org/wiki/Alias_method>
%%%
%%% > ProbabilityValueList = [{10, a}, {20, b}, {30, c}, {40, d}],
%%% > WalkerVectors = walker_alias:build(ProbabilityValueList),
@seriyps
seriyps / decode_wordstat.erl
Created August 7, 2013 15:49
Yandex wordstat encrypted AJAX decoder for Python and Erlang
decode_data(Data, UserAgent, Fuid01) ->
Key = iolist_to_binary([binary:part(UserAgent, 0, min(25, size(UserAgent))),
Fuid01,
<<"I keep watch over you ;)">>]),
decode_chars(Data, Key, 0).
decode_chars(<<>>, _, _) ->
<<>>;
decode_chars(<<Char:8, Rest/binary>>, Key, Idx) ->
KeyPos = Idx rem size(Key),
@seriyps
seriyps / email.erl
Last active November 6, 2022 02:03
Send emails using Erlang gen_smtp shortcut.
% Send plaintext email using gen_smtp https://github.com/Vagabond/gen_smtp
% This function sends email directly to receiver's SMTP server and don't use MTA relays.
%
% Example plaintext email:
% Mail = mail_plain(<<"Bob <sender@example.com>">>, <<"Alice <receiver@example.com>">>, <<"The mail subject">>, <<"The mail body">>),
% send_email(Mail).
%
% Example email with image attachment:
% ImgName = "image.jpg",
% {ok, ImgBin} = file:read_file(ImgName),
@seriyps
seriyps / mo_parser.erl
Created September 2, 2013 23:23
Gettext .mo format parser for Erlang
%%% @author Sergey Prokhorov <me@seriyps.ru>
%%% @copyright (C) 2013, Sergey Prokhorov
%%% @doc
%%% Simple gettext .mo file format parser for Erlang.
%%%
%%% Produce [{KeyPlurals::[binary()], TransPlurals::[binary()]}] orddict as
%%% output.
%%% Eg, for .po file (converted to .mo)
%%% <pre>
%%% msgid "Download"
@seriyps
seriyps / microlisp.py
Created April 11, 2014 14:00
Lisp subset interpreter
# -*- coding: utf-8 -*-
'''
Created on 2014-04-05
@author: Sergey Prokhorov <me@seriyps.ru>
'''
import re
import operator
import decimal
@seriyps
seriyps / erlydtl_xgettext.erl
Last active August 29, 2015 14:01
.po file generator from erlydtl templates
%% Usage:
%% TemplatesDir = "templates",
%% TemplatesNames = ["index.dtl", "_layout.dtl"], % filelib:wildcard("*.dtl", TemplatesDir)
%% LocalesDir = "locales",
%% Domain = "my_project", % phrases will be written to "locales/my_project.pot"
%% Messages = extract_messages(TemplatesDir, TemplatesNames),
%% write_pot(Messages, LocalesDir, Domain).
-module(erlydtl_xgettext).
@seriyps
seriyps / tcp_server.rs
Last active November 17, 2022 10:08
Simple concurrent TCP echo server (rust 0.11)
#![feature(phase)]
#[phase(plugin, link)] extern crate log;
extern crate green;
extern crate rustuv;
use std::io;
use std::os;
use std::io::{Listener,Acceptor,TcpStream};
#[start]