Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

NtotheTC posted:

I like the idea that some stoner somewhere has an inventory full of red mushrooms and no idea why

Meanwhile, some sleazy guy keeps getting banana saplings and is trying to figure out what that even means.

To be fair, the saplings are nice.

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

darthbob88 posted:

More palate-cleanser than horror
https://twitter.com/thatfrood/status/1711219258825298321

While I can't speak for everyone, I personally am quite enamored of the EXUBERANT COWBOY.

EXUBERANT COWBOY sounds like a firmware exploit codename

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Genuinely blessed

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Ihmemies posted:

So our software creates charts. Data requests are asynchronous and they return data with metadata to which chart they belong to. If data requests fail, they return no data, only an exception.

So I am now coding a system to run a Service, which runs a Task of periodically checking a list of pending chart requests. If a chart is not generated after n seconds, the task assumes the data requests failed and we did not get the data to create the chart.

It compares timestamps of now and the moment a chart creation request was issued, so it can understand how “old” each chartgen request is.

I asked that would it be possible for the datamanager to return some kind of useful metadata, even within the exception? I was shot down so I am now coding this stupid rear end garbage collection service.

I guess that after enough cases like this it is how spaghetti monster and coding horrors are eventually born..

... Can you not just see that an exception was returned, instead of polling?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Absolute magnificence.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Tequila Bob posted:

Thanks! The best part of the thread is definitely well after the initial post. It's worth reading the whole thing.

"Don't let anything access production except production."

This is one of those statements that seems so obvious that it should be regarded as a truism. And yet it's so often not the case.

I test in production. Since the tests are in production, they're fine, right? Seems like everyone's making a big deal about nothing!!

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

pokeyman posted:

This is sounding like the most realistic intro dev course around. Possibly unintentionally.

Also flashing back to failing an assignment because I used java.util.Scanner when that was next week's assignment.

Yeah sounds about right.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Student code is cheating, unless they're a grad student or above who should realistically know better. All of us made abject horrors of one kind or another.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

ultrafilter posted:

This doesn't seem to be a particularly well-designed course.

Jabor posted:

Nah, a zero for the code being too slow is just bad pedagogy. This is an academic exercise, not a programming competition.

Relying 100% on the autograder (and then farming out giving feedback on the actual code to the other students in the course instead of giving it yourself) sounds like a incredibly lazy prof.

Yes, he did say that it was a university course. This sounds about right for that. The professor would never lower themselves to actually look at any student classwork, that's what they have TAs and grad students for.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

canis minor posted:

I can do `var foo = {undefined: undefined, null: null}` (or `var map = new Map(); map.set(null, null); map.set(undefined, undefined)`). `Object(foo).keys()` / `Object(foo).values()` (or `map.keys()` / `map.values()`) will return `[undefined, null]`.

Third base!

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Guess they just cdr-n't do it

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Write Four Billion Conditions

Volmarias fucked around with this message at 07:27 on Dec 28, 2023

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
The Soviets used a pencil

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
I'll bite, my knowledge of C/C++ esoteria is apparently insufficient. Is this actually something, or did you ask an AI to generate a picture of hello world?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

GABA ghoul posted:

I think there is a very clever solution for this that could save a lot of work

code:

if (number < 0)
 number = int.Parse(number.ToString().Replace('-', ''))

:thunk:

Doesn't look like anything to me!

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Is that even a strategy????

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Honestly, I'm disappointed that no one except Jabor is considering the case of business requirements changing. What happens when business decides that every number beginning with an even number is also even? Or 99 is even, because that's how they run sale prices? And even Jabor only mentions a strategy, and nothing else.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
My fees start at $200/hr and have a 4 hour minimum, rising to $400/hr and 2 week minimum if I have to talk to anyone.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Bruegels Fuckbooks posted:

