Skip to content

Instantly share code, notes, and snippets.

@lokesh1729
lokesh1729 / base62_encode.py
Last active July 17, 2019 05:41
#python #url #shortid #short #base62 #base64
BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
def encode(num, alphabet=BASE62):
"""Encode a positive number in Base X
Arguments:
- `num`: The number to encode
- `alphabet`: The alphabet to use for encoding
"""
if num == 0:
@lokesh1729
lokesh1729 / prettier-eslint-react-config
Last active July 2, 2019 07:03
#prettier #eslint config for #react
# package.json
{
"devDependencies": {
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^5.0.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-react": "^7.14.1",
"husky": "^2.5.0",
"lint-staged": "^8.2.1",
"prettier": "^1.18.2",
@lokesh1729
lokesh1729 / threading_requests.py
Last active July 2, 2019 07:07
#threading #python
import concurrent.futures
import json
import time
import requests
URLS = [
"https://reqres.in/api/users",
"http://dummy.restapiexample.com/api/v1/employees",
# "https://jsonplaceholder.typicode.com/todos",
# "https://jsonplaceholder.typicode.com/posts",
import asyncio
import json
import time
import aiohttp
result = []
async def download_site(session, url):
@lokesh1729
lokesh1729 / producer_consumer.py
Created May 16, 2019 09:09
Producer Consumer
import concurrent.futures
import logging
import random
import threading
SENTINEL = object()
@lokesh1729
lokesh1729 / get_nested_values_from_dict.py
Created March 26, 2019 10:42
Get Nested Values from dict
def get_nested_values_from_dict(data, attrs, index=0):
"""
get values from nested dictionary
Example:
>>> data = {"a": {"b": {"c": 3}}
>>> get_nested_values_from_dict(data, ["a", "b", "c"])
>>> 3
:param data: dict
:param attrs: list
:param index: int
import java.util.HashMap;
import java.util.Scanner;
public class QHEAP1 {
private static int count = 1;
private static MinimumHeap<Integer> root = null;
HashMap<Integer,Integer> h = new HashMap<>();
public static void main(String args[]) {
long startTime = System.currentTimeMillis();
Scanner sc = new Scanner(System.in);