Skip to content

Instantly share code, notes, and snippets.

View ankitml's full-sized avatar
🎯
Focusing

Ankit ankitml

🎯
Focusing
View GitHub Profile
@ankitml
ankitml / orm.php
Last active January 7, 2016 07:25
Simple orm library in PhP
<?
/**
*
* Connect to the database defined in config file.
* @return - mysqli link object, Flase if error.
*
*/
function connect_db() {
global $CFG;
@ankitml
ankitml / multiple_csv.py
Last active January 5, 2016 12:25
A python function to read data from multiple csvs, each of them can have extra rows or columns or both between them. Also needs a primary column header called key_header
from real_type import get_type
#real type can be taken from https://github.com/ankitml/real_type or https://pypi.python.org/pypi/real_type/0.1
def read_multiple_csv(files, key_header):
"""
takes a list of filesnames and a key_header string to merge the files.
Can merge if there are different columns in the files, different records in
the files.
Assumption - all the files should have the column named key_header
example : files = ['grades.csv', 'previous_grades.csv']
@ankitml
ankitml / transformations.py
Created January 7, 2016 07:21
CSV transformations
from true_type import get_type
import csv
def get_percentile(data_list, score, kind='weak'):
"""
The percentile rank of a score relative to a list of scores.
A percentile of, for example, 80 percent means that 80 percent of the
scores in the data_list are below the given score.
In the case of gaps or ties, the exact definition depends on the type
@ankitml
ankitml / drf-filters.py
Last active April 5, 2022 14:03
Pluggable filters for Django Rest Framework
Accompanies (http://iank.it/pluggable-filters-for-django-rest-framework/)
class FiltersBackendBase:
"""
Base class to create FilterBackends
FilterBackends are complementary classes that can be
used with GenericFilterMixin
"""
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
@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?
@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 / 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 / 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 / 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