Skip to content

Instantly share code, notes, and snippets.

View harshildarji's full-sized avatar

Harshil harshildarji

View GitHub Profile
@harshildarji
harshildarji / q_learning_intro.py
Created August 29, 2019 11:12
Q-Learning Intro
# Tutorial links:
# https://youtu.be/yMk_XtIEzH8?list=PLQVvvaa0QuDezJFIOU5wDdfy4e9vdnx-7
# https://youtu.be/Gq1Azv_B4-4?list=PLQVvvaa0QuDezJFIOU5wDdfy4e9vdnx-7
# https://youtu.be/CBTbifYx6a8?list=PLQVvvaa0QuDezJFIOU5wDdfy4e9vdnx-7
import gym
import numpy as np
import matplotlib.pyplot as plt
env = gym.make('MountainCar-v0')
@harshildarji
harshildarji / convert.py
Last active August 29, 2019 11:18
Convert GloVe to Gensim Word2Vec
# Usage: python convert.py glove_model.txt
import sys
import time
def file_len(fname):
line = col = 0
with open(fname, encoding = 'UTF-8') as f:
for line, l in enumerate(f):
if col == 0:
@harshildarji
harshildarji / professor_boolean_workforce.py
Created December 10, 2018 19:00
Find the total number of people in Prof. Boolean's workforce.
'''
Professor Boolean is an evil villain who is up to no good.
It is your job to help bring her down. The is a gang working under her.
The chain of command of the gang is structured in such a way that each leader has 7 people working directly under him/her.
Your task is to find the total number of people in Prof. Boolean's workforce given the number of level of hierarchy.
'''
levels = int(input('Number of level(s): '))
peoples = 1
for i in range(levels):
peoples += (7 ** (i + 1))
'''
The table below gives the age (in year) and mileage (in KMs) of four used cars:
WARTBURG MOSKVICH LADA TRABI
Age: 5 7 15 28
Mileage: 30530 90000 159899 270564
1. Determine the weights w0 and w1 for a simple linear regression to predict mileage from age.
2. Use the model from (1) to predict the mileage for a 15-year old car.
'''
@harshildarji
harshildarji / check_word.py
Created November 24, 2018 23:18
A little script to check whether the alphabets in a word are presented in an alphabetical order or not!
ip = input('Enter a string: ')
op = ip[0]
for i in range(len(ip) - 1):
dist = ord(ip[i].lower()) - ord(ip[i+1].lower())
if dist > 0: op += ' > ' + ip[i+1]
else: op += ' < ' + ip[i+1]
print(op)
@harshildarji
harshildarji / regex_python.py
Created May 12, 2018 19:25
HackerRank Regex Solutions | Python
# Regex | HackerRank
# https://www.hackerrank.com/domains/regex
# Matching Anything But a Newline
Regex_Pattern = r'...\....\....\....$'
# Matching Specific String
Regex_Pattern = r'hackerrank'
@harshildarji
harshildarji / levenshtein_distance.py
Last active November 24, 2018 23:19
Generating Levenshtein Distance Matrix and finding Minimum Edit Distance
import numpy
s1 = input('input: ').strip().lower(); l1 = len(s1) + 1
s2 = input('target: ').strip().lower(); l2 = len(s2) + 1
m = numpy.empty([l1, l2], dtype = int)
for i in range(l1):
m[i][0] = i
@harshildarji
harshildarji / array_rotation.py
Created December 14, 2017 15:35
Array Rotation (Left and Right)
n, d = map(int, input().split()) # n = len(array), d = Number of rotation
values = [i for i in input().split()][:n]
print(" ".join(values[d:] + values[:d])) # left rotation
print(" ".join(values[n-d:] + values[:n-d])) # right rotation
@harshildarji
harshildarji / QRCode.java
Last active December 19, 2018 14:50
Generating QR code in Android.
...
String QRcode = "...";
new generateQrcode(qrcodeImageview).execute(QRcode);
...
private class generateQrcode extends AsyncTask<String, Void, Bitmap> {
public final static int WIDTH = 400;
ImageView bmImage;
public generateQrcode(ImageView bmImage) {
this.bmImage = bmImage;
@harshildarji
harshildarji / activity_facebook.xml
Last active December 5, 2016 19:05
Sign-In with Facebook using Firebase and get user information using Facebook Graph API.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_facebook"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"