Magic words:
psql -U postgres
If run with -E
flag, it will describe the underlaying queries of the \
commands (cool for learning!).
Most \d
commands support additional param of __schema__.name__
and accept wildcards like *.*
#serialize datetime to json | |
#https://stackoverflow.com/questions/35869985/datetime-datetime-is-not-json-serializable | |
import datetime | |
import json | |
def datetime_handler(x): | |
if isinstance(x, datetime.datetime): | |
return x.isoformat() | |
raise TypeError("Unknown type") |
#UTF-8 proof | |
with open(os.path.join('test','graph.json'),'w',encoding='utf-8') as fd: | |
json.dump(json_graph.adjacency_data(Tree.graph),fd,indent=1,ensure_ascii=False) |
import itertools | |
#collapse list | |
list2d = [[1,2,3],[4,5,6], [7], [8,9]] | |
merged = list(itertools.chain.from_iterable(list2d)) | |
#efficient merge list | |
#courtesy http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python#952946 | |
l = [[1,2,3],[4,5,6], [7], [8,9]] | |
C = [item for sublist in l for item in sublist] |
#add leading zero ... | |
print str(1).zfill(2) | |
print str(10).zfill(2) | |
>>01 | |
>>10 | |
#format https://pyformat.info/ | |
'{:.2f}'.format(3.141592653589793) | |
>>'3.14' |
-- Order report | |
--[u'OrderId', u'FirstName', u'LastName', u'Email', u'Address', u'Postcode', u'ProductList', u'Status', u'PaidDate', u'CompletedDate', u'PaymentMethod', u'Shipping', u'TotalOrder'] | |
SELECT post_id AS OrderId, | |
Group_concat( IF( meta_key = '_billing_first_name', meta_value, NULL ) ) AS FirstName, | |
Group_concat( IF( meta_key = '_billing_last_name', meta_value, NULL ) ) AS LastName, | |
Group_concat( IF(meta_key = '_billing_email', meta_value, NULL)) AS Email, | |
Group_concat( IF( meta_key = '_billing_address_1', meta_value, NULL ) ) AS Address, | |
Group_concat( IF( meta_key = '_billing_postcode', meta_value, NULL ) ) AS Postcode, | |
Group_concat( IF( meta_key = '_desc_content', meta_value, NULL ) ) AS ProductList, |
def pandas_df_to_markdown_table(df,name): | |
fmt = ['---' for i in range(len(df.columns))] | |
df_fmt = pd.DataFrame([fmt], columns=df.columns) | |
df_formatted = pd.concat([df_fmt, df]) | |
df_formatted.to_csv(name,sep="|", index=False) |
<table> | |
{% for key, value in result.iteritems() %} | |
<tr> | |
<th> {{ key }} </th> | |
<td> {{ value }} </td> | |
</tr> | |
{% endfor %} | |
</table> |
Latency Comparison Numbers | |
-------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |