A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
# Python implementation of Binary Indexed Tree | |
# sum of elements and update both cost O(log(n)) | |
# Returns sum of arr[0..index]. This function assumes | |
# that the array is preprocessed and partial sums of | |
# array elements are stored in BITree[]. | |
def getsum(BITTree,i): | |
s = 0 #initialize result | |
# index in BITree[] is 1 more than the index in arr[] |
Bubble Sort: Iterate through entire list while comparing pairs and swap positions based on their values until all elements sorted.
O(n²), but fast if list is almost sorted.
Insertion Sort: Iterates through unsorted list while building a sorted list. For each value encountered in unsorted list, find appropriate place in sorted list and insert it.
O(n²).
When there are multiple apps on a server using same database, e.g. postgres, there are several deployment options:
When using single DB, i.e. options 2-4, you have to decied for using same creditentials for all apps, or make DB users per apps. The former requires less work but may cause interference and debug can be more complicated, the latter is easier to implement but less error prune. I suggest to have shared user for every type of apps. If you have 5 instances of app A with different databases, and 3 instances of app B, you can make 2 shared users for each. Of course shared database means you have to know how your apps interact with database and you are respo
select g2j(now()) | |
CREATE OR REPLACE FUNCTION g2j(in_date timestamp with time zone) | |
RETURNS character varying AS | |
$BODY$ | |
DECLARE | |
y smallint; | |
aday smallint; | |
amonth smallint; | |
ayear smallint; |