java – How to optimize the check for data types before building an object?

I’m trying to build an object, which uses different methods based on different data types. I.e. it differs from withBooleanValue,withStringValue and withDateValue depending on the data type. What I have is a string, and depending on what that string is (boolean, string or date), I need to build this object. Below is how I went about it.

private List<Answer> getAnswers(Set<Question> questions) {
        List<Answer> answers = new ArrayList<>();
        questions.forEach(question -> {
            Answer.Builder answer = Answer.builder()
                    .withQuestion(question.question());
            if (BooleanUtils.toBooleanObject(question.value()) != null) {
                answer.withValue(AnswerValue.builder()
                        .withBooleanValue(BooleanUtils.toBoolean(question.value()))
                        .build());
            } else {
                try {
                    Date dateValue = DateUtils.parseDate(question.value(), new String(){"dd-MM-YYYY"});
                    answer.withValue(AnswerValue.builder()
                            .withDateValue(dateValue)
                            .build());

                } catch (ParseException e) {
                    answer.withValue(AnswerValue.builder()
                            .withStringValue(question.value())
                            .build());
                }
            }
            answers.add(answer.build());
        });
        return answers;
    }

Is there a better way to do this? Somehow the ifs, and try-catch statements make it look very complicated and I’d like to reduce the lines and complexity with a better way.

macos – If you had a Mac that was not going to ever connect to the internet, what would you do to optimize it?

I have a Mac Pro at work in a lab environment that is connected to a bunch of lab equipment that will never be connected to the internet. I’ve noticed that if I open up the console application to look at the streaming logs, there a lot of errors (which look mostly like the Mac is trying to call out to the internet and failing). While this doesn’t really matter, I was wondering what settings you would apply to optimize a Mac like this.

Disclaimer, I a more of a Windows/Linux user so assume very little Mac knowledge!

Cheers!

python 3.x – How do I shorten & optimize my Fibonacci Code?

Here’s the code I’m having trouble shortening. I am currently a beginner in Python 3.x.

from os import system

def fibonacci(terms):
    count = 0
    x = 0
    y = 1
    z = x + y
    if terms <= 0:
        print("Enter a positive integer.")
    elif terms == 1:
        print("Fibonacci sequence in " + str(terms) + " terms.")
        print(x)
    else:
        print("Printing " + str(terms) + " terms.")
        while count < terms:
            print(x)
            z = x + y
            x = y
            y = z
            count += 1

while True:
    user_input = int(input("How many terms? "))
    fibonacci(user_input)
    loop = input("Again? (Y/n) ")
    if loop == "Y" or loop == "":
        system("cls")
    else:
        exit()

I would appreciate if there will be someone who will be able to make this as efficient as possible. Thank you.

python – How can I optimize my Von Neumann neighborhood algorithm?

I am working on a small project that requires finding Von Neumann neighborhoods in a matrix. Basically, whenever there is a positive value in the array, I want to get the neighborhood for that value. I used an iterative approach because I don’t think there’s a way to do this in less than O(n) time as you have to check every single index to make sure all of the positive values are found. My solution is this:

is_counted = {}


def populate_dict(grid, n):
    rows = len(grid)
    cols = len(grid(0))
    for i in range(rows):
        for j in range(cols):
            if grid(i)(j) > 0:
                find_von_neumann(grid, i, j, n, rows, cols)

    return len(is_counted.keys())


def find_von_neumann(grid, curr_i, curr_j, n, rows, cols):
    #print(curr_i, curr_j)
    if n == 0:

        cell = grid(curr_i)(curr_j)

        if cell > 0:
            key = str(curr_i) + str(curr_j)
            if key not in is_counted:
                is_counted(key) = 1



    if n >= 1:

    coord_list = ()
# Use Min so that if N > col/row, those values outside of the grid will not be computed.
    for i in range(curr_i + min((-n), rows), curr_i + min((n + 1), rows)):
        for j in range(curr_j + min((-n), cols), min(curr_j + (n + 1), cols)):
            dist = abs((curr_i - i)) + abs((curr_j - j))

            if n >= dist >= -n and i >= 0 and j >= 0 and i < rows and j < cols:

                coord_list.append((i, j))

    for coord in coord_list:
        key = str(coord(0)) + str(coord(1))
        if key not in is_counted:
            is_counted(key) = 1


