Skip to content

Instantly share code, notes, and snippets.

View GabrielModog's full-sized avatar
🤠

Gabriel Tavares GabrielModog

🤠
View GitHub Profile
import moviepy.editor as mp
clip = mp.VideoFileClip(r"path/to/file.mp4")
clip.audio.write_audiofile(r"path/to/file.mp3")
@GabrielModog
GabrielModog / naive-text-search.js
Created April 11, 2023 08:09
naive pattern search algorithm
function naiveSearch(pattern, str){
const P = pattern.length, TXT = str.length
for(let i = 0; i <= P + TXT; i++){
let pivot
for(pivot = 0; pivot < P; pivot++){
if(str[i + pivot] !== pattern[pivot])
break
}
if(pivot == P){
return i
@GabrielModog
GabrielModog / chatgpt-cli.js
Created March 20, 2023 14:41
chatgpt cli from scratch thing
if (process.argv.length <= 2) {
console.error("Expected arguments");
process.exit(1);
}
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
// maybe will not work properly
function convertMarkdownToObject(table) {
const rows = table.trim().split('\n');
const headerRow = rows.shift().replace(/\|/g, '').trim();
const columns = headerRow.split(/\s+/);
const objects = rows.map(row => {
const cells = row.split('|').map(cell => cell.trim());
return columns.reduce((obj, col, i) => {
@GabrielModog
GabrielModog / convert-to-markdown-table.js
Last active March 13, 2023 10:55
this script converts a weird .ini table from grand fantasia to markdown table
// working by need some adjusments
function convertToMarkdownTable(data){
const rows = data.trim().split('\n');
const tableHeader = Array.from({ length: 41 }, (_, i) => `Column ${i + 1}`);
const tableSeparator = tableHeader.map(() => '---');
const headerRow = `| ${tableHeader.join(' | ')} |`;
const separatorRow = `| ${tableSeparator.join(' | ')} |`;
const bodyRows = rows.map(row => {
const cells = row.split('|').map(cell => cell.trim());
const chain = () => ({
value: "",
counter: 0,
increment(x){
this.counter += x
return this
},
setValue(newValue){
this.value = newValue
return this
@GabrielModog
GabrielModog / write-wave-file.rs
Last active March 19, 2023 05:01
testing wave file write with rust
use std::fs::File;
use std::io::{self, Write};
use std::mem::size_of;
use std::f32::consts::PI;
// wave file structure reference:
// https://ccrma.stanford.edu/courses/422-winter-2014/projects/WaveFormat/#:~:text=A%20WAVE%20file%20is%20often,form%20the%20"Canonical%20form".
// .to_le_bytes() return the memory representation of this integer as a byte array in little-endian byte order. I use as alternative to byteorder
@GabrielModog
GabrielModog / create-wav-file.cpp
Created March 3, 2023 14:07
simple wav file creator with c++
#include <cmath>
#include <fstream>
#include <iostream>
const int sampleRate = 44100;
const int bitDepth = 16;
class SineOscillator {
float frequency, amplitude, angle = 0.0f, offset = 0.0f;
@GabrielModog
GabrielModog / binary-to-text-simple-way.js
Created March 3, 2023 10:01
binary-to-text-simple-way.js
function binaryToText(binString){
let result = ''
for(let item of binString.split(' ')){
const str = parseInt(item, 2)
result += String.fromCharCode(str)
}
return result
}
@GabrielModog
GabrielModog / cli-get-yt-playlist-videos.py
Created February 27, 2023 08:09
command line program in py to get playlist yt videos - pytube it's very buggy
from pytube import Playlist, YouTube, exceptions
import argparse
import os
parser = argparse.ArgumentParser(description="Playlist link")
parser.add_argument("playlist", metavar="playlist", type=str, help="enter your playlist link")
args = parser.parse_args()
playlist = args.playlist
destination = "./audios/"