Skip to content

Instantly share code, notes, and snippets.

View amitness's full-sized avatar
⬆️
1.01³⁶⁵

Amit Chaudhary amitness

⬆️
1.01³⁶⁵
View GitHub Profile
@amitness
amitness / gist:4c566dc8de6fd8ee01f5
Created November 26, 2015 16:12
Download Coursera Subtitle
Use this format for downloading subtitle for a video course on Coursera. Increment the 01_en for successive subtitles.
https://class.coursera.org/cplusplus4c-002/lecture/subtitles?q=01_en&format=srts
@amitness
amitness / neb.py
Last active April 19, 2017 11:06
A gist to teach someone how to send post requests using requests library.
import requests
from bs4 import BeautifulSoup
payload = {
'keyword': '20403105',
'slug': 'SearchResult'
}
response = requests.post('http://www.neb.gov.np/result/search', data=payload)
words = ["Michael", "Lieberman"]

What Codecademy teaches

def join_strings(words):
    result = ""
 for word in words:
@amitness
amitness / computer-engineering.md
Created June 6, 2017 13:18
Linux Alternatives to software used in my lab during undergrad studies
@amitness
amitness / aws_services.py
Last active December 31, 2018 05:54
List all AWS Services and their associated methods
import csv
import boto3
def get_available_methods(service):
client = boto3.client(service)
all_attributes = dir(client)
available_methods = [attribute for attribute in all_attributes if callable(getattr(client, attribute))]
available_methods = [i for i in available_methods if not i.startswith('_')]
@amitness
amitness / tldr.py
Created March 13, 2019 11:57
Read the TOC of a PDF using Python
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
import sys
# python tldr.py filename.pdf
fp = open(sys.argv[1], 'rb')
parser = PDFParser(fp)
doc = PDFDocument(parser)
@amitness
amitness / scan_network.py
Created March 13, 2019 12:00
Get the IP address of all device on the local network
import os
import re
output = os.popen('arp -a').read().splitlines()
ips = [re.search(r'\d+\.\d+\d+.\d+.\d+', b).group(0) for b in output]
for ip in ips:
print(os.popen('nmblookup -A {}'.format(ip)).read())
@amitness
amitness / model_mommy_jsonfield.md
Created May 24, 2019 06:15
How to use JSONField in model_mommy to generate fixtures

In your tests/init.py file, add the following

from model_mommy import mommy

def generator_function():
    return {}


mommy.generators.add('django_mysql.models.JSONField', generator_function)
@amitness
amitness / jupyter-notebook-python-api.md
Created December 18, 2019 08:23
Create a jupyter notebook programatically in python
from nbformat.v4 import new_notebook, new_code_cell, new_markdown_cell

import nbformat

nb = new_notebook()

nb.cells = [
    new_code_cell('print("hello")'),
 new_markdown_cell('# Cool')