Skip to content

Instantly share code, notes, and snippets.

@SuryaSankar
SuryaSankar / M2M_Association_SQLalchemy.py
Last active September 25, 2023 07:30
An example of a many to many relation via Association Object in SQLAlchemy
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, relationship, backref
from sqlalchemy.ext.associationproxy import association_proxy
import uuid
engine = sqlalchemy.create_engine('sqlite:///:memory:')
Base = declarative_base()
@SuryaSankar
SuryaSankar / alter_enum_alembic_mysql.py
Created May 11, 2014 17:12
Alembic migration for modifying a Enum field
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column(table_name='items', column_name='status', nullable=False, server_default="pending_with_moderator", name="status",
type_=sa.types.Enum('pending_with_moderator','pending_with_user','awaiting_user_modification','awaiting_moderator_modification','approved'),
existing_type=sa.types.Enum('pending_with_moderator', 'pending_with_user', 'approved'),existing_server_default="pending_with_moderator",
existing_nullable=False)
@SuryaSankar
SuryaSankar / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@SuryaSankar
SuryaSankar / inkmonkCountdown.js
Created February 7, 2015 15:51
A very simple countdown Timer ( Modified from http://jsfiddle.net/dpeaep/LQGE2/1/ )
angular.module( 'inkmonk.directives', [] )
.directive('inkmonkCountdown',['$compile', function($compile){
return {
restrict: 'AE',
template: "{{counter}}",
scope: {
counterStart : "=start",
dependsOn: "=runduring"
},
controller: ['$scope', '$element', '$attrs', '$timeout', function ($scope, $element, $attrs, $timeout) {
@SuryaSankar
SuryaSankar / utils.py
Last active August 29, 2015 14:15
Python Utils
#########################################################
# Generic methods independent of any App logic here.
# This module is meant to be a Python tool set.
#########################################################
from itertools import chain, groupby
from operator import attrgetter
from contextlib import contextmanager
from inspect import ismethod
import re
@SuryaSankar
SuryaSankar / grid_paths.py
Created April 30, 2015 05:46
All paths in a rowxcol grid from top left till bottom right
class Point(object):
def __init__(self, row, col):
self.row = row
self.col = col
def __eq__(self, other):
return self.row == other.row and self.col == other.col
def __repr__(self):
return "(%s, %s)" % (self.row, self.col)
@SuryaSankar
SuryaSankar / DeveloperJD.md
Last active February 11, 2019 07:22
Developer at Inkmonk.com - Job Description

You will be building...

A Marketplace for Custom Printed Products.

It is challenging because...

  1. It is a multi-category ecommerce platform with customization services built on top. It requires every product to be treated differently from the customer's POV, while still retaining the platform's ability to treat them as interchangeable entities.

  2. Online printing platforms require sophisticated design tools ( For example, take a look at https://inkmonk.com , zazzle.com or vistaprint.com). Building them requires some seriously good frontend wizardry.

  3. The huge complexity in the nature of the products, their physical specifications, their printing specifications and the ways in which they can combine to determine the price of a given product can cause some serious combinatorial challenges. Simplifying the domain to build a scaleable platform is the challenge

@SuryaSankar
SuryaSankar / food_app.md
Last active August 7, 2016 15:59
Task #1 - Build a multi-category Food products ordering platform

Evaluation Task #1 for Backend Developer Role at Inkmonk.com

Have you watched "Cloudy with a chance of meatballs?" The plot is very simple. Flint is an eccentric genius who has discovered a machine which will manufacture infinite varieties of food by mixing and matching ingredients in a zillion ways. And then a host of bad stuff happens as usual. But that is irrelevant to us.

Let's say Flint wants to create a website where he can offer his food item creation service to everyone in the world. He has contracted you to develop the website for him. Here are his requirements

###Requirements

  1. Right now Flint is planning to let users create their own pizzas, burgers, sandwiches, ice creams, milk shakes and a full course Indian meals. The list won't end with this. He will keep on adding and is planning to add at least 100 kinds of food by the end of next month.
@SuryaSankar
SuryaSankar / shop_erp.md
Last active April 4, 2018 12:00
Problem statement to design a basic inventory and billing management tool for a grocery store

Goal

The goal of this task is to find out how good you are at understanding a business requirement and converting it into code. You will be required to build a dashboard with some basic CRUD actions only.

Problem Statement

Design a basic version of an inventory and billing management tool for a grocery store

Basic Requirements

(These are the basic requirements for the tool - which have to be necessarily implemented)

@SuryaSankar
SuryaSankar / monthly_retention_percentage_orders.sql
Created December 12, 2018 11:08
SQL query for plotting a monthly retention grid for orders
SELECT
activity_sq.activity_cohort_date AS first_purchase_date,
population_agg_sq.cohort_total_user_count AS total_user_count,
period_diff(activity_sq.activity_date, activity_sq.activity_cohort_date) AS month_number,
count(DISTINCT activity_sq.order_user_id) * 100 / population_agg_sq.cohort_total_user_count AS retention_percent
FROM (
SELECT date_format(convert_tz(order.paid_on, '+00:00', '+05:30'), '%Y%m') AS activity_date,
order.user_id AS order_user_id,
population_sq.cohort_date AS activity_cohort_date
FROM