Skip to content

Instantly share code, notes, and snippets.

View supix's full-sized avatar

supix supix

View GitHub Profile
@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 / 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 / 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 / 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 / asyncVersion.cs
Last active August 30, 2018 09:57
Simple console application demonstrating how async programming allows to save time
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
internal class Program
{
private static void Main(string[] args)
@supix
supix / postgres_recovery.md
Last active June 6, 2024 18:46
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 / Bayes.md
Last active June 19, 2018 07:11
Applying Bayes Theorem and verifying if through frequentist probability approach

Context

We are in a university campus. There are two faculties: math and business administration. 10% of student are enrolled in math (then, 90% of students are enrolled in business administration). Within math faculty, 75% students are shy. Within business administration, 15% students are shy.

Problem

I see a student, and he is clearly shy. What's the probability that he is enrolled in math faculty?

Theoretical solution through Bayes Theorem

@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 / index.html
Last active May 5, 2018 20:32
Angular template for a website with top nav menu and fixed width
<body>
<div class="topnav">
<a class="active" href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
<div class="content">
<app-root></app-root>