Skip to content

Instantly share code, notes, and snippets.

View ak9999's full-sized avatar
🎯
Focusing

Abdullah "AJ" Khan ak9999

🎯
Focusing
  • New York
View GitHub Profile
@ak9999
ak9999 / missing_number.py
Created January 2, 2022 02:25
Missing number problem from Leetcode
# https://leetcode.com/problems/missing-number/
import random
def generate_input_array(n: int) -> list:
if not (1 <= n <= 104):
raise ValueError('Given `n` does not fulfill 1 <= n <= 104')
nums = list()
while len(nums) != n:
temp = random.randint(0, n)
@ak9999
ak9999 / absolute-to-canonical-paths.py
Created January 2, 2022 02:18
Leetcode problems I did in February 2021
# Link: https://leetcode.com/explore/challenge/card/february-leetcoding-challenge-2021/584/week-1-february-1st-february-7th/3629/
# Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path.
# In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e. '//') are treated as a single slash '/'. For this problem, any other format of periods such as '...' are treated as file/directory names.
# The canonical path should have the following format:
# The path starts with a single slash '/'.
# Any two directories are separated by a single slash '/'.
# The path does not end with a trailing '/'.
@ak9999
ak9999 / const_demo.cpp
Created January 2, 2022 02:15
Demo on using `const`.
#include <iostream>
static int outside_variable{0};
class Demo {
int val;
public:
static const int inside{1};
Demo(int v = 0) {
val = v;
@ak9999
ak9999 / two_sum.py
Created May 12, 2021 23:21
Two Sum Problem Solution
from typing import List
class Solution:
def binary_search(self, container: List[int], key):
low = 0
high = len(container) - 1
while (low <= high):
middle = (low + high) >> 1
middle_value = container[middle]
if middle_value < key:
@ak9999
ak9999 / leetcode_problem.txt
Last active March 5, 2021 02:26
Mob programming solutions to the Ransom Note problem from Leetcode: https://leetcode.com/problems/ransom-note/
Link: https://leetcode.com/problems/ransom-note/
Given an arbitrary ransom note string and another string containing letters from all the magazines,
write a function that will return true if the ransom note can be constructed from the magazines;
otherwise, it will return false.
Each letter in the magazine string can only be used once in your ransom note.
Example 1:
Input: ransomNote = "a", magazine = "b"
@ak9999
ak9999 / missing_number.py
Created January 30, 2021 01:35
My answer to the missing number problem on Leetcode
# https://leetcode.com/problems/missing-number/
import random
def generate_input_array(n: int) -> list:
if not (1 <= n <= 104):
raise ValueError('Given `n` does not fulfill 1 <= n <= 104')
nums = list()
while len(nums) != n:
temp = random.randint(0, n)
@ak9999
ak9999 / NYCPythonVSCodeLiveShare.Dockerfile
Created December 21, 2020 03:21
Dockerfile for pair programming at NYC Python
# Live Share image built from official Python image
FROM python:slim
# Create a new user, dev
RUN useradd --create-home --shell /bin/bash dev
# Give dev a password
RUN echo 'dev:secret' | chpasswd
# Add dev to sudo group
RUN usermod -a -G sudo dev
# Update package list and install packages
RUN apt-get update
@ak9999
ak9999 / Get Recovery Keys.ps1
Created February 7, 2020 13:48
Retrieve BitLocker Recovery Keys From Active Directory
# Generate Report of BitLocker Status for Computers in the BitLocker Machines OU.
# Sources: https://4sysops.com/archives/find-bitlocker-recovery-passwords-in-active-directory-with-powershell/
param([string]$OutputDirectory="~/Desktop",[string]$OrganizationalUnit=([adsi]'').distinguishedName)
if(!([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent() `
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host -ForegroundColor Yellow "Only Administrators can read BitLocker Recovery Keys."
exit
}
$computers = Get-ADComputer -Filter * -SearchBase $OrganizationalUnit
# Generate Report of BitLocker Status for Computers in the BitLocker Machines OU.
param([string]$OutputDirectory="~/Desktop",[string]$OrganizationalUnit=([adsi]'').distinguishedName)
if(!([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent() `
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host -ForegroundColor Yellow "Only Administrators can read BitLocker Recovery Keys."
exit
}
$computers = Get-ADComputer -Filter * -SearchBase $OrganizationalUnit
$results = ForEach ($computer in $computers) {
@ak9999
ak9999 / Dockerfile
Created February 6, 2020 01:09
Here's a dummy docker file. Assume this is in a top level folder that has some folder called `contained` with an __init__.py in there that runs the app.
FROM python:3.7-slim
COPY contained /src/app/contained
WORKDIR /src/app
RUN pip install Flask
ENV FLASK_APP contained
CMD ["flask", "run", "--host=0.0.0.0"]