Skip to content

Instantly share code, notes, and snippets.

View sleebapaul's full-sized avatar
🏃‍♂️
Sprinting

Sleeba Paul sleebapaul

🏃‍♂️
Sprinting
View GitHub Profile
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.Completion.create(
model="text-davinci-002",
prompt="A bot that creates haikus. A haiku is a three or four lines short poem
which can be written in various contexts like life, philosophy, politics, current affairs,
life lessons, deep thinking, beauty, success, failure and many others.
@sleebapaul
sleebapaul / adventuresWithTries.py
Created February 9, 2020 18:33
Adventures with Trie data structure
class Node():
def __init__(self, character):
self.letter = character
self.isEndOfWord = False
self.children = {}
class Trie:
def __init__(self):
"""
Initialize an empty Node as root.
@sleebapaul
sleebapaul / binarySearchTree.py
Last active June 30, 2020 10:42
Arsenal for Binary Search Tree Adventures
class Node():
"""
Basic component of a Tree is a Node
"""
def __init__(self, value):
self.value = value
self.left = None
self.right = None
@sleebapaul
sleebapaul / bitwise_operations.py
Last active December 25, 2019 17:28
Bitwise operations using Python
def set_bit(x, pos):
"""
First create a mask which has 1 in the required position and everywhere else is 0
Then do bitwise OR that will the set 1 in the position
"""
mask = 1 << pos
return x | mask
def clear_bit(x, pos):
"""
@sleebapaul
sleebapaul / binary_search.py
Last active January 11, 2020 06:01
Binary Search using Python
def binary_search(a_list, search_item):
"""
Binary search using loop on a sorted list
Based on the value we look for, bifurcate the list into two look up windows.
The value we look for is the middle value of current window.
If search value < middle value of the window, put the upper bound to middle value
If search value > middle value of the window, put the lower bound to middle value
@sleebapaul
sleebapaul / queue_using_linked_list.py
Created December 20, 2019 03:25
Implementation of Queue using Linked List
class Node(object):
"""
Fundamental building block of a linked list
A node consists of a value and the next node location pointer
"""
def __init__(self, value):
self.val = value
self.next = None
@sleebapaul
sleebapaul / stack_using_linked_list.py
Last active December 20, 2019 03:17
Implementation of Stack using Linked List
class Node(object):
"""
Fundamental building block of a linked list
A node consists of a value and the next node location pointer
"""
def __init__(self, value):
self.val = value
self.next = None
@sleebapaul
sleebapaul / single_linked_list_ops.py
Last active February 19, 2020 17:32
(Almost) everything you need for your Single Linked List adventures
class Node():
"""
Basic component for single linked list - A node
A node consist of a value and a pointer to another node
"""
def __init__(self, data):
self.val = data
self.next = None
@sleebapaul
sleebapaul / simple_language_model.py
Created June 1, 2018 17:53
The simplest character level language model using random picking of characters from a dictionary
import random
import string
from string import punctuation
# Get all the alphabets
alphabetsList = list(string.ascii_letters)
# Get all the punctuations
punctuationList = list(punctuation)
@sleebapaul
sleebapaul / commands
Last active March 16, 2023 06:55
FFMPEG commandline tool for video streaming and format conversion
// To start ffserver
ffserver -f /etc/ffserver.conf
// re stream incoming to ffsever
ffmpeg -rtsp_transport tcp -i "rtsp://admin:admin@65.254.18.55:7314/live/N4NXL/1/2" http://localhost:8090/camera.ffm
// configuration file