Skip to content

Instantly share code, notes, and snippets.

View Micrified's full-sized avatar
🇫🇷
Collating...

Micrified

🇫🇷
Collating...
  • Rotterdam, Nederlands
View GitHub Profile
@Micrified
Micrified / hook_example_permissions.md
Last active November 11, 2024 22:56
Hook Example

Hook based example

The following example uses a User-Role relation in order to codify the more complex permission behavior required for Activites. The relation allows both:

  1. A hierarchical page structure for organizing permissions
  2. Fine-grained rules around page permissions, no matter their position in the hierarchy.

Basics

We begin by defining a Role type listing all possible roles that a user may have in Activities. Furthermore, we define the Perm type to enumerate possible permissions

@Micrified
Micrified / permissions_users.md
Last active October 23, 2024 17:29
Permissions & Users

The following product requirements cause implementation challenges:

  1. Authentication via third party providers
  2. No storage of user credentials
  3. Access to the Wagtail CMS

The contradiction

A key stakeholder requirement is that users login via third-party services. This means:

  1. The credentials are handled and stored by the identity provider
  2. We only receive the user identity, and an affirmation of their authenticity.
@Micrified
Micrified / adapter.go
Created June 6, 2024 23:19
Wrapping interface methods
package main
import (
"fmt"
"encoding/json"
)
func ExpectJSON [T any] (b []byte) (T, error) {
var (
err error
// Online Go compiler to run Golang program online
// Print "Try programiz.pro" message
package main
import "fmt"
// ---
type Restful interface {
Get() string
@Micrified
Micrified / fail.go
Last active April 23, 2024 06:00
Yet another fail
package main
import "fmt"
type R interface {
A() string
B() string
}
type C interface {
R
Method(string) func(C)string
@Micrified
Micrified / sensor_reader.cpp
Created April 21, 2024 09:59
Safe sensor example
#include <chrono>
#include <cstdlib>
#include <iostream>
#include <ratio>
#include <string>
#include <thread>
#include <vector>
#include <mutex>
// [ Written to C++11 standard ]
@Micrified
Micrified / syncmap.go
Last active March 10, 2024 18:26
Generic channel-synchronised map (Golang)
// Note: Use mutexes people
package main
import (
"fmt"
"sync"
)
// generic type: response
type re [T comparable, U any] struct {
@Micrified
Micrified / generic_struct_composition.go
Last active March 10, 2024 18:26
Generic struct composition
package main
import "fmt"
import "encoding/json"
import "bytes"
type AuthPost [T any] struct {
UserID string `json:"userid"`
SID string `json:"sid"`
Data T `json:"data"`
}
@Micrified
Micrified / comma-in-c.md
Created February 6, 2024 08:12
Comma operator in C if-statements

Comma Operator

In C and C++, the comma operator is a binary operator that:

  1. Evaluates the first operand, and discards the result
  2. Evalutes the second operand, and returns this value

So:

if (a,b) {
@Micrified
Micrified / parallel.go
Last active January 29, 2024 22:32
Parallel MD5 hasher (to be compared)
package main
// Continue here: https://go.dev/blog/pipelines
import (
"crypto/md5"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
"sync"