Skip to content

Instantly share code, notes, and snippets.

View mzmmoazam's full-sized avatar

Moazam mzmmoazam

View GitHub Profile
@mzmmoazam
mzmmoazam / HTML2JSON.js
Created December 18, 2016 14:13
JQuery snippet to convert HTML to JSON object.
// jQuery snippet for changing HTML form into JSON
(function ($) {
$.fn.serializeFormJSON = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) { o[this.name] = [o[this.name]]; }
@mzmmoazam
mzmmoazam / csv2pdf.py
Created January 25, 2017 18:51
To convert csv to pdf reports using Reportlab.
import csv
from reportlab.platypus import Paragraph,SimpleDocTemplate
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.graphics.charts.piecharts import Pie
from reportlab.lib.colors import brown,blue
from reportlab.graphics.charts.legends import Legend
from reportlab.graphics.shapes import Drawing
from reportlab.lib.colors import black
# THIS FUNCTION CALCULATES THE PERCENTILE
@mzmmoazam
mzmmoazam / gist:ecca2a5035cc742f042360172c53e8de
Created April 15, 2017 08:25 — forked from econchick/gist:4666413
Python implementation of Dijkstra's Algorithm
class Graph:
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
self.nodes.add(value)
def add_edge(self, from_node, to_node, distance):
@mzmmoazam
mzmmoazam / sqlite_made_easy.py
Created September 24, 2017 06:16
This is to simple the usage of database in any application and create a readable and modular script.
import sqlite3
class database(object):
def __init__(self):
self.filename = "help.db"
self.table = "help_data"
self.sql_do('create table if not exists '+self.table+' ( key TEXT,data TEXT)')
def sql_do(self, sql, *params):
self._db.execute(sql, params)
self._db.commit()
@mzmmoazam
mzmmoazam / database_portgres.py
Last active September 24, 2017 15:45
This is class implementation of the portgresql using python.
#!/usr/bin/python
import psycopg2
class database(object):
def __init__(self,database,table):
self.database = database
self.table = table
self.sql_do('create table if not exists '+self.table+' ( key TEXT,data TEXT)')
def sql_do(self, sql, *params):
@mzmmoazam
mzmmoazam / url_tree.py
Created October 28, 2017 14:16
Can generate the sitemap and also get the links on any specific depth (layer).
import requests
from urllib.parse import urlparse,urljoin
from bs4 import BeautifulSoup
all_urls = set()
class url_tree():
def __init__(self, base_url,page_no=1 ,children=None):
self.url = base_url
self.page_no =page_no
@mzmmoazam
mzmmoazam / hack_openai.py
Created October 28, 2017 14:21
used mlp and lstm on the openai's gym #cartpole games.
import gym
import random
import numpy as np
import tflearn
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.data_utils import to_categorical
from tflearn.layers.estimator import regression
from statistics import median, mean
from collections import Counter
import glob
@mzmmoazam
mzmmoazam / Eng_to_turkish.py
Created April 2, 2018 12:13
This gist uses your computer as a personal translator; converts English audio to Turkish audio.
import speech_recognition as sr, pyttsx
from googletrans import Translator
# pyttsx engine config
speech_engine = pyttsx.init('sapi5') # see http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init
speech_engine.setProperty('rate', 150)
# translator object
translator = Translator()
@mzmmoazam
mzmmoazam / Turkish_2_Eng.py
Created April 2, 2018 12:15
This gist converts Turkish audio to English audio.
import Algorithmia, speech_recognition as sr, pyttsx
# Algorthmia Api key and end point
client = Algorithmia.client('simCM+BqJzKSw/iMrQsR/OTRwVE1')
algo = client.algo('translation/GoogleTranslate/0.1.1')
# pyttsx engine config
speech_engine = pyttsx.init('sapi5') # see http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init
speech_engine.setProperty('rate', 150)
@mzmmoazam
mzmmoazam / naive_bayes.py
Last active May 13, 2018 16:17
A simple naive bayes implementation
import csv, random
class NaiveBayes(object):
def __init__(self, filename, split_ratio):
'''
:param filename: a csv filename with absolute or full path
:param split_ratio: test to train ratio
'''