Skip to content

Instantly share code, notes, and snippets.

View ankitml's full-sized avatar
🎯
Focusing

Ankit ankitml

🎯
Focusing
View GitHub Profile
@ankitml
ankitml / ws1.py
Last active February 6, 2019 20:02
Websockets Tutorial 1
import asyncio
import websockets
async def ws_handler(websocket, path):
async for message in websocket:
print(message)
if message == 'ping':
await websocket.send('pong')
backcall==0.1.0
decorator==4.3.0
hiredis==0.2.0
httptools==0.0.11
ipdb==0.11
ipython==6.5.0
ipython-genutils==0.2.0
jedi==0.12.1
parso==0.3.1
pexpect==4.6.0
import asyncio
import websockets
from websockets.exceptions import ConnectionClosed
from time import sleep
async def connect():
while True:
try:
async with websockets.connect('ws://localhost:9999') as websocket:
@ankitml
ankitml / async_http_benchmark.py
Last active August 28, 2018 18:43 — forked from nhumrich/async_http_benchmark.py
async vs threading http benchmark
from timeit import timeit
import asyncio
import requests
from threading import Thread
import aiohttp
client = aiohttp.ClientSession()
@ankitml
ankitml / devops_best_practices.md
Created June 27, 2018 04:48 — forked from jpswade/devops_best_practices.md
Devops Best Practices

DevOps started out as "Agile Systems Administration". In 2008, Andrew Shafer did a talk called "Agile Infrastucture" addressing issues around involving more of the company in the same disciplines as programmers.

In 2009, Patrick Debois created "DevOpsDays" conference to help to bring it to light. However, it wouldn't begin to trend until about 2010, when people would begin to describe it as a standalone discipline.

Today, DevOps goes beyond just developers, systems administration and infrastructure, its about [dev, ops, agile, cloud, open source and business](https://blogs.the451group.com/opensource/2010/03/03/devops-mixing-dev-ops-agile-cloud-open-source-and-busi

@ankitml
ankitml / imigrate.py
Last active April 13, 2017 18:56
Interactive Django migrations. Supports +1/-1 interface for django migrations, similar to Alembic for SQLAlchemy. Also supports fast forward and fast rewind facility"
from django.core.management.base import BaseCommand, CommandError
from django_redis import get_redis_connection
from django.db import DEFAULT_DB_ALIAS, connections
from django.db.migrations.loader import MigrationLoader
from django.core.management import call_command
class Command(BaseCommand):
help = """Interactive Django migrations. Supports +1/-1 interface for django migrations,
similar to Alembic for SQLAlchemy. Also supports fast forward and fast rewind
@ankitml
ankitml / problem1.md
Created March 15, 2017 09:03
Partially persistent data structures

Partially persistent Data Structures are the ones where we can go back and look at how the data looked like in history.

For this assignment, you have to implement Partially persistent Data structure (dictionary) in python, with any data store (redis, mongoDB, etc) with the following features.

  1. A way to get latest state of dictionary. Or latest value of any key in dictionary.
  2. A way to get historical version of dictionary.
  3. History of any key in the dictionary.
  4. Update the dictionary to a new version.
@ankitml
ankitml / handout.md
Created January 31, 2017 08:13
Handout for workshop

underscore

Underscorejs port for python

Highlights

  • Works with python 3.
  • All methods are lazy and return generators (well almost all)

Why

@ankitml
ankitml / service-checklist.md
Created December 31, 2016 11:49 — forked from acolyer/service-checklist.md
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
3 def get_or_create_lti_user(tool_provider):
2 email = tool_provider.get_param('lis_person_contact_email_primary')
1 name = tool_provider.get_param('lis_person_name_full')
4 userid = tool_provider.get_param('user_id')
1 if userid is None or userid == "" :
2 raise InvalidLTIRequestError('USERID NOT SENT BY CANVAS')
3 if email is None or email == "":
4 raise InvalidLTIRequestError('EMAIL NOT SENT BY CANVAS')
5
6