Skip to content

Instantly share code, notes, and snippets.

View apinanyogaratnam's full-sized avatar
🧐

Apinan Yogaratnam apinanyogaratnam

🧐
View GitHub Profile
@apinanyogaratnam
apinanyogaratnam / text_search_psql.py
Created June 24, 2023 02:59
Search Text Postgres Really Fast
'''
THIS SCRIPT IS FOR TESTING pg_trgm postgres extension
1.
CREATE TABLE test_text_search (
id SERIAL PRIMARY KEY,
word TEXT
);
2.
@apinanyogaratnam
apinanyogaratnam / query.sql
Created June 21, 2023 01:22
Query all enums in postgres
SELECT (
col.table_schema,
col.table_name,
col.ordinal_position as column_id,
col.column_name,
col.udt_name,
string_agg(enu.enumlabel, ', ' ORDER BY enu.enumsortorder) AS enum_values
)
FROM information_schema.columns col
JOIN information_schema.tables tab ON tab.table_schema = col.table_schema
@apinanyogaratnam
apinanyogaratnam / script.sh
Last active February 7, 2023 20:44
aws amazon linux ec2 setup with docker
sudo yum install git -y
sudo git config --global user.name "your_username"
sudo git config --global user.email "your_email_address@example.com"
sudo yum update -y
sudo amazon-linux-extras install docker
sudo yum install docker -y
@apinanyogaratnam
apinanyogaratnam / create_db_script.py
Last active January 1, 2023 16:44
python script boilerplate to create postgres database table
import logging
import os
import sys
from dotenv import load_dotenv
from postgres_database_utils import create_connection, PostgresCredentials
# constants
DROP_TABLE = True
TABLE_NAME = "boilerplate"
@apinanyogaratnam
apinanyogaratnam / script.sh
Created November 12, 2022 15:00
Docker without Docker desktop on mac
# Install hyperkit and minikube
brew install hyperkit
brew install minikube
# Install Docker CLI
brew install docker
brew install docker-compose
# Start minikube
minikube start
@apinanyogaratnam
apinanyogaratnam / flask_rest_api.py
Last active February 13, 2022 15:01
run a flask app with minimal code
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return {'test': "Hello, World!"}
if __name__ == '__main__':
app.run(debug=True, host='localhost', port=8000)
@apinanyogaratnam
apinanyogaratnam / historical_ethereum_prices.py
Created February 9, 2022 00:46
get historical ethereum prices
import requests
date = input("Enter a date in DD-MM-YYYY format: ")
url = f"https://api.coingecko.com/api/v3/coins/ethereum/history?date={date}"
response = requests.get(url).json()
price_at = round(response['market_data']['current_price']['usd'], 2)
print(price_at)
@apinanyogaratnam
apinanyogaratnam / bayc-conversion-abi.js
Created February 7, 2022 22:33
bored ape yacht club abi convertion to json
const tokenABI = [
{
inputs: [
{ internalType: "string", name: "name", type: "string" },
{ internalType: "string", name: "symbol", type: "string" },
{ internalType: "uint256", name: "maxNftSupply", type: "uint256" },
{ internalType: "uint256", name: "saleStart", type: "uint256" },
],
stateMutability: "nonpayable",
type: "constructor",
@apinanyogaratnam
apinanyogaratnam / git-steps.sh
Created January 11, 2022 03:25
steps to perform to push to remote repository
# add all contents to git
git add .
# commit all contents to staging index
git commit -m 'some message goes here about the changes made'
# add a remote origin
git remote add origin https://github.com/<username>/<project-name>
# view branch name
@apinanyogaratnam
apinanyogaratnam / rcp.js
Last active May 3, 2022 08:53
All RCP connections for working with the MetaMask API
const networks = {
polygon: {
chainId: `0x${Number(137).toString(16)}`,
chainName: "Polygon Mainnet",
nativeCurrency: {
name: "MATIC",
symbol: "MATIC",
decimals: 18
},
rpcUrls: ["https://polygon-rpc.com/"],