This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def get_utc_datetime_from_timestamp(timestamp): | |
""" | |
datetime.datetime.utcfromtimestamp returns utc date time | |
whereas datetime.datetime.fromtimestamp returns local (system) date time | |
""" | |
return str(datetime.datetime.utcfromtimestamp(int(timestamp))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncpg | |
db_config = { | |
'user': 'postgres', # name of db user | |
'password': 'my db password', # db password | |
'database': 'my_db', # database name | |
'host': 'localhost' # or remote db ip address | |
} | |
async def custom_query(query_string): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*create a sample table with table name user_credits and columns id primary key, username, credit_assigned, credit_expire_time, is_user_kyced*/ | |
CREATE TABLE user_credits (id BIGSERIAL PRIMARY KEY, username VARCHAR(25), credit_assigned integer, credit_expire_time bigint, is_user_kyced boolean); | |
/* | |
bigserial 8 bytes large autoincrementing integer 1 to 9223372036854775807 | |
integer 4 bytes typical choice for integer -2147483648 to +2147483647 | |
bigint 8 bytes large-range integer -9223372036854775808 to +9223372036854775807 | |
boolean 1 byte state of true or false | |
VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special characters). The size parameter specifies the maximum string length in characters - can be from 0 to 65535 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def lambda_handler(event, context): | |
# TODO implement | |
user_name = event.get('name') | |
message = 'Hello {}'.format(user_name) | |
return { | |
'statusCode': 200, | |
'message': message, | |
'body': json.dumps('This message is from Lambda!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def get_datetime_from_string(datetime_string, datetime_format='%Y-%m-%d %H:%M:%S'): | |
""" | |
if datetime string includes milliseconds (e.g. '2022-12-06 11:22:23.222') | |
then the datetime format will be '%Y-%m-%d %H:%M:%S.%f' to include fraction | |
""" | |
return datetime.datetime.strptime(datetime_string, datetime_format) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
let count = 0; | |
function getAllButtons() { | |
return document.querySelectorAll('button.is-following') || []; | |
} | |
async function unfollowAll() { | |
const buttons = getAllButtons(); | |
for (let button of buttons) { | |
count = count + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop procedure if exists populate_customers; | |
delimiter // | |
create procedure populate_customers (in num int) | |
begin | |
declare i int default 0; | |
while i < num do | |
insert into customers (customer_id, name, email) values ((num*10)+i, concat('name', i), concat('email', i)); | |
set i = i + 1; | |
end while; | |
end // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insert into customer_balance_logs (customer_id, credit, reason) select id, 5, 'x-mas credit' from customers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> source <path to the file alongwith filename>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This way you can customize which branches should be skipped when | |
# prepending commit message. | |
if [ -z "$BRANCHES_TO_SKIP" ]; then | |
BRANCHES_TO_SKIP=(master develop test) | |
fi | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
BRANCH_NAME="${BRANCH_NAME##*/}" |
OlderNewer