Skip to content

Instantly share code, notes, and snippets.

View supix's full-sized avatar

supix supix

View GitHub Profile
@supix
supix / postgres_recovery.md
Last active March 1, 2024 22:58
Postgres error: Missing chunk 0 for toast value in pg_toast

The problem

In some cases, it is possible that PostgreSQL tables get corrupted. This can happen in case of hardware failures (e.g. hard disk drives with write-back cache enabled, RAID controllers with faulty/worn out battery backup, etc.), as clearly reported in this wiki page. Furthermore, it can happen in case of incorrect setup, as well.

One of the symptoms of such corruptions is the following message:

ERROR: missing chunk number 0 for toast value 123456 in pg_toast_45678

This almost surely indicates that a corrupted chunk is present within a table file. But there is a good way to get rid of it.

@supix
supix / DbContext.cs
Last active December 15, 2022 21:22
Sample C# MongoDb setup
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
namespace Persistence.MongoDB
{
internal class DbContext
@supix
supix / GetLoggedUser.cs
Last active November 15, 2022 17:51
Enabling JWT integration in a net core WebApi project
using Microsoft.AspNetCore.Http;
internal class GetLoggedUser : IGetLoggedUser
{
private readonly IHttpContextAccessor httpContextAccessor;
public GetLoggedUser(IHttpContextAccessor httpContextAccessor)
{
this.httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
}
@supix
supix / CheckCodiceFiscale.cs
Last active October 19, 2022 06:38
Validatore codice fiscale in linguaggio C#
/// <summary>
/// Computes checksum validity on an Italian Fiscal Code
/// </summary>
/// <param name="fiscalCode">The Fiscal Code to be checked</param>
/// <returns>Checksum is valid</returns>
/// <remarks>Checksum routines are at https://en.wikipedia.org/wiki/Italian_fiscal_code_card</remarks>
/// <remarks>Used regular expression is at http://blog.marketto.it/2016/01/regex-validazione-codice-fiscale-con-omocodia/</remarks>
private bool IsFiscalCodeOk(string fiscalCode)
{
const string regex = @"/^(?:[B-DF-HJ-NP-TV-Z](?:[AEIOU]{2}|[AEIOU]X)|[AEIOU]{2}X|[B-DF-HJ-NP-TV-Z]{2}[A-Z]){2}[\dLMNP-V]{2}(?:[A-EHLMPR-T](?:[04LQ][1-9MNP-V]|[1256LMRS][\dLMNP-V])|[DHPS][37PT][0L]|[ACELMRT][37PT][01LM])(?:[A-MZ][1-9MNP-V][\dLMNP-V]{2}|[A-M][0L](?:[\dLMNP-V][1-9MNP-V]|[1-9MNP-V][0L]))[A-Z]$/i";
@supix
supix / gather_kernel_version.yaml
Last active March 21, 2022 15:40
Ansible playbook useful to gather the host kernel version
---
- name: gather kernel version
hosts: all
vars:
filename: /tmp/kernelv.txt
dst_folder: /tmp/hosts
tasks:
- name: delete the centralized file
@supix
supix / grep.yaml
Last active March 21, 2022 15:36
Check whether a string is found through grep
---
- name: Check if a string is found through grep
hosts: all
vars:
filename: /tmp/rc.txt
dst_folder: /tmp/hosts
tasks:
- name: delete the centralized file
@supix
supix / yum
Created July 29, 2021 09:11
yum command to find all the CVEs a system is affected by
yum updateinfo list cves
@supix
supix / developmentResources.md
Last active November 4, 2020 15:41
Useful development resource
@supix
supix / pg_create_db_users
Last active August 1, 2019 05:26
Create new postgres database with owner and app user
psql -U postgres
create database myNewDB;
create user myNewDB_web;
create user myNewDB_owner;
ALTER USER myNewDB_web WITH PASSWORD 'pwd';
ALTER USER myNewDB_owner WITH PASSWORD 'pwd';
psql -U postgres -d myNewDB
@supix
supix / create_mongodb_users
Last active February 18, 2019 21:37
Create read-only, read-write and owner-user users on mongodb database
use myDbName
// drop users
db.dropUser("ro_user");
db.dropUser("rw_user");
db.dropUser("owner_user");
// read-only user
db.createUser({
user: "ro_user",