Skip to content

Instantly share code, notes, and snippets.

Avatar

supix supix

View GitHub Profile
@supix
supix / developmentResources.md
Last active Nov 4, 2020
Useful development resource
View developmentResources.md
@supix
supix / GetLoggedUser.cs
Last active Mar 19, 2020
Enabling JWT integration in a net core WebApi project
View GetLoggedUser.cs
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 Aug 30, 2018
Simple console application demonstrating how async programming allows to save time
View asyncVersion.cs
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 Nov 24, 2020
Postgres error: Missing chunk 0 for toast value in pg_toast
View postgres_recovery.md

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 Jun 19, 2018
Applying Bayes Theorem and verifying if through frequentist probability approach
View Bayes.md

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 May 13, 2018
Sample C# MongoDb setup
View DbContext.cs
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
Angular template for a website with top nav menu and fixed width
View index.html
<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>
@supix
supix / create_mongodb_users
Last active Feb 18, 2019
Create read-only, read-write and owner-user users on mongodb database
View create_mongodb_users
use myDbName
// drop users
db.dropUser("ro_user");
db.dropUser("rw_user");
db.dropUser("owner_user");
// read-only user
db.createUser({
user: "ro_user",
@supix
supix / pg_create_db_users
Last active Aug 1, 2019
Create new postgres database with owner and app user
View pg_create_db_users
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 / Web.Config
Last active Jun 14, 2018
Portable way to instantiate a log4net logger throughout all classes
View Web.Config
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
You can’t perform that action at this time.