Skip to content

Instantly share code, notes, and snippets.

View arshamalh's full-sized avatar
:octocat:
This Octacat is my pet!

Mohammad Reza Karimi arshamalh

:octocat:
This Octacat is my pet!
View GitHub Profile
@arshamalh
arshamalh / erc20_balance.go
Last active February 17, 2024 07:30
Finding ETH erc20 tokens balance using golang and infura.io
/// Import on the top of your project
import "github.com/ethereum/go-ethereum/crypto"
type ethHandlerResult struct {
Result string `json:"result"`
Error struct {
Code int64 `json:"code"`
Message string `json:"message"`
} `json:"error"`
}
@arshamalh
arshamalh / erc20_balance.js
Created June 19, 2021 07:37
Finding ETH erc20 tokens balance using JavaScript and infura.io
const infuraProjectID = "Write your infura projectID here" // https://infura.io/signup
const tokenContractAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7"
const accountAddress = "0x757d576da3fba018b1bd9cdd05fa4ca0261792c8"
// Dependencies
const Web3 = require('web3');
const web3 = new Web3()
const keccak_256 = require('js-sha3').keccak256
const rp = require('request-promise')
const retry = require('async-retry')
@arshamalh
arshamalh / getBearerToken.js
Created November 10, 2021 11:23
Twitter OAuth 2.0 Get Bearer Token
// npm install got, dotenv
const got = require('got');
require('dotenv').config();
const credentials = process.env.CONSUMER_TOKEN + ":" + process.env.CONSUMER_SECRET
const credentialsBase64Encoded = new Buffer.from(credentials).toString('base64');
got({
url: 'https://api.twitter.com/oauth2/token',
method:'POST',
@arshamalh
arshamalh / pgCursorPagination.js
Created December 13, 2021 07:03
Cursor pagination in PostgreSQL and Nodejs
// Written by Arsham Arya
// I'm not sure it's the best way,
// So any contribution makes me and other readers happy :)
import pgPromise from "pg-promise";
import Cursor from "pg-cursor";
require("dotenv").config();
const pgp = pgPromise();
@arshamalh
arshamalh / uniqueArrayElement.sql
Last active December 23, 2021 08:15
Postgres making arrays taking unique elements
-- Written by Arsham Arya
-- Any contribution makes readers happy.
INSERT INTO table_name (user_id, my_array_field)
VALUES (2233, array[112, 333])
ON CONFLICT (user_id) DO
UPDATE SET my_array_field = array(
SELECT DISTINCT unnest(table_name.my_array_field || array[112, 333])
) WHERE table_name.user_id = 2233;
@arshamalh
arshamalh / pgCursorPagination.py
Created December 23, 2021 09:40
Cursor pagination in PostgreSQL and Python
# Written by Arsham Arya
# I'm not sure it's the best way,
# So any contribution makes me and other readers happy :)
from psycopg2.pool import ThreadedConnectionPool
import config
_CONNECTION_POOL = None
@arshamalh
arshamalh / contact_book.py
Created January 15, 2022 09:12
simple Tkinter contact book.
from tkinter import *
from tkinter import messagebox
root = Tk()
root.geometry("480x170")
root.title("Raha Contacts books")
Name = StringVar()
Number = StringVar()
Address = StringVar()
@arshamalh
arshamalh / compound_index_pymongo.py
Created January 21, 2022 15:38
Making compound unique index in Mongodb using pymongo
# Compound unique indexs are indexes made of multiple columns together.
# For example if we have this data:
"""
("arsham", 930)
"""
# We can have ("arsham", 920), ("arsham", 910), Also we can have ("atousa", 930)
# but we can't have ("arsham", 930) again.
# I hope I explained it well enough. 😊
from pymongo import MongoClient, ASCENDING
@arshamalh
arshamalh / paginating_tmdb_trends_through_api.py
Last active February 7, 2022 13:06
Getting TMDB trends using their API
@arshamalh
arshamalh / config.py
Last active March 2, 2022 09:21
Python best way to import environment variables for development and production
"""
Written by Arsham Arya
I'm not sure it's the best way,
So any contribution makes everyone happy!
"""
from os import environ
# pip install python-dotenv
from dotenv import dotenv_values