Skip to content

Instantly share code, notes, and snippets.

View renskiy's full-sized avatar

Rinat Khabibiev renskiy

  • Moscow, Russian Federation
View GitHub Profile
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/kevinburke/twilio-go/token"
"github.com/pkg/errors"
)
@renskiy
renskiy / parser.go
Created July 9, 2018 08:01
Syntax analyser of strings like "(foo (bar baz :arg 42))"
package include_parser
import (
"regexp"
"strings"
"errors"
"fmt"
)
var whitespaces = regexp.MustCompile("\\s+")
@renskiy
renskiy / diablo1.js
Last active September 11, 2016 15:54
diabolocom
(() => {
let data = [];
process.stdin.setEncoding('utf8');
process.stdin.on('data', data.push.bind(data));
process.stdin.on('end', () => {
let words = {};
@renskiy
renskiy / base_converter.py
Last active May 5, 2016 16:20
Converts decimal number to the provided base
def convert(number, base):
result = ''
while base < number:
number, remainder = divmod(number, base)
result = str(remainder) + result
return str(number) + result
@renskiy
renskiy / crc_str.py
Last active August 29, 2015 14:16
SqlAlchemy unique str field (for use as `sqlalchemy.orm.composite`)
"""
Author: Rinat Khabibiev <srenskiy@gmail.com>
Compact indexable version of string column for `sqlalchemy` ORM
Uses crc64 hash of string as index value. Supports querying, filtering,
model instantiation and assignment
Usage example:
class User(DeclarativeBase):
@renskiy
renskiy / data.txt
Last active August 29, 2015 14:13
Sum of first N prime numbers
3
4
100
100
1000
@renskiy
renskiy / yml_update.php
Created August 22, 2014 05:34
for TimeWeb
<?php
/**
* Created by PhpStorm.
* User: renskiy
* Date: 15.02.14
* Time: 19:41
*/
class YmlUpdater {
@renskiy
renskiy / RpnTest.php
Last active August 29, 2015 13:56
Reverse Polish notation executor
<?php
require('rpn.php');
class RpnTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider provider_rpn
*/
public function test_rpn($rpn, $expected, $operators='+-/*') {
@renskiy
renskiy / advanced_command.py
Last active August 29, 2015 13:55
Add support of `optparse.OptionGroup` for Django commands
"""
Add support of `optparse.OptionGroup` for Django commands.
Example:
class MyCommand(AdvancedCommand):
option_groups = AdvancedCommand.option_groups + (
make_option_group(
'Option group title',
@renskiy
renskiy / django_select_for_update.py
Last active December 26, 2015 14:29
select_for_update() for Django < 1.4. Tested on Django 1.3.
"""
Adds `select_for_update()` method to Django QuerySet (Django < 1.4).
Usage:
class MyModel(models.Model):
if not hasattr(models.Manager, 'select_for_update'):
objects = ForUpdateManager()
# model definition
"""