neighbors = populate_dict((

(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
), 2)

I went with a hash table as my data structure but I believe that currently the worst case runtime would look very similar to O(n^2). For example if N (the distance factor) is equal to the amount of rows or columns AND every single value is positive, its going to be inefficient. Am I missing something with my solution, for example could using dynamic programming possibly help cut down on the runtime or is this already a good solution?

I’m fairly new to algorithms and runtime analysis so please correct me if I messed up on anything in my own analysis of this , thanks!

performance – How do I optimize the bubble sort in Assembly8086?

I tried to implement bubble sort in Assembly 8086.

datasg      SEGMENT BYTE 'data'
array       DB 1, 3, 2, 5, 4
n           DW 5
datasg      ENDS
stacksg     SEGMENT BYTE STACK 'stack'
            DW 12 DUP(?)
stacksg     ENDS
codesg      SEGMENT PARA 'code'
            ASSUME CS:codesg, DS:datasg, SS:stacksg
MAIN        PROC FAR

; Pushing the previous data segment to keep it secure.
            PUSH DS
            XOR AX, AX
            PUSH AX
            MOV AX, datasg
            MOV DS, AX
;SI = i
            XOR SI, SI
            MOV CX, n
            DEC CX
out:        PUSH CX; Pushing CX to the stack before entering the second for loop
            XOR DI, DI
            MOV CX, n
            DEC CX
            SUB CX, SI
in:         MOV AH, array(DI)
            CMP AH, array(DI+1)
            JLE if_end
            XCHG AH, array(DI+1)
            MOV array(DI), AH
if_end:     INC DI
            LOOP in
            POP CX
            INC SI
            LOOP out
            XOR SI, SI
; Some garbage code to move array elements to AL register one by one to see them while debugging.
            MOV AL, array(SI)
            INC SI
            MOV AL, array(SI)
            INC SI
            MOV AL, array(SI)
            INC SI
            MOV AL, array(SI)
            INC SI
            MOV AL, array(SI)
            RETF
MAIN        ENDP
codesg      ENDS
            END MAIN

It seems to be working for the given example in the above code. I also tried it with different arrays and they all seem to work.
I just want to learn if there is a way to improve it? Improvements like changing JMP codes to decrease the size of code or using AX with XCHG because that is faster.

I also can’t comprehend the idea of pushing CX to stack for using nested-for loops. If you would give some suggestion about it I would be very happy.

optimization – Are lessons on tail recursion transferable to languages that don’t optimize for it?

I’m currently reading through Structure and Interpretation of Computer Programs (SICP). During the course of that book, the lesson of “you can optimize recursive procedures by writing them as tail recursive” is drilled in to the reader again and again. In fact, I’m nearly 100 pages in and have yet to see a single for or while loop – it’s all been recursion. This is starting to worry me. To my knowledge, optimizing tail calls in a way that effectively turns tail recursive procedures in to iterative procedures is not a common feature in modern programming languages. This gives me my question: If I’m using a language that does not optimize for tail recursion, how can I apply these lessons that SICP has been teaching? Is the knowledge at all transferable?

How to optimize images in magento2

My site speed is very slow. So could anyone please let me know how it I optimize all the images??

my site loading can be faster.

I will optimize wordpress speed to boost SEO rankings for $40

I will optimize wordpress speed to boost SEO rankings

Reports from Google indicate that if your site doesn’t load within 3 seconds, the web visitor is likely to turn away. Your slow WordPress site is hurting your Google rankings and losing you customers and sales.Save time, High Google Rankings, High Conversions, Decrease in Bounce Rate and Increase in Sales with our WordPress Speed Optimization Service.

My gig includes but not limited to:

✪ Optimize images

✪ Browser Caching

✪ Avoid bad requests

✪ Database Optimization

✪ WordPress Security

✪ Page Caching

✪ Eliminate render-blocking JavaScript and CSS

✪ Plugin Audit

✪ MySQL Tuning

✪ Cloudflare Setup

✪ Anti-heartbeat Setup

✪ WooCommerce Speed Optimization

✪ Apache configuration
Bugs Free

✪ Cache Preloading from XML Sitemap

✪ Baseline and Completion Speed Assessment GTMetrix Report
another benefit includes:

Bonus advice on how to keep the speed up all the time.

Order Today to make it one of the FASTEST sites in the world! and make More Sales

.

How can I optimize this search operation?

I’m a newbie when it comes to problem solving and I need some help/insight. I have technically ‘solved’ this problem but I have a few questions.


My approach was to perform a double indexOf operation on each element in the provided input.
Is there a more efficient/alternate way to solve this problem ?


My code:

function permutationEquation(p) {
    let newP = (0,...p);
    let returnArray = ();
    for (var i = 1; i < newP.length; i++) {
        let oneIndex = newP.indexOf(i);
        let TwoIndex = newP.indexOf(oneIndex)
        returnArray.push(TwoIndex);
    }

    return returnArray;
}

I will create and optimize your YouTube with complete SEO for $10

I will create and optimize your YouTube with complete SEO

Welcome to my best YouTube channel SEO service

Are you looking for someone to promote and SEO your YouTube channel or Videos? To grow and rank your channel I use white hat SEO methods suggested by the new improvements to YouTube’s algorithms. Metadata is important for content and videos. It includes information about a video such as a title, Description, and Tags which helps your video stand out and get found by the algorithm. I’ll do YT S.E.O along with channel monetization, increasing subscribers, video promotions, S.E.O, and full channel customization to rank your video and grow the channel.

My services :
✅Title Optimization

✅Strong Strategic Description

✅Keywords/Hashtags Research

✅Improve SEO Score

✅Optimize For Organic Views

✅Channel Tags

✅Add End Screen

✅Add Cards

Why Chose me ?
✅Provide report & screen shot

✅ 100% satisfaction guarantee

✅ If you’re not satisfied Money back guarantee

✅ 1 Month free support

✅ Timely Deliver

Note : If you have any question about YouTube SEO simply drop the message & get a reply within a second.

Looking forward to hearing from you.

Thank you

Best regards
MD Apurbo Rahman

.