Skip to content

Instantly share code, notes, and snippets.

View kodekracker's full-sized avatar
🎯
Focusing

Akshay Pratap Singh kodekracker

🎯
Focusing
View GitHub Profile
@kodekracker
kodekracker / source_script.sh
Created April 2, 2020 09:43
A script can be only source and cannot be run it directly
# source scource_script.sh
if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi
# To create an new virtual environment of python and activate it
mkvirtualenv() {
virtualenv $1 && source $1/bin/activate
}
# To create a new directory and check-in to it
mkdircd() {
mkdir -p "$@" && eval cd "\"\$$#\"";
}
# aliases for system
alias zshconfig="vim ~/.zshrc"
alias zshsr="source ~/.zshrc"
alias addppa="sudo add-apt-repository"
alias rmppa="sudo ppa-purge"
alias update="sudo apt update"
alias upgradable="sudo apt list --upgradable"
alias upgrade="sudo apt upgrade"
alias install="sudo apt install"
alias uninstall="sudo apt purge"
@kodekracker
kodekracker / install_r_ubuntu.sh
Last active March 2, 2020 08:33
Install R in ubuntu 14.04 or later (16.04, 18.04, 19.04, 19.10)
#!/usr/bin/env bash
# Behind a firewall some users may receive error [ gpg: keyserver receive failed: Server indicated a failure ]
# That's why we are using port 80 instead of the default port 11371
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -sc)-cran35/" -y
sudo apt update
sudo apt install r-base -y
@kodekracker
kodekracker / read-access.sql
Created January 28, 2020 04:36 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@kodekracker
kodekracker / response_status_code_throttle.py
Last active January 10, 2020 08:26
A django rest framework (DRF) throttle limits the rate of API calls that may be made by an anonymous or authenticated user based on response status code
from rest_framework.throttling import SimpleRateThrottle
import functools
class ResponseStatusCodeThrottle(SimpleRateThrottle):
"""
Limits the rate of API calls that may be made by an anonymous or
authenticated user based on response status code.Any view that has the
`throttle_scope` property set will be throttled. The unique cache
key will be generated by concatenating the user id of the request,
@kodekracker
kodekracker / nginx.conf
Created December 30, 2019 06:58 — forked from v0lkan/nginx.conf
Configuring NGINX for Maximum Throughput Under High Concurrency
user web;
# One worker process per CPU core.
worker_processes 8;
# Also set
# /etc/security/limits.conf
# web soft nofile 65535
# web hard nofile 65535
# /etc/default/nginx
@kodekracker
kodekracker / detect_os_and_distribution.sh
Created December 13, 2019 07:24
Shell script for detecting linux OS and distribution
#!/bin/bash
detect_os ()
{
if [[ ( -z "${os}" ) && ( -z "${dist}" ) ]]; then
# some systems dont have lsb-release yet have the lsb_release binary and
# vice-versa
if [ -e /etc/lsb-release ]; then
. /etc/lsb-release

Install dlib and face_recognition on a Raspberry Pi

Instructions tested with a Raspberry Pi 2 with an 8GB memory card. Probably also works fine on a Raspberry Pi 3.

Steps

Download the latest Raspbian Jessie Light image. Earlier versions of Raspbian won't work.

Write it to a memory card using Etcher, put the memory card in the RPi and boot it up.

@kodekracker
kodekracker / all_countries_info.json
Last active December 13, 2019 06:10
Country Information(name, two character code, calling codes, mobile number NSN(National Significant Number) digits length,flag, time zones) . This is created by using https://restcountries.eu/ , https://github.com/manuelmhtr/countries-and-timezones and wikipedia information.
[
{
"name": "Afghanistan",
"alpha2Code": "AF",
"callingCodes": [
"93"
],
"mobile_number_nsn_digits":{
"min": 9,
"max": 9