Skip to content

Instantly share code, notes, and snippets.

View ankitml's full-sized avatar
🎯
Focusing

Ankit ankitml

🎯
Focusing
View GitHub Profile
@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
"""
@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 / 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 / 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;