Skip to content

Instantly share code, notes, and snippets.

View ivansaul's full-sized avatar

ivansaul

View GitHub Profile
@ivansaul
ivansaul / SplitRangePDF.py
Created October 15, 2020 15:58
Split PDF by range with Python v3.x and pypdf2
#!/usr/bin/python
from PyPDF2 import PdfFileReader, PdfFileWriter
#split range
pgi=30 #start
pgf=37 #end
pdf_document = "test.pdf"
pdf = PdfFileReader(pdf_document)
pdf_writer = PdfFileWriter()
for page in range(pgi-1,pgf):
@ivansaul
ivansaul / discordDM.py
Last active June 13, 2022 04:14
Welcome direct message discord python
import discord
from discord.ext import commands
#add this line
intents=intents=discord.Intents.all()
#if the above don't work, try with this
#intents = discord.Intents()
#intents.members = True
@ivansaul
ivansaul / GoogleTransPython.py
Last active November 6, 2020 17:56
Fix error in result (AttributeError: 'NoneType' object has no attribute 'group') GoogleTrans Python
'''
After making more than 10,000 queries, I realized that
each successful query takes a maximum of 15 iterations,
taking an average 1 second.
'''
import googletrans
from googletrans import Translator
def en_es(palabra):
translator = Translator()
@ivansaul
ivansaul / CodigoIdiomas.csv
Last active September 16, 2024 15:38
Google translate language codes ISO-639-1 || Códigos de idioma del traductor de Google ISO-639-1
Código ISO-639-1 Idioma
af Afrikáans
sq Albanés
am Amárico
ar Árabe
hy Armenio
az Azerí
eu Vasco
be Bielorruso
bn Bengalí
@ivansaul
ivansaul / split_concat_videos.md
Last active November 10, 2020 17:53
Split and Concat Videos With this Python Script

MoviePy

Source: MoviePy

Installation:

pip install moviepy

Python script:

from moviepy.editor import VideoFileClip, concatenate_videoclips
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 5.
Rank,Title,Genre,Description,Director,Actors,Year,Runtime (Minutes),Rating,Votes,Revenue (Millions),Metascore
1,Guardians of the Galaxy,"Action,Adventure,Sci-Fi",A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.,James Gunn,"Chris Pratt, Vin Diesel, Bradley Cooper, Zoe Saldana",2014,121,8.1,757074,333.13,76
2,Prometheus,"Adventure,Mystery,Sci-Fi","Following clues to the origin of mankind, a team finds a structure on a distant moon, but they soon realize they are not alone.",Ridley Scott,"Noomi Rapace, Logan Marshall-Green, Michael Fassbender, Charlize Theron",2012,124,7,485820,126.46,65
3,Split,"Horror,Thriller",Three girls are kidnapped by a man with a diagnosed 23 distinct personalities. They must try to escape before the apparent emergence of a frightful new 24th.,M. Night Shyamalan,"James McAvoy, Anya Taylor-Joy, Haley Lu Richardson, Jessica Sula",2016,117,7.3,157606,138.12,62
4,Sing,"Animation,Comedy,Family","In a city of humano
@ivansaul
ivansaul / read_excel_from_git_lab.py
Created February 7, 2021 04:31
Read Excel file (.xlsx) into pandas data frame from GitLab url
import pandas as pd
import requests
url= 'https://gitlab.com/username/repo/-/raw/master/data.xlsx'
myfile = requests.get(url)
df=pd.read_excel(myfile.content)
print(df)
@ivansaul
ivansaul / google_sheets.py
Created February 11, 2021 08:28
Simplest Way of Reading Google Sheets into a Pandas Dataframe (Python)
import pandas as pd
#Create a public URL
#https://docs.google.com/spreadsheets/d/0Ak1ecr7i0wotdGJmTURJRnZLYlV3M2daNTRubTdwTXc/edit?usp=sharing
#get spreadsheets key from url
gsheetkey = "0Ak1ecr7i0wotdGJmTURJRnZLYlV3M2daNTRubTdwTXc"
#sheet name
sheet_name = 'Sheet 1'
@ivansaul
ivansaul / fish_alias.md
Last active February 21, 2021 03:21
Create alias in Fish shell and save this as a permanent.

First method

A fish alias is actually implemented as a function. To save a function, you need funcsave. So this is the sequence

alias foo=bar
funcsave foo

That creates ~/.config/fish/functions/foo.fish which will then be available in any fish session.

Second method

I prefer this method so that I can easily edit my aliases in a single file.

@ivansaul
ivansaul / get_youtube_id.py
Last active November 5, 2024 16:43
Python: Get youtube id | Extract Video id from a Youtube url
#pip install pytube
#Examples
url1='http://youtu.be/SA2iWivDJiE'
url2='http://www.youtube.com/watch?v=_oPAwA_Udwc&feature=feedu'
url3='http://www.youtube.com/embed/SA2iWivDJiE'
url4='http://www.youtube.com/v/SA2iWivDJiE?version=3&hl=en_US'
url5='https://www.youtube.com/watch?v=rTHlyTphWP0&index=6&list=PLjeDyYvG6-40qawYNR4juzvSOg-ezZ2a6'
url6='youtube.com/watch?v=_lOT2p_FCvA'
url7='youtu.be/watch?v=_lOT2p_FCvA'