Skip to content

Instantly share code, notes, and snippets.

View slowli's full-sized avatar

Alex Ostrovski slowli

View GitHub Profile
@slowli
slowli / LangUrlRule.php
Created March 24, 2015 10:09
Правило создания / разбора URL с поддержкой нескольких языков
<?php
class LangUrlRule extends CUrlRule {
/**
* Регулярное выражение для поддерживаемых языков интерфейса.
*/
const LANG_REGEX = '(ru|uk|en)';
/**
* Если значение булевой переменно, то правило ведет себя
@slowli
slowli / common.py
Created June 21, 2015 10:52
Embedding declarations in runnable Python scripts
'''
Example of an embeddable module.
'''
#region get_input
def get_input():
''' Scans and returns input until EOF symbol. '''
input_text = ''
try:
@slowli
slowli / template.py
Created June 21, 2015 10:58
Template for Rosalind.info solutions
#!/usr/bin/python
'''
Template for Rosalind.info problems
AFRQ problem (http://rosalind.info/problems/afrq/) is used
to illustrate tests and processing input / output.
'''
import unittest, sys
@slowli
slowli / decorators.py
Created June 22, 2015 10:55
A little demonstration of decorators in Python
#!/usr/bin/python
'''
A little demonstration of decorators in Python.
'''
import sys
def noargs(decorator):
''' Decorator enabling use of no-args form for parametric decorators. '''
@slowli
slowli / dp.py
Created June 23, 2015 09:01
Dynamic programming in Python with decorators
#!/usr/bin/python
'''
Demonstration of functional-style dynamic programming implementation
in Python using decorators and generators.
Run the script to measure efficiency of decorator-based DP implementations
compared to imperative bottom-up implementations (spoiler: decorators are slow).
The following recurrent formulas are used:
@slowli
slowli / tree.py
Created June 24, 2015 17:44
Tree algorithms in Python with decorators
#!/usr/bin/python
'''
Implementation of trees with some useful methods:
copying, parsing and creating Newick tree representation, getting splits,
testing for equality, changing the root node, etc.
Most recurrent relationships in trees (e.g., tree splits) are implemented
using a custom function decorator.
Run as a script to test all methods.
@slowli
slowli / autogen.rs
Created March 7, 2018 12:18
Envisioned codegen
// Not complete, but you get the idea.
impl<'a> Transactions<'a> {
pub const SERVICE_ID: u16 = 1;
fn write_payload(&self, writer: &mut ::exonum::messages::MessageWriter) {
match *self {
Transactions::CreateWallet { public_key, name } => {
let __from = 0 as ::exonum::encoding::Offset;
let __size = <&'a PublicKey as ::exonum::encoding::Field>::field_size();
@slowli
slowli / noise.rs
Last active June 14, 2018 10:35
Generic stepwise handshake for Exonum
// Copyright 2018 The Exonum Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@slowli
slowli / schema.rs
Created February 11, 2020 15:11
Declarative schema description
#[derive(FromAccess)]
struct Schema<T: Access> {
pub transactions: MapIndex<T::Base, Hash, Transaction>,
pub blocks: ListIndex<T::Base, Hash>,
pub wallets: ProofMapIndex<T::Base, PublicKey, Wallet>,
pub wallet_history: Group<T, PublicKey, ProofListIndex<T::Base, Hash>>,
}
@slowli
slowli / interface.rs
Created February 11, 2020 15:12
Interface description in Exonum 1.0
/// Cryptocurrency service transactions.
#[exonum_interface]
pub trait CryptocurrencyInterface<Ctx> {
/// Output of the methods in this interface.
type Output;
/// Creates wallet with the given `name`.
#[interface_method(id = 0)]
fn create_wallet(&self, ctx: Ctx, arg: CreateWallet) -> Self::Output;
/// Transfers `amount` of the currency from one wallet to another.