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
@aahnik
aahnik / limited_length_dict.py
Created January 2, 2021 22:36
When you just want to keep the last n added values to a dictionary. Python
var = {}
count = 1
limit = 10
while True:
data = input('enter data ')
var.update({count:data})
@aahnik
aahnik / searchy.py
Created December 13, 2020 06:06
Search a substring in a list of strings;Python | Finding strings with given substring in list;search a query in a list of strings;re;list comprehension;filter;lambda;re.search
# search a query in a list of strings
import re
my_list = ['Horrible donkey', 'irritable monkey', 'international idiot']
search_for = 'd'
# list comprehension
@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.
@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 / 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 / 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 / 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
def power(a,b):
if b == 0:
return 1
else:
return power(a,b-1) * a
def sum(n):
if n == 1:
return 1
else:
return n + sum(n+1)
@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