class Foo:
bar = "class attribute"
def __init__(self):
self.ham="instance attribute"
def baz(self):
self.baz = "changed instance attribute"
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; |
When there are multiple apps on a server using same database, e.g. postgres, there are several deployment options:
- Each app can have a database container for each own
- There could be a single database container and a shared network for all apps
- using a single docker-compose.yml for all apps having one database container,
- database can be installed on local host with different users for each apps
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
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²).
# 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[] |