Skip to content

Instantly share code, notes, and snippets.

View Uriel29's full-sized avatar

Uriel dos Santos Souza Uriel29

View GitHub Profile
@Uriel29
Uriel29 / promise_monad.md
Created June 19, 2022 20:00 — forked from VictorTaelin/promise_monad.md
async/await is just the do-notation of the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed too. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing

const listagem = new mongoose.Schema({
nome: { type: String, required: [true, 'Nome'] },
//lista:[{nome:String, sobrenome: String, numeroSerial: Number}],
lista:{type : Array,validate: v => Array.isArray(v) && v.length > 0},
});
const listagemModel = mongoose.model('listagem', listagem);
@Uriel29
Uriel29 / po.js
Created September 14, 2020 18:28
4/5
let n = gets()
for (let i = 0; i < n; i++) {
let t = gets();
let jogoArray = t.split(' ');
let [fernanda, marcia] = jogoArray;
while (true) {
const password = gets();
if (password.length === 0) {
break;
}
checaSenha(password);
}
@Uriel29
Uriel29 / overridecomponente.php
Created March 2, 2019 01:06
Inserir módulos dentro de componentes do Joomla. Em override! Precisei por módulos dentro do blog.php do Joomla e dentro do content, tudo em override.
<?php echo JHtml::_('content.prepare', '{loadposition home-banner}'); ?>
<?php $document = &JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$position = 'home-banner';
$options = array('style' => 'raw');
echo $renderer->render($position, $options, null);
@Uriel29
Uriel29 / app.js
Last active November 8, 2023 01:24
Instalar PWA com botão que aparece assim que o Service esta registrado e o beforeinstallprompt esta funcional! Deixei o botão como none:
window.onload = function() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js').then(function() {
console.log('Service Worker Registered');
});
}
let deferredPrompt;
const addBtn = document.querySelector('#enable-banner-install');
window.addEventListener('beforeinstallprompt', (e) => {
@Uriel29
Uriel29 / postupdate.php
Created January 27, 2019 12:14
coloque na raiz do administrador /admistrator/postupdate.php
<?php
/**
* @package Joomla.Administrator
*
* @copyright Copyright (C) 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* Define the application's minimum supported PHP version as a constant so it can be referenced within the application.
@Uriel29
Uriel29 / php.ini
Created January 15, 2019 12:31
php.ini que modifica as diretivas na Locaweb e outros lugares
[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; This file controls many aspects of PHP's behavior. In order for PHP to
; read it, it must be named 'php.ini'. PHP looks for it in the current
; working directory, in the path designated by the environment variable
; PHPRC, and in the path that was defined in compile time (in that order).
; Under Windows, the compile-time path is the Windows directory. The
1) gift/tmpl/added_items.php
Mudanca para aparecer o botão somente para um grupo de usuários
<?php
$user = JFactory::getUser();
$groups = JUserHelper::getUserGroups($user->id);
if(!in_array('64', $groups))
{
@Uriel29
Uriel29 / listview.php
Last active January 20, 2017 18:39
listview no seblod que mostrasse apenas usuarios que pertencam um grupo especifico > criado por Marcio Garrido
Demanda :
Criar uma listview no seblod que mostrasse apenas usuarios que pertencam um grupo especifico de usuarios no joomla.
No meu sistema , eu precisava mostrar somente na list os usuarios em dia.Estes usuarios, quando em dia faziam parte do grupo chamado "Associacoes Adiplentes" cujo Group_id é 118. Toda vez que um usuario comecava a participar deste grupo, um novo registro na tabela user_usergroup_map_BDEL era atualizado.
Desta forma, criei um campo na tabela users chamado "em_dia" e fiz uma trigger na tabela user_usergroup_map que validava esta a inclusao de usuarios no grupo 118 e retornava esta validacao para a tabela users.
Codigo
1) Alterar a tabela users criando a coluna "em_dia"