Skip to content

Instantly share code, notes, and snippets.

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);
@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
@lokesh1729
lokesh1729 / producer_consumer.py
Created May 16, 2019 09:09
Producer Consumer
import concurrent.futures
import logging
import random
import threading
SENTINEL = object()
import asyncio
import json
import time
import aiohttp
result = []
async def download_site(session, url):
@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",
@lokesh1729
lokesh1729 / divide_array_sub_arrays_v1.py
Created July 10, 2019 07:30
divide an array into contiguous k sub arrays
def divide(data, n_column=3):
result = []
cur_index = 0
n = len(data)
while cur_index < n/n_column:
result.append(data[cur_index*n_column: (cur_index+1)*n_column])
cur_index += 1
if n%n_column != 0:
result.append(data[cur_index*n_column: (cur_index+1)*n_column])
return result
@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 / get_starting_date_minus_n_months.py
Last active October 31, 2019 12:20
This function returns the datetime object by substracting n months (time won't change) #python
def get_starting_date_minus_n_months(curr_date, num_months):
"""
Given the curr_date (datetime) object and num_months, returns the starting date
minus "num_months" months. Note that time won't change
for example: curr_date is "2019-10-22 23:59:59" and num_months is 3
it returns "2019-07-01 23:59:59"
"""
if num_months < 0:
raise ValueError(
@lokesh1729
lokesh1729 / my first webpack config.js
Created May 12, 2020 14:29
yahoooo!!! my first webpack config working fine :)
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
module.exports = ({ mode, presets } = { mode: "production", presets: [] }) => ({
devtool: "eval-cheap-module-source-map",