I think we can do this. Note that the code for peer to peer and proof of work aspects of blockchain is omitted as an exercise for the reader.

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace BlockchainIsEven
{
    public class Transaction
    {
        public string FromAddress { get; set; }
        public string ToAddress { get; set; }
        public int Amount { get; set; }
        public byte[] Signature { get; set; }

        public bool Validate()
        {
            // Perform basic transaction validation
            return !string.IsNullOrEmpty(FromAddress) && !string.IsNullOrEmpty(ToAddress) && Amount > 0;
        }
    }

    public class Block
    {
        public int Index { get; set; }
        public DateTime Timestamp { get; set; }
        public string PreviousHash { get; set; }
        public string Hash { get; set; }
        public Transaction[] Transactions { get; set; }

        public void Mine(int difficulty)
        {
            string hashPrefix = new string('0', difficulty);
            while (!Hash.StartsWith(hashPrefix))
            {
                Hash = CalculateHash();
            }
        }

        private string CalculateHash()
        {
            using (SHA256 sha256 = SHA256.Create())
            {
                string rawData = $"{Index}{Timestamp}{PreviousHash}{SerializeTransactions()}";
                byte[] bytes = Encoding.UTF8.GetBytes(rawData);
                byte[] hash = sha256.ComputeHash(bytes);
                return BitConverter.ToString(hash).Replace("-", "");
            }
        }

        private string SerializeTransactions()
        {
            // Serialize transactions to a string representation
            return string.Join(",", Transactions);
        }

        public string CalculateMerkleRoot()
        {
            var transactionHashes = Transactions.Select(t => CalculateHash(t.ToString())).ToArray();
            return BuildMerkleTree(transactionHashes);
        }

        private string BuildMerkleTree(string[] hashes)
        {
            if (hashes.Length == 1)
                return hashes[0];

            var parentHashes = new List<string>();
            for (int i = 0; i < hashes.Length; i += 2)
            {
                if (i + 1 < hashes.Length)
                {
                    var leftHash = hashes[i];
                    var rightHash = hashes[i + 1];
                    var combinedHash = CalculateHash($"{leftHash}{rightHash}");
                    parentHashes.Add(combinedHash);
                }
                else
                {
                    parentHashes.Add(hashes[i]);
                }
            }

            return BuildMerkleTree(parentHashes.ToArray());
        }

        private string CalculateHash(string data)
        {
            using (SHA256 sha256 = SHA256.Create())
            {
                byte[] bytes = Encoding.UTF8.GetBytes(data);
                byte[] hash = sha256.ComputeHash(bytes);
                return BitConverter.ToString(hash).Replace("-", "");
            }
        }
    }

    public class Blockchain
    {
        private readonly List<Block> _chain = new List<Block>();
        private readonly List<Transaction> _pendingTransactions = new List<Transaction>();
        public const int DIFFICULTY = 4;
        public const int BLOCK_REWARD = 10;
        public const int TRANSACTION_FEE = 1;

        public void AddTransaction(Transaction transaction)
        {
            if (transaction.Validate())
                _pendingTransactions.Add(transaction);
        }

        public async Task MineBlock(string minerAddress)
        {
            var block = new Block
            {
                Index = _chain.Count + 1,
                Timestamp = DateTime.Now,
                PreviousHash = _chain.LastOrDefault()?.Hash ?? string.Empty,
                Transactions = _pendingTransactions.ToArray()
            };

            block.Mine(DIFFICULTY);
            _chain.Add(block);
            _pendingTransactions.Clear();

            var coinbaseTransaction = new Transaction
            {
                FromAddress = string.Empty,
                ToAddress = minerAddress,
                Amount = BLOCK_REWARD
            };
            _pendingTransactions.Add(coinbaseTransaction);

            await BroadcastBlock(block);
        }

        private async Task BroadcastBlock(Block block)
        {
            var apiClient = new BlockchainAPIClient();
            await apiClient.BroadcastBlockAsync(block);
        }

        public async Task<bool> IsValidChain()
        {
            for (int i = 1; i < _chain.Count; i++)
            {
                var currentBlock = _chain[i];
                var previousBlock = _chain[i - 1];

                if (currentBlock.Hash != currentBlock.CalculateHash())
                    return false;

                if (currentBlock.PreviousHash != previousBlock.Hash)
                    return false;

                var apiClient = new BlockchainAPIClient();
                if (!await apiClient.VerifyProofOfWorkAsync(currentBlock, DIFFICULTY))
                    return false;
            }

            return true;
        }

        public async Task ResolveConflicts()
        {
            var apiClient = new BlockchainAPIClient();
            var peers = await apiClient.GetPeersAsync();
            var newChain = _chain;

            foreach (var peer in peers)
            {
                var response = await apiClient.GetChainFromPeerAsync(peer);
                var chain = response.Chain;

                if (chain.Count > newChain.Count && await IsValidChain(chain))
                    newChain = chain;
            }

            if (newChain != _chain)
                _chain = newChain;
        }
    }

    public interface IIsEvenStrategy
    {
        Task<bool> IsEvenAsync(int number);
    }

    public class TraditionalIsEvenStrategy : IIsEvenStrategy
    {
        public Task<bool> IsEvenAsync(int number)
        {
            return Task.FromResult(number % 2 == 0);
        }
    }

    public class BlockchainIsEvenStrategy : IIsEvenStrategy
    {
        private readonly Blockchain _blockchain = new Blockchain();

        public async Task<bool> IsEvenAsync(int number)
        {
            var transaction = CreateTransaction(number);
            _blockchain.AddTransaction(transaction);

            await _blockchain.MineBlock("miner1");
            await _blockchain.ResolveConflicts();

            return transaction.Amount % 2 == 0;
        }

        private Transaction CreateTransaction(int number)
        {
            var transaction = new Transaction
            {
                FromAddress = "sender",
                ToAddress = "receiver",
                Amount = number - Blockchain.TRANSACTION_FEE
            };

            // Sign the transaction with a dummy private key
            using (ECDsa ecdsa = ECDsa.Create())
            {
                byte[] transactionBytes = Encoding.UTF8.GetBytes(transaction.ToString());
                transaction.Signature = ecdsa.SignData(transactionBytes, HashAlgorithmName.SHA256);
            }

            return transaction;
        }
    }

    public class IsEvenChecker
    {
        private IIsEvenStrategy _strategy;

        public IsEvenChecker(IIsEvenStrategy strategy)
        {
            _strategy = strategy;
        }

        public async Task<bool> IsEvenAsync(int number)
        {
            return await _strategy.IsEvenAsync(number);
        }
    }

    public class Program
    {
        public static async Task Main(string[] args)
        {
            int number = 42;

            IIsEvenStrategy traditionalStrategy = new TraditionalIsEvenStrategy();
            IsEvenChecker traditionalChecker = new IsEvenChecker(traditionalStrategy);
            bool isEvenTraditional = await traditionalChecker.IsEvenAsync(number);
            Console.WriteLine($"Traditional IsEven: {isEvenTraditional}");

            IIsEvenStrategy blockchainStrategy = new BlockchainIsEvenStrategy();
            IsEvenChecker blockchainChecker = new IsEvenChecker(blockchainStrategy);
            Console.WriteLine("Checking if the number is even using blockchain...");
            bool isEvenBlockchain = await blockchainChecker.IsEvenAsync(number);
            Console.WriteLine($"Blockchain IsEven: {isEvenBlockchain}");
        }
    }
}

