Skip to content

Instantly share code, notes, and snippets.

View Hemanthkumar2112's full-sized avatar

Hemanth Kumar M Hemanthkumar2112

View GitHub Profile
@Hemanthkumar2112
Hemanthkumar2112 / django POST
Created August 10, 2021 08:49 — forked from gerhc/django POST
AJAX POST
xhr = new XMLHttpRequest();
xhr.open("POST", "add_specs/", false);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
data = JSON.stringify(spec_rows);
xhr.send(data);
@Hemanthkumar2112
Hemanthkumar2112 / remove duplicate within a list.py
Created July 3, 2021 13:52
remove duplicate within a list
def removeDuplicates(self, nums:List[int]) -> int:
nums.sort()
for i in nums:
while nums.count(i)>1:
nums.remove(i)
print(nums)
@Hemanthkumar2112
Hemanthkumar2112 / recursive_binary_search.py
Last active July 1, 2021 14:34
binary search in recursive [o(logn)]
def binary_search(a:list,target:int)->str: ##found, notfound
if len(a)==0:return "NOT FOUND"
a.sort()
mid = len(a)//2
if a[mid]== target:return "FOUND"
else:
if a[mid] < target:return binary_search_re(a[mid+1:],target)
if a[mid] > target:return binary_search_re(a[:mid],target)