Skip to content

Instantly share code, notes, and snippets.

View ronaldaug's full-sized avatar
💻
Working from home

Ronald ronaldaug

💻
Working from home
View GitHub Profile
@ronaldaug
ronaldaug / fourpolicies.sql
Created April 18, 2025 07:20
Four policies per table
-- Read
create policy "Allow authorized read access"
on leaves for select
to authenticated
using (authorize('leaves.read'));
-- Create
create policy "Allow authorized create access"
on leaves for insert
to authenticated
@ronaldaug
ronaldaug / authorize.sql
Last active April 18, 2025 12:19
authorize method
create or replace function authorize(resource_action text) returns boolean as $$
declare
v_user_id uuid;
v_role_id int;
v_resource text;
v_action text;
v_has_permission boolean := false;
v_is_admin boolean := false;
begin
-- Get current user's ID from Supabase Auth

users table

Column Type
id PK
user_id uuid (from Supabase Auth)

roles table

| Column | Type |

@ronaldaug
ronaldaug / policices.sql
Last active April 18, 2025 07:13
messy policies
-- Table: leaves
create policy "admin can delete" on leaves for delete using (...);
create policy "manager can update" on leaves for update using (...);
create policy "employee can read" on leaves for select using (...);
@ronaldaug
ronaldaug / cunit.md
Last active September 20, 2023 04:55
Units Convertor For Any Units - Javascript

CUnit

CUnit - Convert any units.

The below example shows calculating cigaratte, pack, cartoon and box. You can add any units to data_array and calculate among units.

const data_array = [
  {
    unit: "cigaratte",
@ronaldaug
ronaldaug / shan-git-cheat-sheet.md
Last active January 14, 2022 03:26
Shan Git Cheat Sheet
@ronaldaug
ronaldaug / auth.md
Last active September 8, 2021 08:43
Simple PHP session login for web pages

Simple PHP session login for web pages

Installation

  1. Create a file call auth.php with below codes.
  2. Require at the top of the page you want to protect like require_once("auth.php");;
  3. Done.
<?php
@ronaldaug
ronaldaug / useful-node.md
Last active April 26, 2023 10:22
Useful Nodejs functions without dependencies

Prompt to get the value

const { stdin, stdout } = process;

// Prompt function
function prompt(question) {
  return new Promise((resolve, reject) => {
    stdin.resume();
@ronaldaug
ronaldaug / upload.md
Created November 25, 2020 15:19
Upload files via Cockpit CMS API
Upload via Javascript (AJAX)

HTML

<input type="file" name="myFile" id="myFile">
      <button class="upload">Upload</button><br>
@ronaldaug
ronaldaug / partial.md
Created July 1, 2020 05:53
Import Partial HTMLs (client side)

Create index.html , sidebar.html and footer.html

index.html

    <sidebar class="partial"></sidebar>

    <footer class="partial"></footer>