Skip to content

Instantly share code, notes, and snippets.

View aleksb86's full-sized avatar
🎯
Focusing

Aleksey aleksb86

🎯
Focusing
  • Russian federation
View GitHub Profile
@aleksb86
aleksb86 / python_logger_example.py
Last active February 7, 2017 09:18
Python simple logging snippet
import logging
# Set logger with logfile (*.log) in same directory as current
# executing file.
logger = set_logger('{}.log'.format(os.path.abspath(__file__)))
# Write error event with traceback information:
try:
1 / 0
@aleksb86
aleksb86 / Add_columns_to_table.sql
Created June 16, 2017 10:35
Script for adding columns to any table (or other than ALTER mass executions).
--Скрипт для добавления столбцов
--в таблицу. IN - список схем и таблиц в строковом виде.
use DWH_ODS_dev
GO
--------------------
declare @t table (sch varchar(50), tabname varchar(50))
declare @sch varchar(50) = ''
declare @tabname varchar(50) = ''
@aleksb86
aleksb86 / delete_duplicates.sql
Created June 22, 2017 07:11
Simple duplicate deletion by unique col
delete from reg.cropio_export exp
where exp.obj in ('machine', 'trailer')
and exp.objectid not in (
select max(objectid) as objectid
from reg.cropio_export
where obj in ('machine', 'trailer')
group by obj, uid
)
;
@aleksb86
aleksb86 / Simple_etl_proc.py
Last active July 13, 2017 13:32
Simple extract, transform\filter and load process in Python.
# -*- coding: UTF-8 -*-
import pyodbc
conn_tmd = pyodbc.connect(r'DSN=DEV_DWH_TMD;UID=informatica-repos;PWD=HswfhmLjhju2')
conn_buff_1c = pyodbc.connect(r'DSN=DWH_1C;UID=dwh_dev;PWD=sd0%7gsh3874')
conn_gis_src = pyodbc.connect(r'DSN=DEV_DWH_GIS;UID=appviews;PWD=g*3MDqEP2ghj')
conn_op_src = pyodbc.connect(r'DSN=DWH_OP;UID=Infaipc_prod_dwh;PWD=HfcnhjdsqHbceyjr4')
conn_sf_src = pyodbc.connect(r'DSN=DWH_SF_src;UID=Infaipc_prod_dwh;PWD={Dsldb;yjqZobr82}')
@aleksb86
aleksb86 / install_rails_env.txt
Created August 15, 2017 06:25
Install RVM, Ruby, gems (Rails, etc.)
1. INSTALL RVM:
aboev@aboev-Vostro-5568:/$ cd /tmp
aboev@aboev-Vostro-5568:/tmp$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: keyring `/home/aboev/.gnupg/secring.gpg' created
gpg: keyring `/home/aboev/.gnupg/pubring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: requesting key 39499BDB from hkp server keys.gnupg.net
gpg: /home/aboev/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
Получить последний коммит: git log --name-status HEAD^..HEAD
Получить N последних коммитов: git log -n <число коммитов>
NB! Удалить все локальные коммиты до указанного: git reset --hard <sha-1 коммита, ДО которого нужно откатиться> (операция необратима)
Откатить отдельный файл к предыдущему коммиту: git checkout 59a89329038f6a5be7e2b2dba4e45e0b6c465ea2 -- core/app/models/core/bpe/tasks/send_exemplars.rb
Откатить все к предыдущему коммиту: git checkout <sha-1 of that commit>
git checkout <хэш коммита, к которому надо откатиться> -- <путь к файлу>
# Simple GET:
$("body")
.on "change", "select#portfolio-select-year", () ->
selected_year = $("select#portfolio-select-year :selected").text()
url = "/fixes?selected_year=#{selected_year}"
$.get(url)
# GET with callback:
@aleksb86
aleksb86 / bash_shorthands.txt
Last active July 26, 2018 12:54
Bash shorthands
# CURL
# -------------------------------------
# curl post request with no data:
curl -X POST http://URL/example.php
# curl post request with data:
curl -d "data=example1&data2=example2" http://URL/example.cgi
# curl POST to a form:
curl -X POST -F "name=user" -F "password=test" http://URL/example.php
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
def validate_request_data(fields, model_name):
def decorator_method(fn):
def decorated(*args, **kwargs):
# args[0] == GenericView Object
error_messages = []
for field in fields:
if not args[0].request.data.get(field, None):
error_messages.append("Field '{}' is required for {}".format(field, model_name))
return Response(
data={