Skip to content

Instantly share code, notes, and snippets.

View userimack's full-sized avatar

Mahendra Yadav userimack

View GitHub Profile
@userimack
userimack / bashrc_git_helper_functions
Created March 10, 2019 11:37
bash functions to create commits with emoji in git
#.# Better Git Logs.
### Using EMOJI-LOG (https://github.com/ahmadawais/Emoji-Log).
# Git Commit, Add all and Push — in one step.
function gcap() {
git add . && git commit -m "$*" && git push
}
# NEW.
function gnew() {
@userimack
userimack / gitconfig
Created March 10, 2019 11:35
gitconfig for writing emoji commit messages
# Git Commit, Add all and Push — in one step.
cap = "!f() { git add .; git commit -m \"$@\"; git push; }; f"
# NEW.
new = "!f() { git cap \"📦 NEW: $@\"; }; f"
# IMPROVE.
imp = "!f() { git cap \"👌 IMPROVE: $@\"; }; f"
# FIX.
fix = "!f() { git cap \"🐛 FIX: $@\"; }; f"
# RELEASE.
"""
# Proto message
service {
rpc GetTodo(Todo) returns (Todo) {}
}
message Todo {
int64 id = 1;
string text = 2;
}
@userimack
userimack / django_log_settings.py
Created March 13, 2018 10:41
Django logging settings, tested with version 1.11
# Logging settings for django projects, works with django 1.5+
# If DEBUG=True, all logs (including django logs) will be
# written to console and to debug_file.
# If DEBUG=False, logs with level INFO or higher will be
# saved to production_file.
# Logging usage described below:
# import logging
# logger = logging.getLogger(__name__)
# logger.info("Log this message")
@userimack
userimack / postgres_queries_and_commands.sql
Created February 23, 2018 10:05 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@userimack
userimack / .gitignore
Created February 14, 2018 04:35
A gitignore file for Python/Django projects
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@userimack
userimack / group_lectures_together.py
Last active February 12, 2018 11:59
A script to chnage the filename of my videos and group them by lectures
# find -name "* *" -type f | rename 's/ /_/g' # to remove spaces in the directory
import glob
import os
import shutil
lectures_string = """\nSection: 1 0 / 5\nWelcome to Try Django 1.11\n\n 1. Welcome to Try Django 1.11 3:53\n 2. Walkthrough 3:51\n 3. Getting Started with Django 24:08\n 4. For your Reference 2:36\n 5. What Django Does 10:35\n\nSection: 2 0 / 8\nHTML & Django\n\n 6. Rendering HTML 4:44\n 7. Render a Django Template 9:13\n 8. Context in Django Templates 9:17\n 9. Template Inheritance 13:59\n 10. Include Template Tag 6:04\n 11. Reactivate Virtualenv 1:10\n 12. Class Based Views 8:26\n 13. Template View 7:29\n\nSection: 3 0 / 8\nRemembering Things\n\n 14. Remembering things with Models 11:03\n 15. More on Model Fields 8:59\n 16. Displaying Saved Data 9:47\n 17. Understanding QuerySets 9:14\n 18. Generic List View 8:58\n 19. Restaurant Profile Detail 10:15\n 20. SlugField & Unique Slug Generator 7:01\n 21. Signal for Unique Slug 6:3
@userimack
userimack / Verify_two_dicts.py
Created October 25, 2017 06:40
Verify names of two dicts dict1 and dict2. It will verify if the names doesn't match properly in lower case. It deletes the line "Press Enter to continue..." :)
# LANGUAGE: Python3
# AUTHOR: Mahendra Yadav
CURSOR_UP = '\033[F'
ERASE_LINE = '\033[K'
prinnt("Length of dict1 = {}".format(len(dict1)))
prinnt("Length of dict2 = {}".format(len(dict2)))
# To find the difference between the keys use dict1.keys() - dict2.keys()
for key in dict1:
print(key)
@userimack
userimack / getting_started_guide.txt
Last active February 16, 2024 11:11
Steps to set up airflow
1. Setting up virtualenv
virtualenv env
2. activate it using:
source ./env/bin/activate
3. pip install airflow # will install airflow version 1.8 to use latest one use: pip install apache-airflow
4. Add "export AIRFLOW_HOME=~/<directory>" to your bashrc/zshrc
echo "export AIRFLOW_HOME=/home/mahendra/pyconf/app_airflow" >> .zshrc
@userimack
userimack / download_data.py
Created October 8, 2017 04:23
DAG script for downloading script.
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.python_operator import PythonOperator
from airflow.operators.email_operator import EmailOperator
from datetime import timedelta, datetime
from airflow.models import Variable
import xml.etree.ElementTree as ET
import glob
default_args = {