Skip to content

Instantly share code, notes, and snippets.

View ansrivas's full-sized avatar

Ankur Srivastava ansrivas

View GitHub Profile
Git global setup
git config --global user.name "Ankur Srivastava"
git config --global user.email "ankur.srivastava@recogizer.de"
Create a new repository
git clone git@gitlab.recogizer.net:PlatformOps/log-platform.git
cd log-platform
touch README.md
@ansrivas
ansrivas / docker.sh
Created November 26, 2017 23:43
Fedora docker post steps
$ sudo groupadd docker && sudo gpasswd -a ${USER} docker && sudo systemctl restart docker
$ newgrp docker
@ansrivas
ansrivas / Makefile
Created November 16, 2017 23:09 — forked from mcastilho/Makefile
Makefile for Medium article
.PHONY: all tags clean test build install generate image release
REGISTRY_REPO = <..redacted..>
OK_COLOR=\033[32;01m
NO_COLOR=\033[0m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m
# Build Flags
@ansrivas
ansrivas / main.go
Created November 13, 2017 16:35
csrf template validation using pongo2, chi and gorilla/csrf
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
@ansrivas
ansrivas / server.py
Created November 6, 2017 10:55
in memory caching with a ttl using aiohttp and aiocache
from datetime import datetime
from aiohttp import web
from aiocache import cached
from aiocache.serializers import JsonSerializer
@cached(key="my_custom_key", serializer=JsonSerializer(), ttl=5)
async def time():
return {"time": datetime.now().isoformat()}
@ansrivas
ansrivas / subprocess_aiohttp.py
Last active January 25, 2018 19:16
asyncio subprocess with aiohttp
# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""Initialize module utils."""
import asyncio
from aiohttp import web
class Operations(web.View):
"""."""
@ansrivas
ansrivas / set_ips.sh
Created October 28, 2017 22:04
get/set external IP
export EXTERNAL_IP=$(ifconfig eth0 | grep 'inet addr' | awk '{print $2}'| sed "s/addr://g")
export INTERNAL_IP=$(ifconfig eth1 | grep 'inet addr' | awk '{print $2}'| sed "s/addr://g")
@ansrivas
ansrivas / permissions.md
Last active October 25, 2017 10:50
ssh key permissions
1. .ssh directory permissions to be 700 (drwx------) 
2. public key (.pub file) to be 644 (-rw-r--r--)
3. private key (id_rsa) should be 600 (-rw-------)
4. Lastly, your home directory should not be writeable by the group or others (at most 755 (drwxr-xr-x)).
chmod 700 ~/.ssh
chmod 644 ~/.ssh/id_rsa.pub
@ansrivas
ansrivas / python_tips.md
Last active October 7, 2017 23:20
Python tips and tricks
  1. Concatenating a series of lists has quadratic performance. Use itertools.chain() or chain.from_iterable() instead.
  2. With #python iterators, we think of next() as initiating execution. With coroutines, we "await" a downstream event to initiate execution.
  3. Adding %(filename)s and %(lineno)d to the logging format makes it easier to see where log messages came from.
  4. The matrix multiplication operator "@" has the same precedence as multiplication, division, floor division, and remainder.
@ansrivas
ansrivas / encodings.md
Last active March 17, 2022 21:09
Convert iso-8859-1 to utf-8 in python
# convert iso-8859-1 to unicode to utf-8, where `v` is the string in `iso-8859-1` format
v.decode("iso-8859-1").encode("utf-8")

And as a note, this is also some basic rule:

If you have no way of finding out the correct encoding of the file, then try the following encodings, in this order:

utf-8
iso-8859-1 (also known as latin-1)