Skip to content

Instantly share code, notes, and snippets.

View izmailoff's full-sized avatar
🎯
Focusing

Aleksey Izmailov izmailoff

🎯
Focusing
View GitHub Profile
@izmailoff
izmailoff / closure_madness_in_python
Created September 30, 2021 01:51
Python closures are dangerous
# SCALA
scala> val fs = List(1, 2, 3).map(i => () => i)
val fs: List[() => Int] = List($Lambda$2341/0x00000008408e7c40@64518270, $Lambda$2341/0x00000008408e7c40@3b7c58e7, $Lambda$2341/0x00000008408e7c40@79627d27)
scala> fs.foreach(x => println(x()))
1
2
@izmailoff
izmailoff / gen_sql_fk_to_cascade_option.sql
Created February 23, 2021 09:55
Change all Postgres foreign keys to on update cascade - generates sql which you can execute.
select
cl2.relname as child_table,
att2.attname as "child_column",
cl.relname as "parent_table",
att.attname as "parent_column",
conname,
'alter table ' || cl2.relname || ' drop constraint ' || conname || ';' as drop_stmt,
'alter table ' || cl2.relname || ' add constraint ' || conname
|| ' foreign key (' || att2.attname || ') references ' || cl.relname
|| ' on update cascade deferrable initially deferred;' as create_stmt
@izmailoff
izmailoff / git-submodules.md
Created February 17, 2021 07:21 — forked from slavafomin/git-submodules.md
Git submodules best practices

Git submodules best practices

Useful commands

— Clone repository with submodules automatically:

git clone --recursive [email protected]:name/repo.git

— Initialize submodules after regular cloning:

@izmailoff
izmailoff / git_mergetool_setup.sh
Created April 8, 2020 02:27
git mergetool setup
sudo apt-get update
sudo apt-get install kdiff3
git config --global --add merge.tool kdiff3
git config --global --add mergetool.kdiff3.path "/usr/bin/kdiff3"
git config --global --add mergetool.kdiff3.trustExitCode false
git config --global --add mergetool.prompt false
git config --global --add diff.guitool kdiff3
git config --global --add difftool.kdiff3.path "/usr/bin/kdiff3"
@izmailoff
izmailoff / count_documents.sh
Created March 3, 2020 06:13
Count MongoDB documents in all collections
#!/bin/bash
db_name="$1"
if [ -z "$db_name" ]; then
echo "Usage: $0 <db_name or uri>"
exit 1
else
echo "Collections in db: $db_name."
@izmailoff
izmailoff / postgres_stats.sql
Created February 24, 2020 06:41
Postgres DB stats
-- analyze DB for more precise stats
VACUUM (FULL, ANALYZE);
-- get row counts for all tables (option 1)
SELECT
nspname AS schemaname,relname,reltuples
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE
nspname NOT IN ('pg_catalog', 'information_schema') AND
@izmailoff
izmailoff / README.md
Created January 22, 2020 03:45 — forked from genomics-geek/README.md
Setting up a Dockerized web application with Django REST APIs, ReactJS with Redux pattern, and Webpack Hot Reloading! Mouthful.

Guide on how to create and set up a Dockerized web app using Django REST APIs and ReactJS

Hopefully this will answer "How do I setup or start a Django project using REST Framework and ReactJS?"

This is a guide to show you step by step how this can be setup. If you just want to get started, use the cookiecuter I set up cookiecutter-django-reactjs. It basically is a fork of pydanny's cookiecutter, just added the front-end stuff :).

I created this because it was SUCH a pain in the ass setting up a project using all the latest technologies. After some research, I figured it out and have it working. The repo that implements this is located here. Feel free to use it as a boilerplate ;)

Main features:

  • Django REST APIs
@izmailoff
izmailoff / list_all_tables_columns_only.sh
Created December 27, 2019 09:38
Grab all table columns only without any additional information from postgres. Ugly but works for me.
#!/bin/bash
for t in $(echo '\dt' | psql "$1" | cut -d '|' -f 2 | egrep -v 'List|Name|--|\(')
do echo "TABLE: $t"
echo "\d $t" | psql "$1" | grep '|' | egrep -v Column | cut -d '|' -f 1
echo
done
@izmailoff
izmailoff / latest_docs.js
Created November 27, 2019 05:42
Mongo shell script to get latest docs in each collection
var cols = db.getCollectionNames();
cols.forEach(x => {
var res = db[x].find({}).sort({_id: -1}).limit(3);
print(x + ": ");
res.forEach(x => print(x._id + " is " + x._id.getTimestamp()));
print();
}
);
@izmailoff
izmailoff / ffmpeg_json_meta.sh
Created November 2, 2019 03:32
get video file info from linux shell (ffmpeg stuff)
ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json some.mp4
{
"programs": [
],
"streams": [
{
"index": 0,
"codec_name": "h264",