Skip to content

Instantly share code, notes, and snippets.

View dinizgb's full-sized avatar

Gabriel Diniz dinizgb

View GitHub Profile
@dinizgb
dinizgb / getLastDatesWithinPeriod.ts
Last active June 30, 2023 16:15
Javascript function to get last dates within a determined period.
/**
* Function to get last dates within a determined period
* @param {Number} period - With the period
* @returns {Array} With an Array with dates in ISO format (YYYY-MM-DDTHH:MM:SS.sssZ) as string
*/
export const getLastDatesWithinPeriod = (period: number): Array<string> => {
const today = new Date();
const days = [];
for (let i = 0; i < period; i++) {
const day = new Date(today);
@dinizgb
dinizgb / differenceInDays.ts
Created June 30, 2023 14:35
Javascript function to get the difference in Days between two dates.
/**
* Function to get the difference in Days between two dates
* @param {string} date1 - With the date 1 (With at least yyyy-mm-dd date format)
* @param {number} date2 - With the date 2 (With at least yyyy-mm-dd date format)
* @returns {number} With the difference in days
*/
export const differenceInDays = (date1: string, date2: string): number => {
const d1 = new Date(date1);
const d2 = new Date(date2);
const timeDiff = d2.getTime() - d1.getTime();
@dinizgb
dinizgb / addOrDecreaseDaysToDate.ts
Last active June 30, 2023 14:36
Javascript function to add or decrease days to a date.
/**
* Function to add or decrease days to a date
* @param {string} date - With the date (With at least yyyy-mm-dd date format)
* @param {number} days - With the days
* @param {boolean} action - True to increase days or false to decrease days
* @returns {string} With the the new date
*/
export const addOrDecreaseDaysToDate = (date: string, days: number, action: boolean): string => {
const result = new Date(date);
action ? result.setDate(result.getDate() + days) : result.setDate(result.getDate() - days);
@dinizgb
dinizgb / react-indiana-drag-scroll-default-usage
Created April 6, 2022 20:18
React Indiana Drag Scroll Default Usage
import React, { Component } from 'react';
import styled from 'styled-components';
import ScrollContainer from 'react-indiana-drag-scroll';
const MenuSticky = styled.div`
width: 100%;
padding: 10px 0;
display: -moz-box;
display: -webkit-box;
top: 0;
//Clone the full project on: https://github.com/dinizgb/nextjs-weather-widget-with-styled-components
import React, { useState, useEffect } from "react";
import Image from 'next/image';
import styled from 'styled-components';
const WeatherWidgetWrapper = styled.div`
min-width: 250px;
background: #fff;
border: 1px solid #e8eaff;
//Clone the full project on: https://github.com/dinizgb/nextjs-weather-widget-with-styled-components
import React, { useState, useEffect } from "react";
import Image from 'next/image';
import styled from 'styled-components';
const WeatherWidgetWrapper = styled.div`
min-width: 250px;
background: #fff;
border: 1px solid #e8eaff;
//Clone the full project on: https://github.com/dinizgb/nextjs-weather-widget-with-styled-components
import React, { useState, useEffect } from "react";
import Image from 'next/image';
import styled from 'styled-components';
const WeatherWidgetWrapper = styled.div`
min-width: 250px;
background: #fff;
border: 1px solid #e8eaff;
<?php
/*
Script: Get URL Parts in PHP
Author: Gabriel Diniz
*/
$url = 'https://www.example.com/pathname?queryname=googley';
//FULL PARSING
var_dump(parse_url($url));
@dinizgb
dinizgb / php-stock-market-web-scraping.php
Created July 23, 2021 20:59
Web scraping with PHP
<?php
/*
Project: PHP stock market web scraping
Author: Gabriel Diniz
Version: 1.0
*/
require_once( __DIR__ . '/simple_html_dom.php' );
$stock = file_get_html('https://br.advfn.com/mundo/brasil');