Skip to content

Instantly share code, notes, and snippets.

View russo97's full-sized avatar
🏠
Working from home

Wanderson Silva russo97

🏠
Working from home
View GitHub Profile
@russo97
russo97 / getCookie.js
Created March 3, 2024 00:43
get cookie from browser if its exists
/**
*
* @param name {string}
* @returns {string | false}
*/
function getCookie (name) {
const selectedCookie = document.cookie
.split(COOKIE_SEPARATOR)
.find(cookie => {
const { name: cookieName } = splitCookie(cookie)
@russo97
russo97 / setCookie.js
Created March 2, 2024 01:23
setCookie using a custom JS function
/**
* @typedef {Object} cookieOptions
* @property {Date} expires - optional
* @property {boolean} secure - optional
* @property {'None' | 'Lax' | 'Strict'} sameSite - optional
* @property {string} path - optional
* @property {string} domain - optional
* @property {boolean} httpOnly - optional
*/
@russo97
russo97 / settings.json
Created January 15, 2024 12:21
settings for VSCode Live Sass Compiler
{
"liveSassCompile.settings.forceBaseDirectory": "",
"liveSassCompile.settings.formats": [
{
"format": "compressed",
"extensionName": ".min.css",
"savePath": "~/../css/"
}
]
}
@russo97
russo97 / current-time-events.html
Created October 31, 2023 12:47 — forked from andrebian/current-time-events.html
Youtube iframe API - Eventos baseado no tempo atual do video (current time events)
<div id="player" data-video-id="ZZ5LpwO-An4"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
var tag = document.createElement('script');
var firstScriptTag = document.getElementsByTagName('script')[0];
// O container do video
var playerDiv = $('#player');
@russo97
russo97 / computed.js
Created August 16, 2023 00:02
generate a clamp for a range of page indexes
const clampedPaginatedIndex = computed(() => {
const page = parseInt(response.products?.page ?? 1);
const lastPage = response.products?.last_page ?? 1;
const clampRange = Math.min(5, lastPage);
const offset = Math.max(0, Math.min(page - Math.ceil(clampRange / 2), lastPage - clampRange));
return Array.from({ length: clampRange }, (_, index) => offset + index + 1);
});
@russo97
russo97 / makeConversion.js
Created July 20, 2023 12:49
get data from form and send them to your RDStation account
//API e Código de integração
<script type="text/javascript" src="https://d335luupugsy2.cloudfront.net/js/integration/stable/rd-js-integration.min.js"></script>
//Este código de integração é encontrado nos dados da conta no painel do RD
<script type="text/javascript" async src="https://d335luupugsy2.cloudfront.net/js/loader-scripts/5d1f5125-2ff1-41ad-959d-5b2e3f6a2023-loader.js" >
jQuery('.wpcf7-form').submit(function(e){//é o form - tem que sar a tag form
jQuery('[type="submit"]').attr('disable','disable');//é o botão de envio
e.preventDefault();
var postdata=jQuery('.wpcf7-form').serializeArray();//é o form - tem que sar a tag form
postdata.push({
@russo97
russo97 / mixins.scss
Created June 6, 2023 03:55
helpers to scss
@mixin sizedBox ($width: 10px, $height: $width) {
width: $width;
height: $height;
}
@mixin clampLines ($lines: 1) {
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: $lines;
@russo97
russo97 / secondsToHours.js
Created April 11, 2023 23:10
converting seconds to an object containing hours, minutes, and seconds, respectively.
const SECONDS_PER_HOUR = 3600;
const SECONDS_PER_MINUTE = 60;
function toFloor (value) {
return Math.floor(value);
}
function secondsToHours (secs) {
const hours = toFloor(secs / SECONDS_PER_HOUR);
@russo97
russo97 / transactions.js
Last active April 5, 2023 00:05 — forked from tiagomatosweb/transactions.js
Desafio #4 - Array de Transações
const transactions = [
{
date: '2023-03-20',
description: 'Restaurante X-Burger',
amount: -30
},
{
date: '2023-03-20',
description: 'Cinema',
@russo97
russo97 / Desafio javascript - #1.js
Last active February 7, 2023 01:43
Resolução do desafio #1 do Tiago Matos, liberado no Instagram
// Faça o calculo do total destes produtos que estão no carrinho
const cart = [
{
name: 'Pizza de calebreza',
amount: 10,
qty: 2,
addons: [
{
'name': 'Extra calabreza',