Skip to content

Instantly share code, notes, and snippets.

View aleksb86's full-sized avatar
🎯
Focusing

Aleksey aleksb86

🎯
Focusing
View GitHub Profile
@aleksb86
aleksb86 / GIT_DEPLOY_TO_HEROKU.md
Created January 8, 2019 21:40
GIT Deploying Django (DRF) project to Heroku

Before you start - use virtualenv for isolated Python environment. This manual cant apply to Django project with static files (JS, CSS, images etc.) 0. You should to register to heroku.com

  1. Install Heroku CLI: curl https://cli-assets.heroku.com/install-ubuntu.sh | sh or quick install: curl https://cli-assets.heroku.com/install.sh | sh
  2. Create Django-rest-framework project, init git repository.
  3. $ heroku login
  4. $ heroku create [preferred_name_of_application]
  5. Create file runtime.txt (on same level that Django project directory and application directory) with content:
@aleksb86
aleksb86 / query_from_curl_to_elasticsearch
Created December 21, 2018 11:09
How to send query to elasticsearch (REST)
curl -XGET 'localhost:9200/sed_test_db_core_ws_documents/_search?pretty=true&q=id:5c1bbd4cb29a000003000001'
# sed_test_db_core_ws_documents - название индекса, в котором ищется
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={
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
@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
# 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:
Получить последний коммит: 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 <хэш коммита, к которому надо откатиться> -- <путь к файлу>
@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) <[email protected]>" imported
@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 / 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
)
;