Skip to content

Instantly share code, notes, and snippets.

View magnum's full-sized avatar
💭
experimenting...

Antonio Molinari magnum

💭
experimenting...
View GitHub Profile
@magnum
magnum / linux-setup.sh
Created April 27, 2024 00:10 — forked from dhh/linux-setup.sh
linux-setup.sh
# CLI
sudo apt update -y
sudo apt install -y \
git curl docker.io \
build-essential pkg-config autoconf bison rustc cargo clang \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc2 \
libvips imagemagick libmagickwand-dev \
redis-tools sqlite3 libsqlite3-0 libmysqlclient-dev \
rbenv apache2-utils
async function fetchNFTsOwnedByUser() {
const transferEvents = await nftContract.queryFilter({
address: nftContractAddress,
topics: [
ethers.utils.id("Transfer(address,address,uint256)"),
null,
ethers.utils.hexZeroPad(userWalletAddress, 32)
]
});

Do not use forEach with async-await

TLDR: Use for...of instead of forEach() in asynchronous code.

For legacy browsers, use for...i or [].reduce()

To execute the promises in parallel, use Promise.all([].map(...))

The problem

@magnum
magnum / google_sheet_invoices_and_times_appscript.js
Last active December 8, 2023 16:46
google sheets appscript to retrieve invoices from fattureincloud and times from toggl
/*
references
fattureincloud
https://developers.fattureincloud.it/api-reference/#get-/c/-company_id-/issued_documents
toggl
https://developers.track.toggl.com/docs/reports/detailed_reports
*/
@magnum
magnum / gist:e69d34d0e9ebabcbe12ada94c78e9549
Created October 6, 2023 19:25 — forked from Prezens/gist:f99fd28124b5557eb16816229391afee
Apache .htaccess settings for Vue, vue-router
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
function HTTPResponse( uri ) {
var response_code ;
var options = {
'validateHttpsCertificates' : false
};
try {
response_code = UrlFetchApp .fetch( uri, options ) .getResponseCode() .toString() ;
}
catch( error ) {
response_code = error .toString() //.match( / returned code (\d\d\d)\./ )[1] ;
<?php
function cache_fetch($key, $group='', $callable, $expiration=0) {
$value = wp_cache_get($key, $group);
if(!$value) {
$value = $callable();
wp_cache_set($key, $value, $group, $expiration);
}
return $value;
}
@magnum
magnum / list_drupal7_modules.js
Created March 1, 2023 17:21
list drupal7 modules
(function($){
const data = [];
$("fieldset").each(function(i,elCategory){
const category = $(elCategory).find('.fieldset-title').text().replace("Nascondi ", "");
$(elCategory).find("tr").each(function(i,elModule){
const title = $(elModule).find("strong").text();
const active = $(elModule).find("input[type='checkbox']:checked");
data.push({
category: category,
title: title,
@magnum
magnum / dotenv.php
Created December 16, 2022 15:01
dotenv support in php, eg. wordpress
<?php
try {
require_once 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createUnsafeImmutable('./');
$dotenv->load();
} catch (Exception $e) {
echo(implode("<br>", array(
("Caught exception: ".$e->getMessage()."<br>"),
"please be sure to install .env support package with 'composer require vlucas/phpdotenv'",
"and that a .env is present"

Keybase proof

I hereby claim:

  • I am magnum on github.
  • I am amolinari (https://keybase.io/amolinari) on keybase.
  • I have a public key ASAw8G94hH7MRkMfAuJ43CJbz7HbY6RnyG-KUv8mpmgrQQo

To claim this, I am signing this object: