ghodawalaaman

joined 3 months ago
[–] ghodawalaaman@programming.dev 1 points 2 weeks ago (1 children)

that's exactly what happened with recent project I worked with it's https://spaidyslabs.com/ if you are interested. we just shove whatever worked at the time of developing it and now it just a mess!

no policies protecting the supabase, all the supabase calls are coming from client instead of the backend which makes it so difficult to make it secure. 😭

at this point I think we need a entire rewrite of the database and the nextjs code which takes time and effort 😭😭😭

[–] ghodawalaaman@programming.dev 1 points 2 weeks ago (1 children)

What policies are preventing users from inserting data? okay, I just got confused there for a bit actually what's happening is that I have created a policy on SELECT to prevent other users from accessing data of other users and it looks something like auth.uid() = user_id. iirc the policy to prevent INSERT looks something like this: auth.role() = 'authenticated'::text() so yeah only authenticated users can insert data but that doesn't guaranty that client/user/browser will insert correct data.

If you are asking this question then you very likely should not be doing what you’re doing. yes, I know that's why I am asking for suggestions, I don't have much experience in either supabase or Nextjs but I am learning :)

There are ways to do it safely, but it’s for very very specific circumstances, with very very specific security setups. okay, so what do you suggest I should do. I can't just shove more policies into the supabase to make it secure I think so the only way to make it secure is to have the server ( vercel ) do all the supabase calls and don't share the supabase url so that the client can't just query supabase. but again the reason I am not doing this is that it will require a very big refactor throughout the codebase. ( which I am terrified of T.T )

[–] ghodawalaaman@programming.dev 2 points 1 month ago (1 children)

Oh so that's why I was seeing a lot of post from that account, I thought they were generous😨

[–] ghodawalaaman@programming.dev 4 points 3 months ago

Wow thanks for the mini tutorial :)

 

Hello o/

I have been trying to get my forth interpreter working but I can't even parse it properly without error. here is what I have done so for ( it's my 3rd attempt ). if you know any good resources to learn compiler design then please link it. Thank you in advance!

namespace test;

public enum TokenType
{
    Number,
    Operator,
    String,
    Identifier,
    FunctionStart,
    FunctionEnd,
}
public class Token
{
    public TokenType Type { get; set; }
    public string Value { get; set; }

    public override string ToString()
    {
        return $"{Type}: {Value}";
    }
}

public class Program
{
    public static void Err()
    {
        Console.WriteLine("error");
    }
    public static void Main(string[] args)
    {
        string code = "12 12  : abc 10 . ;          23 - + ";

        List<Token> tokens = new List<Token>();
        bool stringMode = false;
        int startStringIndex = 0;
        for (int cur = 0; cur < code.Length; cur++)
        {
            char ch = code[cur];
            if (stringMode)
            {
                if (ch == '"' && code[cur-1] != '\\')
                {
                    stringMode = false;
                    string strValue = code.Substring(startStringIndex, cur - startStringIndex);
                    tokens.Add(new Token { Type = TokenType.String, Value = strValue });
                }
            }
            switch (ch)
            {
                case '+':
                case '-':
                case '*':
                case '/':
                    {
                        tokens.Add(new Token { Type = TokenType.Operator, Value = ch.ToString() });
                        break;
                    }
                case '.':
                    {
                        if (cur + 1 < code.Length && code[cur+1] == '"') 
                        {
                            stringMode = true;
                            cur+=2; // Skip the opening quote
                            startStringIndex = cur;
                        } else
                        {
                            tokens.Add(new Token { Type = TokenType.Operator, Value = ch.ToString() });
                        }
                        break;
                    }
                case >= '0' and <= '9':
                    {
                        int start = cur;
                        while (cur + 1 < code.Length && code[cur + 1] >= '0' && code[cur + 1] <= '9')
                        {
                            cur++;
                        }
                        string numberValue = code.Substring(start, cur - start + 1);
                        tokens.Add(new Token { Type = TokenType.Number, Value = numberValue });
                        break;
                    }
                case (>= 'a' and <= 'z') or (>= 'A' and <= 'Z'):
                    {
                        int start = cur;
                        while (cur + 1 < code.Length && ((code[cur + 1] >= 'a' && code[cur + 1] <= 'z') || (code[cur + 1] >= 'A' && code[cur + 1] <= 'Z') || (code[cur + 1] >= '0' && code[cur + 1] <= '9') || code[cur + 1] == '_'))
                        {
                            cur++;
                        }
                        string identifierValue = code.Substring(start, cur - start + 1);
                        tokens.Add(new Token { Type = TokenType.Identifier, Value = identifierValue });
                        break;
                    }
                case ':':
                    {
                        tokens.Add(new Token { Type = TokenType.FunctionStart, Value = ch.ToString() });
                        break;
                    }
                case ';':
                    {
                        tokens.Add(new Token { Type = TokenType.FunctionEnd, Value = ch.ToString() });
                        break;
                    }
                case ' ':
                case '\n':
                    {
                        break;
                    }
                default:
                    {
                        Err();
                        Console.WriteLine("Something went wrong!");
                        break;
                    }
            }
        }

        foreach (var token in tokens)
        {
            Console.WriteLine(token);
        }
    }
}

[–] ghodawalaaman@programming.dev 1 points 3 months ago

C# ( c sharp )

using System.Collections;
using System.Collections.Generic;

namespace ConsoleApp1
{
    public static class Program
    {
        public static void Part1()
        {
            var lines = File.ReadAllLines("C:\\Users\\aman\\RiderProjects\\ConsoleApp1\\ConsoleApp1\\input.txt");
            var dialReading = 50;
            int result = 0;
            foreach (var line in lines)
            {
                if (dialReading == 0)
                {
                    result += 1;
                }
                char dir = line[0];
                int rotation =  int.Parse(line.Substring(1));
                if (dir == 'R')
                {
                    dialReading += rotation;
                    dialReading %= 100;
                }
                else
                {
                    int diff = dialReading - rotation;
                    if (diff > 0)
                    {
                        dialReading -= rotation;
                        dialReading %= 100;
                    }
                    else
                    {
                        dialReading = dialReading + 100 - rotation;
                        dialReading %= 100;
                    }
                }
            }

            Console.WriteLine(result);
        }

        public static void Part2()
        {
            var lines = File.ReadAllLines("C:\\Users\\aman\\RiderProjects\\ConsoleApp1\\ConsoleApp1\\input.txt");
            var dialReading = 50;
            int result = 0;
            foreach (var line in lines)
            {
                char dir = line[0];
                int rotation =  int.Parse(line.Substring(1));
                if (dir == 'R')
                {
                    while (rotation > 0)
                    {
                        if (dialReading == 0)
                            result += 1;
                        dialReading += 1;
                        dialReading %= 100;
                        rotation -= 1;
                    }
                }
                else
                {
                    while (rotation > 0)
                    {
                        if (dialReading == 0)
                            result += 1;
                        dialReading -= 1;
                        if ( dialReading < 0)
                            dialReading += 100;
                        dialReading %= 100;
                        rotation -= 1;
                    }
                }
            }

            Console.WriteLine(result);
        }
        public static void Main(string[] args)
        {
            Part1();
            Part2();
        }
    }
}
 

Hello,

I have been trying to learn c# from dotnet tutorial and they gave this code which supposed to trigger garbage collector and in turn call the Destructor of the class. however when I run the same code, I get result of Constructor only and not the Destructor.

using System;
namespace DestructorExample
{
    class DestructorDemo
    {
        public DestructorDemo()
        {
            Console.WriteLine("Constructor Object Created");
        }
        ~DestructorDemo()
        {
            string type = GetType().Name;
            Console.WriteLine($"Object {type} is Destroyed");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            DestructorDemo obj1 = new DestructorDemo();
            DestructorDemo obj2 = new DestructorDemo();

            //Making obj1 for Garbage Collection
            obj1 = null;
            GC.Collect();
            Console.ReadKey();
        }
    }
}

here is the code, if you know please tell me why it's not working

[–] ghodawalaaman@programming.dev 27 points 3 months ago (9 children)

Windows + Visual Studio :(

view more: ‹ prev next ›