Skip to content

Instantly share code, notes, and snippets.

View devmnj's full-sized avatar
💭
Exploring Algos

Manoj AP devmnj

💭
Exploring Algos
View GitHub Profile
@devmnj
devmnj / hf_colab
Last active October 28, 2024 14:55
Use hugging face models in Colab
//authenticate hf with token
import huggingface_hub
huggingface_hub.login()
//Use the model
sentiment_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
result = sentiment_pipeline("Tesla's latest earnings report exceeded expectations, leading to a surge in stock price.")
print(result)
@devmnj
devmnj / gsheet-to-panda
Created October 21, 2024 12:40
Load google sheet data into panda frame
# load data frame in google sheet
import gspread
from google.oauth2.service_account import Credentials
from google.auth import default
# Define the scope of access you need
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds, _ = default()
@devmnj
devmnj / read-google-sheet.js
Created May 22, 2024 15:47
Google Sheet API fetching in Javascript
import {google} from 'googleapis'
export async function getSheetData() {
const auth = new google.auth.GoogleAuth({
credentials: {
client_email: process.env.SERVICE_EMAIL,
private_key: process.env.SERVICE_KEY.replace(/\\n/g, "\n"),
},
scopes: ['https://www.googleapis.com/auth/spreadsheets.readonly']
@devmnj
devmnj / maping_with_typescript.ts
Created February 8, 2024 05:56
Typescript array map to a different type
//target type
export type LatestInvoice = {
id: string;
name: string;
image_url: string;
email: string;
@devmnj
devmnj / REPL.SQL
Created January 23, 2024 10:00
MSSQL REPLACING SINGLE QUOTE
UPDATE TABLE_NAME SET COL1= REPLACE(COL1,'''','"')
@devmnj
devmnj / backgrowndwkr.cs
Created January 22, 2024 17:48
Batchwise data fetching in Dapper-MYSQL, using Background Task in C# - Background worker.
static class BackgroundDataFetcher
{
private static int batchSize = 2;
public static BindingList<LedgerModel> ledgers = new BindingList<LedgerModel>();
public static async Task FetchAsync(int ledId = 0)
{
try
{
@devmnj
devmnj / panda_frame_error.py
Last active January 12, 2024 17:40
Steps to prepare dataframe for Algo in Python
# I encounter proplem while using Historical data
# For yfinance most of the case the data is in good shape
# The first thing I am looking for index column, of numbers. if it exist, need to replace with datetime
# the last thing I want make sure that the date column is in panda datetime type otherwise have to covert it.
df =pd.DataFrame(data['Success'])
df =df[['datetime','open','high','low','close','volume']]
df['datetime']= pd.to_datetime(df['datetime'])
df.set_index('datetime', inplace=True)
@devmnj
devmnj / pandas_xl_read_column.py
Last active December 31, 2023 05:59
Read excel file using Python, specify column range
import pandas as pd
import numpy as np
series=pd.read_excel(r'C:/Users/hp/OneDrive/documents/mahdata.xlsx',sheet_name='EASY', usecols='B:G',header=None,
index_col=False)
series= series.to_numpy()
data = np.flip(series,axis=0)
@devmnj
devmnj / conda-env
Created December 16, 2023 17:11
Anaconda env in Windows
Managing conda environments
It is recommended to install Zipline in an isolated conda environment. Installing Zipline in conda environments will not interfere your default Python deployment or site-packages, which will prevent any possible conflict with your global libraries. For more information on conda environment, see the Conda User Guide.
Assuming conda has been set up, you can create a conda environment:
$ conda create -n env_zipline python=3.10
Now you have set up an isolated environment called env_zipline, a sandbox-like structure to install Zipline. Then you should activate the conda environment by using the command
$ conda activate env_zipline
You can install Zipline by running
@devmnj
devmnj / conda-win11-pshell
Created December 16, 2023 17:10
Conda powershel error fix
Conda Error
`conda error error: argument COMMAND: invalid choice: 'activate'`
# solution
`conda init powershell`