Skip to content

Instantly share code, notes, and snippets.

View silvericarus's full-sized avatar
💭
Remembering past moments

Alberto González Rosa silvericarus

💭
Remembering past moments
View GitHub Profile
@silvericarus
silvericarus / download_folder_organizer.py
Created December 9, 2024 01:57
Python function to organize a folder and categorize it
import os
import shutil
def organize_files():
downloads_folder = os.path.join(os.path.expanduser("~"), "Downloads")
subfolders = {
"Images": [".jpeg", ".jpg", ".tiff", ".gif", ".bmp", ".png", ".bpg", ".svg", ".heif", ".psd"],
"Videos": [".avi", ".flv", ".wmv", ".mov", ".mp4", ".webm", ".vob", ".mng", ".qt", ".mpg", ".mpeg", ".3gp"],
"Documents": [".pdf", ".oxps", ".epub", ".pages", ".docx", ".doc", ".fdf", ".ods", ".odt", ".pwi", ".xsn", ".xps", ".dotx", ".docm", ".dox", ".rvg", ".rtf", ".rtfd", ".wpd", ".xls", ".xlsx", ".ppt", ".pptx"],
@silvericarus
silvericarus / binary_search.c
Last active December 16, 2022 21:34
C function that searchs for a number in an array with the 'binary search' algorithm
int binary_search(int* nums, int numsSize, int target){
int middle;
int min;
int max;
middle = numsSize / 2;
if (target < nums[middle])
{
min = 0;
max = middle;
@silvericarus
silvericarus / two_sum.js
Last active September 9, 2023 17:46
Javascript function that given an array of numbers, find the first two ones that sum to the target, and returns the positions.
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
const sum = [];
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {
@silvericarus
silvericarus / first_single_char.c
Created December 4, 2022 23:45
C function that takes a string and returns the index of the first unrepeated character, if it doesn't find any unique character, it returns -1
int str_len(char *s)
{
int i;
i = 0;
while(s[i] != '\0')
i++;
return (i);
}
@silvericarus
silvericarus / steps_to_zero.c
Created December 1, 2022 23:48
C function that takes a number and calculates the number of steps needed to convert that number into 0.
//If the number is even, you divide it by 2, if it's odd, you subtract one from the number. That's the possible steps.
int numberOfSteps(int num){
static int steps = 0;
int tmp = 0;
int firstCall;
firstCall = 0;
if (num % 2 == 0 && num != 0)
{
if(steps == 0)
@silvericarus
silvericarus / richest_customer_wealth.c
Created November 20, 2022 01:31
C function that takes a matrix of accounts, the number of accounts, and an array with the size of each account, and returns the wealth of the richest wealth included in the matrix.
int max_wealth(int** accounts, int accountsSize, int* accountsColSize){
int mainWealth;
int tmpW;
int i;
int j;
i = 0;
mainWealth = 0;
tmpW = 0;
while(i < accountsSize)
@silvericarus
silvericarus / lst_middle_node.c
Created November 20, 2022 00:33
C function that counts the elements in a linked list and returns the middle element.
int ft_lstsize(struct ListNode *lst)
{
int index;
index = 0;
while (lst)
{
index++;
lst = lst->next;
}
@silvericarus
silvericarus / roman_to_int.c
Last active November 19, 2022 00:40
C function that takes a string with the valid roman numerals (IVXLCDM) and return the integer that those numerals represent
int romanToInt(char *s){
int i;
int num;
num = 0;
i = 0;
while(s[i] != '\0')
{
if(s[i] == 'I')
{
if(s[i + 1] == 'V')
@silvericarus
silvericarus / ft_strbinarybase.c
Created June 21, 2022 22:53
C function that returns the binary result of each character in a string.
#include <stdio.h>
#include <unistd.h>
void print_char_bnry(unsigned char c)
{
int i;
char c_tmp;
i = 8;
while (--i >= 0)
@silvericarus
silvericarus / zipper_merge.js
Last active April 23, 2019 19:34
JS function for merging two arrays into another array double the length with its elements being the originals entwined like a zipper.
function zipper_merge(array1, array2) {
if (array1.length != array2.length) {
return null;
}
var array3 = {};
var count = 0;
var pos = 0;
while(pos<array1.length*2){
array3[pos]=array1[count];