Skip to content

Instantly share code, notes, and snippets.

View cegorah's full-sized avatar

Aleksei Kharinskii cegorah

View GitHub Profile
@cegorah
cegorah / dict_xsyn.sql
Last active October 10, 2023 07:38
Postgresql dict_xsyn text search configuration
#https://www.postgresql.org/docs/current/dict-xsyn.html
DROP TEXT SEARCH CONFIGURATION text_search_dict;
DROP TEXT SEARCH DICTIONARY mysyn;
CREATE TEXT SEARCH DICTIONARY mysyn (TEMPLATE = xsyn_template, RULES = mysyn);
ALTER TEXT SEARCH DICTIONARY mysyn(RULES='mysyn', KEEPORIG=false);
CREATE TEXT SEARCH CONFIGURATION text_search_dict (COPY = english);
ALTER TEXT SEARCH CONFIGURATION text_search_dict ALTER MAPPING FOR word, asciiword WITH mysyn, english_stem;
with food_with_synms as (SELECT food_id, sponsor_id, portion_id, preparations, brand_name, index_vector, index_string
@cegorah
cegorah / build_mac.sh
Created April 2, 2020 10:26
Cmake build with custom openssl on Mac
#!/bin/bash
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1/lib ..
@cegorah
cegorah / bazel_cpp_installation.sh
Last active January 20, 2020 02:16
Build tensorflow_cpp lib for Debian
apt install curl
curl https://bazel.build/bazel-release.pub.gpg | apt-key add -
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
apt update
apt install python3 python3-numpy git bazel-1.2.1
cd /opt && git clone https://github.com/tensorflow/tensorflow.git && cd tensorflow
./configure
bazel build -c opt --config=monolithic //tensorflow:libtensorflow_cc.so
https://medium.com/@tomdeore/standalone-c-build-tensorflow-opencv-6dc9d8a1412d
@cegorah
cegorah / get_log.py
Created September 11, 2018 03:06
Class for logging purpose
import logging
class GetLog:
"""
This is just a helper class that return logging.logger object with proper setup.
Usage:
info_log = GetLog.setup_logger("info", log_file=log_dir + "info.log",
level=logging.INFO)
error_log = GetLog.setup_logger("error", log_file=log_dir + "error.log",
level=logging.ERROR)
@cegorah
cegorah / connection.py
Created September 11, 2018 02:47
Parse xml with lxml and refresh API key
def check_connection(self):
"""
Routine that check connection with OpenStack and storing api_key to database.
Get necessary value from xml.
"""
try:
indata = sys.stdin.read()
tree = XMLTree(indata)
ip = tree.get_element(".//ip")
password = tree.get_element(".//password")
@cegorah
cegorah / openstack_user.py
Created September 11, 2018 02:44
Save Openstack user in internal database
def create(self):
id = Database.OpenstackUsers.replace(
billing_user_id=self.billing_id, os_user_id=self.ostack_user_id,
os_password_cr=Billing.crypt_password(self.password), proc_module_id=self.proc_module
).execute()
self.save_token(id)
return self
def save_token(self, id):
token_data = dict(
@cegorah
cegorah / Project.py
Last active September 11, 2018 03:07
Function factory based on a class name
def __item_works(self, Item, func_dict):
class_name = Item.__class__.__name__.lower()
if class_name not in func_dict:
raise ValueError("{} is not implemented".format(class_name))
try:
item = func_dict.get(class_name)('')
return item
except Exception as e:
raise e
@cegorah
cegorah / openstack_client.py
Created September 11, 2018 02:36
Send api by method
def send_api_call(self, url, method="post", **kwargs):
"""
Helper that used for sending API-call
:param method: Type of HTTP method
:param url (string): Full url that represent a call
:param json_object (json): JSON object that must be transferred in call
:return: request.response object
"""