Skip to content

Instantly share code, notes, and snippets.

View un1t's full-sized avatar

Ilya Shalyapin un1t

View GitHub Profile
@un1t
un1t / abcnum_converter.py
Created April 6, 2016 18:56
Converting an Integer to a String in Any Base
import string
# http://interactivepython.org/runestone/static/pythonds/Recursion/pythondsConvertinganIntegertoaStringinAnyBase.html
class AbcNumCoverter:
chars = string.digits + string.ascii_lowercase
base = len(chars)
@classmethod
def to_str(cls, n):
@un1t
un1t / elasticsearch_ru_stemming_and_morphology.py
Created March 10, 2016 12:10 — forked from svartalf/elasticsearch_ru_stemming_and_morphology.py
Example of the ElasticSearch configuration for russian stemming and morphology
requests.put('http://localhost:9200/site/', data=json.dumps({
'settings': {
'analysis': {
'analyzer': {
'ru': {
'type': 'custom',
'tokenizer': 'standard',
"filter": ['lowercase', 'russian_morphology', 'english_morphology', 'ru_stopwords'],
},
},
@un1t
un1t / checksock.py
Created December 11, 2015 11:02
python check unix socket
from __future__ import print_function
import socket, sys
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
addr,path = sys.argv[1].split(":")
sock.connect(addr)
sock.send("""GET {} HTTP/1.1
host: test.ru
@un1t
un1t / parse-xml.go
Last active January 3, 2022 09:36
Golang XML stream parser
package main
// https://github.com/dps/go-xml-parse/blob/master/go-xml-parse.go
import (
"fmt"
"os"
"encoding/xml"
)
@un1t
un1t / elastic-bulk.go
Last active October 18, 2021 01:49
golang elasticsearch bulk insert
package main
import (
"fmt"
"gopkg.in/olivere/elastic.v2"
"strconv"
)
type Tweet struct {
User string `json:"user"`
@un1t
un1t / vagrant-boxes
Created April 27, 2015 14:05
Suspend Vagrant boxes before shutdown on Ubuntu
#!/bin/sh
# save it to "/etc/init.d/vagrant-boxes"
# sudo update-rc.d vagrant-boxes defaults 99 01
RETVAL=0
USER='ilya'
stop() {
LIST=`sudo -u $USER vagrant global-status | grep running | awk '{print $1}'`
for i in `echo $LIST`; do
import readline
texts = ['hello', 'world', 'readline']
def completer(text, state):
options = [x for x in texts if x.startswith(text)]
try:
return options[state]
except IndexError:
return None
@un1t
un1t / pathspec
Created March 10, 2015 18:31
pathspec match_files example
pathspec.match_files(map(pathspec.GitIgnorePattern, ["*.css", "!*.ie.css"]), ["styles.css", "styles.ie.css", ".tmp"])
@un1t
un1t / .vimrc
Created February 24, 2015 07:50
set list
set expandtab
retab 4
set shiftwidth=4
set tabstop=4
syntax on
set nu
set ai
@un1t
un1t / django-script.py
Created February 21, 2015 21:48
How to run scripts outside django
# coding: utf-8
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
django.setup()
# write your code here