Skip to content

Instantly share code, notes, and snippets.

View rdwns's full-sized avatar
🤓

Ridwan Ul Haq rdwns

🤓
View GitHub Profile
# Specify the provider (GCP) and the version of the API
provider "google" {
version = "~> 2.15"
}
# Configure the GCP project and authentication details
# Replace <PROJECT_ID> and <SERVICE_ACCOUNT_KEY> with your own values
variable "project_id" {
default = "<PROJECT_ID>"
@rdwns
rdwns / installdocker.sh
Last active June 30, 2020 19:31
shell script to install docker
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
#!/usr/bin/env python3
import sys, webbrowser, pyperclip
if len(sys.argv) > 1:
address = ' '.join(sys.argv[1:])
else:
address = pyperclip.paste()
webbrowser.open(f'https://google.com/maps/place/{address}')
@rdwns
rdwns / multi-clipboard.py
Last active June 9, 2020 10:41
A python clipboard that holds multiple entries
import sys, pyperclip, shelve, json
mcbShelf = shelve.open('mcb')
#SaveClipBoardContent
if len(sys.argv) == 3 and sys.argv[1].lower() == 'save':
print(f'"{pyperclip.paste()}" saved in the multi clipboard!')
@rdwns
rdwns / date_extract.py
Created June 7, 2020 17:35
Extracts Dates from copied text and outputs them in DD-MM-YYYY
import re, pyperclip
def extract_date(date):
valid_dates = []
invalid_dates = []
for i in date:
day = i[0]
@rdwns
rdwns / printTable.py
Created June 5, 2020 11:49
To print nested lists in columns
def printTable(tableData):
colWidth = [0] * len(tableData) #create a list with columns equal to the number of nested lists
numCols = 0
numRows = 0
for lists in range(len(tableData)):
longest_string = max(tableData[lists], key=len) #find the longest string in each of the lists
colWidth[lists] = len(longest_string)
numRows = len(tableData[lists]) #this is a bottleneck of the script, it stores the length of the last nested list, so if previous lists have less number of elements, an error is thrown
@rdwns
rdwns / comma_code.py
Last active May 31, 2020 13:16
Function that takes a list as argument and returns a string with all items seperated by a comma and a space, with and inserted before the last item
def lstfunc(lst):
#Seperate the list into two parts, firstpart goes from first element to the second last element
#lastpart covers the penultimate and the ultimate part of the list
#use map() to convert all values to strings otherwise it will throw errors on int items
firstpart = map(str,lst[:-2])
lastpart = map(str, lst[-2:])
#join the list elements with ', ' and end with ', ' to cover the last item of the firstpart
print(', '.join(firstpart), end=', ')
print(' and '.join(lastpart))
@rdwns
rdwns / graph2.c
Last active December 1, 2017 02:07
Graph in C v2
#include <stdio.h>
#include <stdlib.h>
void BFS(int src);
void DFS(int n, int s[10]);
int a[10][10], n,i,j;
void main()
{
@rdwns
rdwns / infix-postfix.c
Created November 30, 2017 14:22
Infix to Postfix Conversion
#define SIZE 50
#include <stdio.h>
#include <ctype.h>
char stack[SIZE];
int top=-1;
push(char elem)
{
stack[++top]=elem;