Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am farzadhallaji on github.
* I am farzadhallaji (https://keybase.io/farzadhallaji) on keybase.
* I have a public key ASCV8BMpAu47N-Ea8q8vlgLrJDiwUitIiNktf_EDl3x8OQo
To claim this, I am signing this object:
@farzadhallaji
farzadhallaji / req.py
Created March 14, 2019 08:01
sawtooth request
import requests
import json
auth_token = "eyJhbGciOiJIUzUxMiIsImlhdCI6MTU1MjM3MTg3OCwiZXhwIjoxNTUyMzc1NDc4fQ.eyJlbWFpbCI6Im1vaGFtYWQuYWRrNzhAZ21haWwuY29tIiwicHVibGljX2tleSI6IjAyNzk0NGYwOWY3ZDNiYzk2NTkyNWFhZDBmMDdjNDkxZDY4MmU2YjgxOWNlZTY1Yjg5MzY2NzA4NDJjNDIzY2FmMyJ9.vioLHca_WRfq1QK51lxb_WGEOcSxuq9BPkyyz233vM_mVMBptEHOuwui2l9PeCjw86BBFwXzUmvshhn5_bBlZw"
urlP = 'http://212.24.96.236:8040/'
def signup(email,passw,label,des) :
headers = {'Content-type': 'application/json', 'Accept': 'text/plain' , 'Authorization': 'Bearer ' + auth_token}
path = "accounts"
payload = { 'label' : label
@farzadhallaji
farzadhallaji / googlecolab-import-folder.py
Last active January 28, 2023 12:57
import folder on google colab
from google.colab import drive
drive.mount("/content/drive")
import os
path = '/content/drive/My Drive/path_to_folder/' #replace path_to_folder with your desired folder path
os.chdir(path)
@farzadhallaji
farzadhallaji / thundersvm-google-colab.py
Created January 30, 2023 13:37
install thundersvm on google colab
!wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda-repo-ubuntu1704-9-0-local_9.0.176-1_amd64-deb
!dpkg -i cuda-repo-ubuntu1704-9-0-local_9.0.176-1_amd64-deb
!ls /var/cuda-repo-9-0-local | grep .pub
!apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
!apt-get update
!sudo apt-get install cuda-9.0
!pip install thundersvm-cpu
@farzadhallaji
farzadhallaji / read_dat_file.py
Created February 14, 2023 22:50
how to read .dat dataset files in pandas
import re
def read_dot_dat_file(path):
datContent = [i.strip().split() for i in open(path).readlines()]
r = re.compile("@inputs.*")
_at_data = datContent.index(['@data'])
assert datContent[0][0] == '@relation'
assert datContent[_at_data-1][0] == '@outputs'
assert datContent[_at_data-2][0] == '@inputs'
assert len(datContent[_at_data-3][2:]) == 2 # Two Class
@farzadhallaji
farzadhallaji / hvar.py
Created February 18, 2023 22:25
standard deviation for harmonic mean
from scipy.stats import hmean
# https://stats.stackexchange.com/questions/7471/can-the-standard-deviation-be-calculated-for-harmonic-mean
harmonic_var = lambda S : (np.power(S,-1).var())/(len(S)*np.power(np.power(S,-1).mean(),4))
# example
import numpy as np
np.random.seed(100)
s = np.random.dirichlet((1,5),10)
@farzadhallaji
farzadhallaji / Ta-Lib-in-google-colab.py
Created April 30, 2023 00:50
installing Ta-Lib in google colab
!pip uninstall numpy -y
!pip install numpy==1.24.2
!wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
!tar -xzvf ta-lib-0.4.0-src.tar.gz
%cd ta-lib
!./configure --prefix=/usr
!make
!make install
%cd ..
@farzadhallaji
farzadhallaji / videos-duration.py
Created July 17, 2023 19:23
Total duration of all videos
import os
from moviepy.editor import VideoFileClip
folder_path = '/home/ri/Desktop/TFL/ahmadian' # Replace with the path to your folder
total_duration = 0
for file in os.listdir(folder_path):
if file.endswith('.webm'): # Adjust the file extension if necessary
file_path = os.path.join(folder_path, file)
video = VideoFileClip(file_path)
@farzadhallaji
farzadhallaji / trim_video.sh
Last active October 22, 2023 20:29
trim video
#!/bin/bash
# Check if ffmpeg is installed
command -v ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg is required but it's not installed. Exiting."; exit 1; }
# Check for valid number of arguments
if [ "$#" -ne 4 ]; then
echo "Usage: $0 input.mp4 start_time end_time output_base_path"
echo "Time format: HH:MM:SS or MM:SS"
exit 1
@farzadhallaji
farzadhallaji / vocab.py
Last active November 12, 2023 23:43
convert list of words to html file to memrize it
# -*- coding: utf-8 -*-
"""vocab.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1GNxF9QyJc8hL3KgVKB8t4GPgH8sGNTci
"""
# ! pip install google-translate-for-goldendict