:boom: Finally! Something flexible! Thank you!

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

dc3k posted:

everything in linux is a file
everything in javascript is a god drat nightmare

Removed the spoilers, it's not a surprise to anyone at this point

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

RPATDO_LAMD posted:

what yall really need is some solid mathematical background for your IsEvens

Python code:
def isEven(x):
    return not isRelativelyCoprime(x, 2)
    
def isRelativelyCoprime(a, b):
    if b > a:
        a, b = b, a
    # if two integers a and b are coprime to each other, then
    # for all integers i and j,
    # b*i % a == b*j % a implies i % a == j % a.
    for i in range(0, a):
        for j in range(i + 1, a):
            if (i * b) % a == (j * b) % a:
                if i % a != j % a:
                    return False # found a counterxample!
    return True

it uses modulos, and it only takes quadratic time to run!

My eyes just rolled into the back of my head

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
code:

string greeting = "Hello", name;
cin >> name;
cout <<  greeting << "World, " << name << "!";

For beginners, this is basically "uh I Guess I read and write by doing these weird arrows? Not sure why but ok?" And then you learn about manipulators you can use for clever programming tricks, but with No Idea what's even happening there. "Why does the magic word endl work, but also you're calling some kind of function called setw? I thought functions returned values, but I guess I can tell it to use a function or something?" And then you find out that cout and cin are the only places these <<s and >>s seem to work, except for maybe a couple other places where they mean Something Else?

Straight up inscrutable, I have absolutely no idea why someone decided "let's give new developers this magical footgun so they learn JUST ENOUGH to do stupid tricks, but don't know what is actually happening." They're powerful tools but they shouldn't be beginner tools.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

zokie posted:

Since Java is so verbose and tedious compared to newer languages it seems to have created a culture of relying on a lot of magic stuff to avoid as much hiring boiler plate as possible. To me coming from frontend and C# starting to contribute to our Spring based backend felt like a lot of magic incantations.

There is a similar problem with C#, certainly when it comes to EF and asp.net, but it doesn’t feel like it’s being taken as far as Lombok for example.

You're absolutely correct that it's a pain in the rear end, and you have to work around it. I was going to suggest Google Guice, but I don't know how widely that's actually used.

Dagger is a nice DI framework for Java / Kotlin that performs compile-time injection, which may well be much nicer depending on whether you actually need to be able to add/remove modules at runtime

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Xarn posted:

Dehumanize yourself and face the [==[[=[]=]]==]s

These loss edits have gotten very abstract

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

necrotic posted:

a runtime configurable array base index?

:wtc:

What an incredibly cursed concept

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

OddObserver posted:

I hope there is someone senior enough to explain to him that he is touching people's tools.

Doesn't that normally get you fired before you can cause a lawsuit?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply