java – How do i efficiently read random lines from a TXT or CSV file?

Context of the problem:

  1. I have made chess GUI (Java)
  2. The GUI is capable of loading chess puzzles/problems to solve
  3. Of said puzzles, i have gotten my hands on a database which is just shy of a million entries

The problem/question:
How does one most efficiently go about getting a random puzzle from this database?

Obviously keeping the database in memory is not an option, despite it already being compressed. Stripped all data that isn’t needed from it and in the end converted it into byte-arrays. All to no avail. The full database always ends up taking up somewhere between 100 and 200 MB of memory. A tenth of that would be acceptable (for my purposes).

Even worse: When processing the entire database (in attempts to keep it all in memory), the process file->memory took upwards of 700 MB memory.

Let’s say i have the following:

  • The database as either a txt or csv file
  • The amount of lines in said file (which is equal to the amount of puzzles)

Am i with that, in some way, capable of grabbing either a random or specific puzzle from the file (albeit async, that doesn’t matter) without having to load the entire database into memory?

Thanks for your time!

dataset – Question about plotting dashed lines

Just remove the List wrapping:

Plot[data, {x, 0, 100}, 
 PlotStyle -> {{Red, Dashed}, {Blue, Dashed}, {Darker[Green], 
    Dashed}, {Black, Dashed}, {Purple, Dashed}, {Gray, Dashed}}]

enter image description here

You can also use

PlotStyle -> Thread[Directive[{Red, Blue, Darker[Green], Black, Purple, Gray}, Dashed]]

or

PlotStyle -> Thread[{{Red, Blue, Darker[Green], Black, Purple, Gray}, Dashed}]

visual studio code – vscode ruby indent lines starting with ‘.method’

I’m using VSCode (on MacOS) and would like to indent lines starting with .method().

Instead of

some_object
.some_method()
.another_method()

I would like

some_object
  .some_method()
  .another_method()

This is obviously a trivial example.

For reasons I don’t want to get into, I would like to do this in VSCode natively – not using a gem like rufo.

magento2.3 – Address Options > Number of Lines in a Street Address

I am experiencing a problem in my magento 2 store.
I cannot set the line quantity in Settings> Client Configuration> Name and Address Options> Number of Lines in Address
I can put any value 1, 2,3 or 4
Magento always returns only two lines as shown below.
This error occurs in all places where the customer’s address is placed, either in the admin, in / customer or at the checkout
All the basic procedures for cleaning caches, compilation and deploys were done, I even rebooted the server but nothing worked.
Environment:
PHP 7.3
Magento 2.3.6
Opcache
Redis
MYSQL

Magento is in developer mode,
none
exception for this error.

I did a search for street in my database and got these results in the table eav_attribute.

I just recently migrate the data from my magento 1 store and I believe something is corrupted in my database.

Magento Error

eav_attribute

eav_attribute

c – K&R 1-22 Folding Lines Exercise

I am currently reading and doing exercises from K&R. For exercise 1-22, I have the following solution. When I check my answer with other solutions online, I find that mine is generally shorter. Am I missing something? Any corrections are appreciated!

  1. Very long solution
  2. Very long solution 2
  3. Shorter solutions (some of the solutions at the top are around the same length as mine, but not generalized).

Exercise 1-22 Specifications: Write a program to “fold” long input lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your program does something intelligent with very long lines, and if there are no blanks or tabs before the specified column.

#include <stdio.h>

#define LEN 20
#define TABSTOP 8
#define MAXLINE 1000

int get_line(char s(), int lim);

int main() {
    int len, nc;
    char line(MAXLINE);
    while ((len = get_line(line, MAXLINE)) > 0) {
        nc = 0;
        for (int i = 0; i < len; i++) {
            if (nc >= LEN) {
                putchar('n');
                nc = 0;
                if (line(i) != 't') putchar(line(i));
            } else putchar(line(i));
            if (line(i) == 't') nc += (nc + 1) % TABSTOP;
            else ++nc;
        } 
    }
}

int get_line(char s(), int lim) {
    int c, i;

    for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c != 'n'; ++i)
        s(i) = c;
    if (c == 'n') s(i++) = c;
    s(i) = '';
    return i;
}

Different level of spacing between rows on different lines while converting a csv file to txt file using python

I have to convert a .csv file into .txt file which I did and I have the following code.

text_list = ()

with open(csv_file,"r") as infile:
    for line in infile:
        line = line.split(",", 2)
        text_list.append("t".join(line))

txt_file = 'test.txt'
with open(txt_file, 'w') as outfile:
    for line in text_list:
        outfile.write(" " + line)
    outfile.close

But the problem is,

CSV file:

phi,Z,T
0,0,0
10.000005,1.2,3000.00
20.000005,2.4,6000.00

Required txt file:

phi        Z    T
0          0    0
10.000005  1.2  3000.00
20.000005  2.4  6000.00

Text file I have with the above mentioned code:

phi    Z    T
0    0    0
10.000005    1.2    3000.00
20.000005    2.4    6000.00

Thank you

graphics – Opengl in 500 lines barycentric calculation question

https://github.com/ssloy/tinyrenderer/wiki/Lesson-2-Triangle-rasterization-and-back-face-culling

I cannot figure out how we go from uAB-vector + vAC-vector + PA-vector = 0 to the linear system with those subscripts x and y? Is there another way of explaining how we take three vectors, split them into x and y type vectors, and produce a cross-product that can be used to find the barycentric coords (u, v, w)?

Also, I am not sure why there is a division by the z component of the cross product in last line of the barycentric function. Maybe the answer to my first question will make this more obvious.

Below is a picture of the section of the tutorial where I am stuck. Link to full page is above.

enter image description here

display – Green and white lines on screen of a macbook pro

my Macbook pro 13inch, Early 2015 has the problem you can see in the picture enter image description here

I take that to the support, they told me the screen was broken, so they replaced it, but the problem is still there.
Now the weird side of the story, that issue is there just after the login screen. If I connect the macbook to an external display, both the internal and exernal starts to be well visible again!

Another strange thing is that I tried to wipe everything, formatting the entire disk and installing a brand new Catalina os (I had Sierra before).
All the installation went smootly in the recovery suite (without the external display connected), and the initialization of the os as well. But, after the desktop appeared, the problem was back there.

When the hdmi cable is connected, the screen works perfectly fine, as you can see here
enter image description here

I tried to reset NVRAM with the P R option cmd combination
I tried also to reset the SMC with shift ctrl option combination

Nothing seems to have any effect.

Any idea? Thank you

plotting – Add vertical lines to `ComplexPlot3D` at roots

I have a Table of 6 plots of polynomials of increasing degree, using ComplexPlot3D:

Clear["Global`*"]; 
poly[z_] := Sum[k*z^k, {k, 1, n}]; 
Table[ComplexPlot3D[poly[z], {z, -1.5 - 1.5*I, 1.5 + 1.5*I}], {n, 1, 6}]

enter image description here

I would like to add a black vertical line passing through each root of the polynomials. You can kind of see where they are from the plots, but lines would be a helpful visualisation aid.

I can obtain the roots easily enough:

Table[{poly[z], Roots[poly[z] == 0, z]}, {n, 1, 6}]

But how do I convert the data provided by Roots into vertical lines? Ultimately, I want to be able to do this for polynomials of arbitrary degree, so a ‘manual’ solution isn’t much help.

Thanks in advance, and stay safe.

Split /n rows into multiple lines

Very similar to this post, Google sheets split multi-line cell into new rows (+ duplicate surrounding row entries), but it doesn’t seem to like the "split on line 5", can someone help?