Skip to content

Instantly share code, notes, and snippets.

View darioielardi's full-sized avatar
🎯
Focusing

Dario Ielardi darioielardi

🎯
Focusing
View GitHub Profile
@darioielardi
darioielardi / factory-singleton.dart
Last active February 20, 2019 14:44
[Dart Singleton] Different ways to have a singleton in Dart #singleton
class Singleton {
Singleton._internal();
static final Singleton _singleton = new Singleton._internal();
factory Singleton() => _singleton;
}
@darioielardi
darioielardi / quick-sort.dart
Last active February 20, 2019 14:44
[QuickSort] #algorithms
import 'dart:math';
class Quick {
void swap(List<int> arr, int i, int j) {
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
@darioielardi
darioielardi / cpt-tax.php
Last active March 12, 2019 15:22
[WP CPT + Taxonomy + Meta Boxes] Example Wordpress Custom Post Type with Taxonomy and Meta Boxes #wordpress
<?php
// Sedi Custom Post Type
class Sedi_Cpt {
public function __construct()
{
add_action( 'init', array( $this, 'build_custom_post_type' ), 0 );
add_action( 'init', array( $this, 'build_aree_taxonomy' ), 0 );
add_action( "add_meta_boxes", array( $this, "build_meta_boxes" ) );
@darioielardi
darioielardi / Makefile
Created March 13, 2019 22:05
[Makefile for Docker Compose] Common Makefile for Docker Compose #makefile #docker
DC_COMMON = ./config/common/docker-compose.yaml
DC_DEV = ./config/dev/docker-compose.yaml
dev: ${DC_COMMON} ${DC_DEV}
docker-compose -f ${DC_COMMON} -f ${DC_DEV} -p suma up
dev-build: ${DC_COMMON} ${DC_DEV}
docker-compose -f ${DC_COMMON} -f ${DC_DEV} -p suma up --build
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:3.2.1'
}
@darioielardi
darioielardi / pg_get_size.sql
Created September 5, 2019 07:59
[Postgres DB Size] #postgres #sql
SELECT pg_size_pretty( pg_database_size('DB_NAME') );
@darioielardi
darioielardi / script.sh
Created November 6, 2019 18:09
Flutter Flavors Firebase iOS Configuration Build Script
# This script copies the right firebase configuration ( GoogleService-Info.plist file ) for the running flavor.
# It must be run as a Build Phase. It assumes three flavors: "dev", "stage" and "prod".
if [ "${CONFIGURATION}" == "Debug-prod" ] || [ "${CONFIGURATION}" == "Release-prod" ] || [ "${CONFIGURATION}" == "Profile-prod" ];
then
cp -r "${PROJECT_DIR}/Runner/Firebase/prod/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"
elif [ "${CONFIGURATION}" == "Debug-stage" ] || [ "${CONFIGURATION}" == "Release-stage" ] || [ "${CONFIGURATION}" == "Profile-stage" ];
then
cp -r "${PROJECT_DIR}/Runner/Firebase/stage/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"
elif [ "${CONFIGURATION}" == "Debug-dev" ] || [ "${CONFIGURATION}" == "Release-dev" ] || [ "${CONFIGURATION}" == "Profile-dev" ];
@darioielardi
darioielardi / intl.ts
Created January 19, 2022 12:41
nextjs i18n
import { useRouter } from 'next/router';
export const locales = ['it', 'en'] as const;
export type Locale = typeof locales[number];
export const isLocale = (locale: string): locale is Locale => {
return (locales as unknown as string[]).includes(locale);
};
@darioielardi
darioielardi / search-params.ts
Last active January 28, 2022 12:29
nextjs uncontrolled search params hook
import { useRouter } from 'next/router';
import { ParsedUrlQuery, ParsedUrlQueryInput } from 'querystring';
import { useEffect, useMemo, useState } from 'react';
// common defs
export const numParam: ParamDef<number> = {
encode: (value) => value.toString(),
decode: (value) => (typeof value === 'string' && value ? parseInt(value, 10) : undefined),
};
@darioielardi
darioielardi / truncate.ts
Created December 24, 2022 11:51
truncate tables passing entity classes with MikroORM
import { Constructor } from '@mikro-orm/core';
import { EntityManager } from '@mikro-orm/core';
export async function truncate(em: EntityManager, entities: Constructor[]) {
const meta = em.getMetadata();
for (const entity of entities) {
const entityMeta = meta.get(entity.name);
if (!entityMeta) {