Skip to content

Instantly share code, notes, and snippets.

View sumit2312's full-sized avatar
:octocat:
Focusing

Sumit Kumar sumit2312

:octocat:
Focusing
View GitHub Profile
#!/usr/bin/env python
### Import required python libraries
import os
import time
import shutil
from boto.s3.connection import S3Connection
from boto.s3.key import Key
@sumit2312
sumit2312 / auth.py
Created January 3, 2022 12:55 — forked from ibeex/auth.py
Python LDAP (ActiveDirectory) authentication
import ldap
def check_credentials(username, password):
"""Verifies credentials for username and password.
Returns None on success or a string describing the error on failure
# Adapt to your needs
"""
LDAP_SERVER = 'ldap://xxx'
# fully qualified AD user name
LDAP_USERNAME = '%s@xxx.xx' % username

drf-cheat-sheet

A collection of anything from basics to advanced recommended methods and usages with Django REST Framework for creating browsable and awesome web API's. This could also serve as a quick reference guide.

Here is DRF's official documentation in case you need everything in detail.

Why Django REST Framework?

Summarized from the official docs:

  • Web browsable API
  • Serialization that supports ORM and non-ORM data sources.
import cv2
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from math import log10, sqrt
img = cv2.imread('original_boat_img.gif')
import numpy as np
import cv2
def sp_noise(image, prob):
'''
Add salt and pepper noise to image
prob: Probability of the noise
'''
output = image.copy()
Task 1: Create a project jumphost instance
Navigation menu > Compute engine > VM Instance
Task 2: Create a Kubernetes service cluster
gcloud config set compute/zone us-east1-b
gcloud container clusters create nucleus-webserver1
// We can use stl container list as a double
// ended queue to store the cache keys, with
// the descending time of reference from front
// to back and a set container to check presence
// of a key. But to fetch the address of the key
// in the list using find(), it takes O(N) time.
// This can be optimized by storing a reference
// (iterator) to each key in a hash map.
#include <bits/stdc++.h>
using namespace std;
// https://leetcode.com/problems/implement-trie-prefix-tree/
class Trie {
struct Trienode
{
char val;
int count;
int endsHere;
Trienode *child[26];
};
Trienode *root;
@sumit2312
sumit2312 / preSucc.java
Created June 26, 2020 17:44 — forked from anil477/preSucc.java
Inorder predecessor and successor for a given key in BST
// http://www.geeksforgeeks.org/inorder-predecessor-successor-given-key-bst/
// http://code.geeksforgeeks.org/NvtCcP
Input: root node, key
output: predecessor node, successor node
/*
1. If root is NULL
then return
2. if key is found then
a. If its left subtree is not null
Then predecessor will be the right most