Skip to content

Instantly share code, notes, and snippets.

View aahnik's full-sized avatar
🏠
something's happening!

Aahnik Daw aahnik

🏠
something's happening!
View GitHub Profile
# General Term (x ** power)/factorial(power)
# where power ranges from 0 to n-1 if the series has n terms
def factorial(num):
# recursive function
if num == 0:
# base case
return 1
else:
return num * factorial(num - 1)
# aahnik 2020
def recursive_binary_search(arr, lo, hi, ele):
# Returns index of ele in arr if present, else -1
# arr is our list
# lo is lower/left pointer
# hi is higher/right pointer
# ele is element to search
if hi >= lo:
# possibility that ele exists
@aahnik
aahnik / sum_of_n_natural_numbers_for_loop.py
Last active September 14, 2020 12:20
sum of n natural numbers for loop python
def sum(n):
s = 0
for i in range(1,n+1):
s += n
print(s)
sum(10)# would print 55
def sum(n):
if n == 1:
return 1
else:
return n + sum(n+1)
def power(a,b):
if b == 0:
return 1
else:
return power(a,b-1) * a
@aahnik
aahnik / ui_desc.txt
Last active November 1, 2020 12:19
Description for Unscripted Impulse ui desc aahnik daw description
Unscripted Impulse is a podcast of conversations between two friends Aahnik and Navoneel
on various topics ranging from Science to History to fiction to Literature
to JEE to Coding to Consciousness to Evolution to Indology to Everything about Existence and Reality ...
I am Aahnik: ;FreeThinkerSeekerYogi, I ❤️ CODING ; PHYSICS ; MATH, astikaAtheist, FollowingDharma, NoReligion
Visit my Website: https://aahnik.github.io
Read my articles on Medium: https://medium.com/@aahnik
Twitter: https://twitter.com/AahnikD
Facebook: https://www.facebook.com/aahnik.daw
@aahnik
aahnik / toGIF.md
Last active November 10, 2020 07:09
Ubuntu records 30s .webm screencasts in Videos Folder via Ctrl+Shift+Alt+R, automatically convert them to GIF in Pictures Folder, and delete video file

Make GIF ScreenCasts of 30s

Ubuntu records 30s .webm screencasts in Videos Folder via Ctrl+Shift+Alt+R, automatically convert them to GIF in Pictures Folder, and delete video file

Make sure to have ffmpeg installed

  • Save the toGIF.sh in your Videos folder, link
  • make it executable chmod +x ~/Videos/toGIF.sh
  • Go to Settings ---> Keyboard Shortcuts ---> New ShortCut
  • Set a new shortcut like this
@aahnik
aahnik / sample_code_selenium_using_user_data_dir.py
Last active November 11, 2020 17:57
Using user data dir in selenium. Using a session. Reuse saved cookies. sample_code_selenium_using_user_data_dir.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
session_path = 'path/of/folder/'
chrome_driver_path = 'path/of/chrome-driver-executable'
url = 'url'
chrome_options = Options()
chrome_options.add_argument(f'--user-data-dir={session_path}')
@aahnik
aahnik / asynchronous.py
Created November 16, 2020 11:35
Jai shree async ... Showing the power of async. ( Idea from https://youtu.be/R4Oz8JUuM4s )
import aiohttp
import asyncio
from timer import timer
async def fetch():
base = 'https://httpbin.org/get'
async with aiohttp.ClientSession() as session:
async with session.get(url=base) as response:
@aahnik
aahnik / #tg_conv_bot.md
Last active August 6, 2023 18:31
A simple conversation bot that will ask user's name, and save it. Persistent, Polling, Shows Button, Has conversation flow, Conversation Handler, python-telegram-bot, ptb,

How to run

  1. Install dependancies.
pip3 install python-dotenv python-telegram-bot
  1. Then put the files of this gist inside a folder.