Skip to content

Instantly share code, notes, and snippets.

@sidharthshah
sidharthshah / simple-crawler.py
Created August 7, 2019 10:10
Python Crawling Example
import re
import ssl
from urllib import request
seedlist = ['https://scrapy.org/']
def extract_urls(url):
"""
this function is used to extract URLs from HTML
"""
def numeric_encoding(some_string):
mappings = {"A": "1", "G": "2", "C": "3", "T": "4"}
results = ""
for current in some_string:
results += mappings[current]
return results
numeric_encoding("AGCTTCA")
@sidharthshah
sidharthshah / hello_google_docs.py
Last active April 14, 2018 11:21
Python-Google-Sheet-Example
# This is example from https://developers.google.com/sheets/api/quickstart/python
"""
Shows basic usage of the Sheets API. Prints values from a Google Spreadsheet.
"""
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
@sidharthshah
sidharthshah / Notes.md
Last active September 3, 2017 07:27
Notes from DeepLearning.TV's Youtube Videso
  • GEOFF HILTON {Father of DNN}
  • MLP {Multi Layered Perceptron} -> Vanialla Neural Network
  • Problem of Vanishing Gradient {This is what RBM Solves}

Unsupervised

RBM {Extract features and reconstruct inputs}

  • Forward/Backward Phase
# Grammar Based Natural Language Query Parser
# Background: I've implemented a better search engine for an eCommerce Site. There was a legacy code which had lot of
# if-else blocks. By using Grammer based parsing code I was able to reduce Line of Codes for Module and
# make it more extensible and maintainable
# Ref:
# 1. http://infohost.nmt.edu/tcc/help/pubs/pyparsing/pyparsing.pdf
# 2. http://q3k.org/gentoomen/Programming/Python/Getting%20Started%20with%20Pyparsing%20(2007).pdf
from pyparsing import Word, alphas, oneOf
@sidharthshah
sidharthshah / samples.py
Last active May 13, 2017 10:20
Sample Python Code
# This is Readable
>>> nums = []
>>> for i in range(1000):
... nums.append(random.randint(1, 1000))
...
# This is not readable
num_1 = [random.randint(1, 1000) for i in range(1000)]
# Traditional way of doing things
@sidharthshah
sidharthshah / format_name.py
Last active November 8, 2015 04:49
Simple way to format name
from string import strip
def format_name(name):
#Step 1: Split by ,
#Step 2: Remove any extrac white space in tokens using Map
#Step 3: Reverse List using ::-1
#Step 4: Join with White Space
return " ".join(map(strip, name.split(","))[::-1])
>>> format_name("Shah, Saheb")
'Saheb Shah'
# -*- coding: utf-8 -*-
import os
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from hashlib import md5
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.skoovbot
@sidharthshah
sidharthshah / science-wikipedia-articles.txt
Created October 14, 2015 03:35
List of wikipedia Pages relating to Science category
environmental change
resistor ladder
effects of high altitude on humans
mendelian inheritance
pellucidar
ryōji noyori
aphthous stomatitis
holonomic brain theory
umbilicus (mollusc)
destroy all humans!
parser.add_argument('-v', '--verbose', action='count', default=0)
parser.add_argument('-q', '--quiet', action='count', default=0)
logging_level = logging.WARN + 10*args.quiet - 10*args.verbose
# script -vv -> DEBUG
# script -v -> INFO
# script -> WARNING
# script -q -> ERROR
# script -qq -> CRITICAL