text:
Q: Can I tell the .NET GC to leave some threads alone? I'm investigating the possibility of rewriting a relatively small service from C++ to C#. The service has two main functions:

*

*Execute HTTP requests once in a while. They involve several high-level tasks like JSON encoding/decoding, base64 encoding/decoding, and HTTP requests themselves, for which C++ isn't awesome;

*Perform a number of real-time, audio-related tasks that have hard deadlines, for which C# isn't awesome.

The real-time tasks are handled by a separate library that does its own threading stuff and barely interacts with the rest of the service at all. The rest of the service feeds it a little bit of data, obtained from the HTTP requests, every 5 minutes or so.
The thing is, since the real-time part has hard deadlines, I can't really tolerate GC pauses on the library's threads. On my own code's side, there should be plenty of time for the GC to run between Web requests, but I can't tolerate that it kicks in while I'm trying to feed data to the library either.
I found that I can create a critical section in which the garbage collector won't start using GC.TryStartNoGCRegion(), which solves half of the problem.
However, I still don't know if there is a way to tell the .NET GC to leave alone specific threads that don't run managed code. Is that possible?

A: As you have pointed out, when an application is configured to run in Workstation GC Mode, the garbage collector wont suspend threads executing native code. In that case anytime your service receives a request I would try something like this...
    private bool _running = true;
    private int _workCounter = 0;
    private AutoResetEvent _workFlag = new AutoResetEvent(false);
    private void RunNoGCNativeCode(params object[] args)
    {
        // Increase the work counter to determine how many requests are being processed
        if (Interlocked.Increment(ref _workCounter) == 1)
        {
            // Try to start a No GC Region
            GC.TryStartNoGCRegion(1 * 1024 * 1024 * 1024, true);
        }
        // TODO: Prep data and execute your native code
        // TODO: Process response
        // TODO: Dispose of anything that is no longer in use and null objects as needed
        if (Interlocked.Decrement(ref _workCounter) == 0 && GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
        {
            GC.EndNoGCRegion();
        }
        // Notify Manual Collection thread work has been completed
        _workFlag.Set();
    }

On a different thread...
    private void WaitForNoWorkThenGC()
    {
        // Continue running thread while in use
        while (_running)
        {
            // Wait for some work to be complete
            _workFlag.WaitOne();
            // If there is no work being processed call GC.Collect()
            if (_workCounter == 0)
            {
                GC.Collect();
            }
        }
    }

This should help you control when GC occurs to minimize impact on your application
As for managed code, I have not found any indication that .NET Garbage Collection can "leave alone" specific threads executing managed code. All current modes(Server, Workstation, Concurrent, etc) of garbage collection will suspend ALL threads executing managed code when it chooses to. Do note that some GC modes can have a shorter pause in threads which might also help. I've tried using TryStartNoGCRegion() in a real-time c# application also and it ignores my request always because the amount of memory I use, I could not find a way to specify only collect after X memory limit is reached either.
However there are two potential solutions you can look into.

*

*Using Garbage Collection Notifications to monitor when the GC is approaching a full garbage collection. Potentially if you free up some memory manually before it ever reaches the collection point you can avoid Garbage Collection.

*Run the different type of requests in separate application processes? or pass them to separate application processes as you receive them. This way each application doesn't share context's and garbage collection will be handled separately.

A: Didn't check it but,
I would inherit Thread, or Task whatever you use
like:
public class SuppressedThread : Thread
{
    protected override void Finalize()
    {
         try
         {
          // kill what you want
         }
         finally
         {
          base.SupressFinalizeFinalize();
         }
    }
}

public class SuppressedThread : Thread, IDisposable
{
    protected override void Dispose()
    {
         try
         {
          // kill what you want
         }
         finally
         {
          GC.SupressFinalize();
         }
    }
}

then you can use it normally
var newThread = new SuppressedThread(DoWork);
newThread.Start(42);

What do you think?


text:
Q: "float" object not iretable error; but I dont see what I'm iterating over? I am trying to rewrite fast5 (HDF5) data files into abf format, I have the following code that should be able to rewrite the given fast5 file into an general data type for rewrite into abf with another tool. However the code below produces errors at the digitizing step
from uuid import uuid4
import numpy as np
from fast5_research import BulkFast5

filename='test1.fast5'
mean, stdv, n = 40.0, 2.0, 10000
raw_data = np.random.laplace(mean, stdv/np.sqrt(2))

# example of how to digitize data
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
rng = stop - start
digitisation = 8192.0
bins = np.arange(start, stop, rng / digitisation)

# np.int16 is required, the library will refuse to write anything other
raw_data = np.digitize(raw_data, bins).astype(np.int16)

# The following are required meta data
channel_id = {
    'digitisation': digitisation,
    'offset': 0,
    'range': rng,
    'sampling_rate': 4000,
    'channel_number': 1,
    }
read_id = {
    'start_time': 0,
    'duration': len(raw_data),
    'read_number': 1,
    'start_mux': 1,
    'read_id': str(uuid4()),
    'scaling_used': 1,
    'median_before': 0,
}
tracking_id = {
    'exp_start_time': '1970-01-01T00:00:00Z',
    'run_id': str(uuid4()).replace('-',''),
    'flow_cell_id': 'FAH00000',
}
context_tags = {}

with Fast5.New(filename, 'w', tracking_id=tracking_id, context_tags=context_tags, channel_id=channel_id) as h:
    h.set_raw(raw_data, meta=read_id, read_number=1)

with error
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, stat
Traceback (most recent call last):
  File "/home/archie/PycharmProjects/Fast5read/Fast5rewrite.py", line 11, in <module>
    start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
TypeError: 'float' object is not iterable

When I looked for help I am suppose to iterate over a range, but I dont see where the iteration is or how to fix this error than.

A: start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))

min() and max() are functions that expect to take iterables as arguments. They find the smallest and largest element in those iterables respectively.
Given the way you've called np.random.laplace(), it will return a single float value back, which is not an iterable.

A: If you want an iterable from numpy.random.laplace you must specify the shape of the array you want returning in the (optional) 3rd parameter.
https://numpy.org/doc/stable/reference/random/generated/numpy.random.laplace.html
e.g. to draw 10000 samples:
mean, stdv, n = 40.0, 2.0, 10000
raw_data = np.random.laplace(mean, stdv/np.sqrt(2),n)

# example of how to digitize data
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
rng = stop - start
digitisation = 8192.0
bins = np.arange(start, stop, rng / digitisation)

redpajama_set_name: RedPajamaStackExchange


text:
Q: Prevent NERD Tree from opening buffer on start I'm using Janus for Vim customizations.
One thing that bothers me is that it opens NERD Tree in a separate buffer on start. I don't want to disable NERD Tree completely. Just want to not get it opened on start.
Is there a way without tweaking the internals of Janus?

A: Finally figured it out based on the Janus configuration mentioned by @romanl.
I had to add to ~/.vimrc.after
augroup AuNERDTreeCmd
  autocmd!
augroup end

A: Yet another "plugin distribution for Vim" user who chose to give complete control over his Vim configuration to someone else and has no idea how to change the default behaviour. Yeah, "easy" is so better than "hard".
This behaviour is probably defined in an autocmd, somewhere in your "janus" directory or whatever it uses to store its things. Maybe here.
You should probably take this as an opportunity to rethink your choice, drop Janus entirely and adopt a saner configuration strategy.
If you are the one adding/removing stuff to your ~/.vimrc and installing plugins, you simply can't find yourself in such a situation.


text:
Q: How do I get all photos a fan page is tagged in with the Facebook Graph API? I was able to write a PHP application which requests an access node for the admin of the FB Fan Page, and then requests an access node to gain access to the fan page itself.
I'm now able to get all photos that were posted to the timeline of the fan page by going to https://graph.facebook.com/GROUP_ID/tagged?access_token=...
However, I actually want the photos the fan page is tagged in. The above url only gives me the photos posted to the time line of the fan page, not the ones in which the page is tagged by other users. According to the developers documentation I could get these by going to https://graph.facebook.com/GROUP_ID/photos?access_token=...
Everything seemed to work this way. I got a photo in which the fan page was tagged (profile picture of the fan page). However, I don't get any other photos in which the fan page is tagged. I tried to tag the fan page in its own photos (posted and tagged by an admin of the fan page) and tagging the fan page in other people's photos, but I only get the one profile photo in which the fan page is tagged.
Is this a permission problem or something else?
When requesting the access tokens I asked for the following permissions:

*

*offline_access

*read_stream

*manage_pages

Any help would be greatly appreciated.


text:
Q: Squarespace CSS: When I target code for bordered columns to a section, the Mobile width shrinks to less than half of the screen Site URL: https://www.ukulelekidz.com/camp
Here is my desktop code for 2 column border with shadow (works good)
.sqs-col-6 {border: 2px solid #172236;width:47%!important;margin-left: 2.5%; box-shadow: 2px 5px 10px rgba(0,0,0,0.2)}

Here is my adjustment for mobile... (works good also)
@media only screen and (max-width:768px){ .sqs-col-6 {margin-left:0%!important;margin-bottom: 7%}}

The issue is the borders are applied to all 2 column sections on my site, so i then go to target just the section I want and great, it works for desktop, but then messes up the mobile view. Here is the full code i used to target the section:
section[data-section-id="6038f9680adafe73679299cc"]
.sqs-col-6 {border: 2px solid #172236;width:47%!important;margin-left: 2.5%; box-shadow: 2px 5px 10px rgba(0,0,0,0.2)}
@media only screen and (max-width:768px){ .sqs-col-6 {margin-left:0%!important;margin-bottom: 7%}}

See screen shot of what happens to mobile view when I target.
I did find a work around by not targeting the section, and then removing the border effect from where it appears on all other 2 column sections... Example:
section[data-section-id="60387a655347d0248f70c4ea"]{.sqs-col-6 {border: none; box-shadow:none}}

but I don't think that's how CSS should work. How do I target code for a desktop section in squarespace, then fix the code for mobile?
I am new to CSS so any help is appreciated! Thanks!

A: The following CSS, in place of what you have now, will add the border and box shadow at all widths, will separate the columns horizontally at wide widths, and will separate them vertically on mobile. The margin is split between left and right so that the boxes are centered.
#page-section-60387a655347d0248f70c4f4 .sqs-col-6 {
  border: 2px solid #172236;
  box-shadow: 2px 5px 10px rgba(0,0,0,.2);
  box-sizing: border-box;
}
@media screen and (min-width: 768px) {
  #page-section-60387a655347d0248f70c4f4 .sqs-col-6 {
    width: 47.5% !important;
    margin-left: 1.25%;
    margin-right: 1.25%;
  }
}
@media screen and (max-width: 767px) {
  #page-section-60387a655347d0248f70c4f4 .sqs-col-6 {
    margin-bottom: 35px;
  }
}


text:
Q: A process is a program that is loaded into RAM Is this correct? Basically, programs are simply code on hard disk and they are called process(es) when they are in the RAM, right?

A: While this might be a little clumsy, you could say that. Creating a process takes two steps:

*

*Allocate a u area (basically, information about the process that is accessible to the kernel), fill an entry in the process table, initialise all related components... basically, just create another process for the kernel to manage. This is done through the fork system call.

*Load an executable file into memory. This is done through the exec (now execve) system call. During this call, 3 main memory areas, called regions are filled:

*

*The text region, which consists of a set of instructions your process is to follow : basically, your program. This is contained within your executable file (the compiler writes it based on your source code).

*The data region, which contains your initialised data (variables with values, e.g. int myvar = 1) and enough space to hold unitialised data (called bss), such as an array (e.g. char buffer[256]).

*The stack region. This part is a little trickier to explain, and as I said in a comment, Maurice J. Bach does it better than I ever would (chapter 2, section 2.2.2). Basically, the stack is a dynamic area in memory, which grows as functions are called, and shrinks as they return. When executing a program, frames corresponding to the main function are pushed onto the stack. These frames will be popped when the program terminates.

Now, while this might seem enough to run a program, it isn't. Now that your process is running, the kernel still needs to maintain it. Quoting:

As outlined in Chapter 2, the lifetime of a process can be conceptually divided into a set of states that describe the process. (The Design of the UNIX Operating System, Maurice J. Bach, chapter 6 : the structure of processes).

This means that your process will not always be "running", nor will it always be in primary storage (what you call "RAM"). For instance:

*

*If your process ever goes to sleep (because it is told to by its text, or because it is waiting for something), the kernel may decide to swap it out to secondary storage (usually a swap area). When this happens, your process is no longer in primary storage ("in memory/RAM") : the kernel has saved it, and will be able to reschedule it once it's been loaded back into primary storage.

*If your process ran enough time, and the kernel decides to preempt it (and let another process run instead for some time), it may swap it out again if it cannot hold it into memory.

A typical life for a process is...

*

*Created: the fork system call has been used.

*Ready to run (in memory) : instructions and data have been loaded.

*Running (switching between user and kernel mode, probably several times..)

*Sleeping, waking up, sleeping, waking up, ...

*Exiting (final switch to kernel mode, zombie state, disappearance).

Steps 3 and 4 may actually interweave.
Note that processes are one of two main concepts on UNIX systems (along with files). For this reason, it is impossible to cover everything about them in a Q&A format. The book I kept quoting in my answer is an excellent reference for UNIX systems, and while *NIXes/UNIX-like system may differ in some areas, they still rely on the same concepts.

A: When looking at the Wikipedia page: "a process is an instance of a computer program that is being executed".
So if usually to be executed the program needs to be loaded in RAM, a process is not necessarily in RAM.
You can for example thing about a sleeping process being put in swap. The process is still running (i.e. it is being listed using the ps command) but its state has been written on disk to free some RAM space.


text:
Q: Braintree for iOS apps with paypal integration Is the a braintree iOS SDK for native iOS app payment system integration that uses paypal payments too?
I cannot seem to find one. Is there a third party sample code?
Or is there a guide on how to do it?

A: I work at Braintree. If you have more questions, please reach out to our support team.
Yes, the Braintree iOS SDK includes PayPal support:

PayPal
Braintree offers a few options when accepting PayPal payments. First,
you'll need to choose whether you would like to use our Drop-In UI or
a custom integration.
Vault vs. Checkout
Next, you can choose between our Vault and Checkout flows. Below is a
comparison of the two options:

*

*Vault Compatibility: iOS, Android, and web

*Checkout Compatibility: Web only


text:
Q: How do I create a 3 second delay in this jQuery? jQuery.noConflict();

jQuery(document).ready(function() {

    // milliseconds
    var intervalTime = 75,

    div = jQuery(".animate"), st = div.text(), timer, count = 0, total = st.length;
    div.html("").css("visibility", "visible");

    timer = setInterval(showLetters, intervalTime);

    function showLetters() {

        if(count < total) {

            div.html(div.text().split("_").join("") + st.charAt(count) + "");
            count++;

        }
        else {

            clearInterval(timer);

        }

    }

});

Some text here.

A: To 'wait' to do something in Javascript, you can always use
setTimeout(callback, intervalInMillis)

So if its showLetters() you want to wait 3 seconds to do, you would need
setTimeout(showLetters(), 3000);

Hope that helps!


text:
Q: Amchart responsive issue I am facing issue in AmChart responsiveness.
Please find codepen here: codepen
The x axis labels are visible in wide screen UI.

But for tab screens, some labels are not visible

I  want all labels to be visible in all screens.

A: AmCharts automatically tweaks how many labels are visible in an axis by default due to  autoGridCount being enabled. You can force all labels to be visible by setting it to false and setting the gridCount property equal to the number of data points in your dataProvider.
categoryAxis: {
  // ...
  autoGridCount: false,
  gridCount: /* dataProvider size */
}


text:
Q: iFrames Iexplorer doesn't write or read sessions (or cookies) I built a form to submit data step by step. In between steps data is carried on from step 1 to step 2 and so on. That data is needed. 50% of the visitors access the form from different sites using an iframe.
Initially the data was stored in cookies. That worked in almost every browser, except iexplorer. I played for days with P3P but gave up. Nothing changed whatsoever. I then read that sessions didn't have this problem. So i changed the whole loginsystem to sessions.
Now I am testing the system and still every browser works using the form in an iframe, except ofcoarse Iexplorer.
Is there anything i can do?
Update: The server was in another timezone while it was located in my timezone. Changing the timezone was supposed to help, but didn't.

A: Took some time, but it's solved. Here we go:

*

*Sometimes the timezone is incorrect. If the difference is more than an hour, Iexplorer sessions will be destroyed inmidiatelly. You can change the timezone manually or ask your webhoster to do so. In PHP you can try: date_default_timezone_set(string $timezone_identifier)

*In addition to 1, sometimes it's impossible to stay within an hour. If so, you can change the session cache expire settings. In PHP it's <?php session_cache_expire(1440); ?>

*IE in iframes apparenty has an issue with underscores sometimes. When using underscores, IE rejects the cookie. So don't use them or make sure that IE doesn't store it's sessions that way.

*Use P3P (check if it's legally allowed and such!). In PHP you could use header('P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
That's all i tried and together they worked (not on their own).


text:
Q: How to add item/entity to a queue dynamics crm 2011 using SOAP endpoint How can I add an item/entity to a queue in dynamics crm 2011 programmatically using SOAP calls. Any help will greatly appreciated.

A: Use AddToQueueRequest and CRM organization service endpoint to add item to the queue.
For more details see this post. Or this one
Try more Googling before asking the question. It's not very hard to find this info.


text:
Q: Сравнить список с наименованиями и числами в питоне. Найти наименование у которого соответствующее число наивысшее В первом списке имена игроков, во втором списке количество их очков.Нужно найти победителя(того у кого больше всего очков, если у двух игроков одинаковое кол-во наивысших балов, победителем считается первый в списке.
my_list = [['Vasya', 'Sasha', 'Kolya', 'Igor'], [5, 4, 3, 4]]
winner = 'Vasya'
my_list2= [['Igor', 'Kolya', 'Petya', 'Sasha'], [4, 6, 6, 3]]
winner2 = 'Kolya'

A: ну например так
my_list = [['Vasya', 'Sasha', 'Kolya', 'Igor'], [5, 4, 3, 4]]
winner = my_list[0][my_list[1].index(max(my_list[1]))]
print(winner)

my_list = [['Igor', 'Kolya', 'Petya', 'Sasha'], [4, 6, 6, 3]]
winner = my_list[0][my_list[1].index(max(my_list[1]))]
print(winner)

а вообще самому надо для начала пытаться делать школьное задание ;-)

A: Ещё вариант:
winner = sorted(zip(*my_list), key=lambda x: -x[1])[0][0]


text:
Q: how to use recordset movelast i need help for the code that i can use old rs.movelast to vb.net 2010..
any simple way to query my record that automatic select the last..
here is my connection sample i just call it only in any form..///
Public Function ExecuteSQLQuery(ByVal SQLQuery As String) As DataTable
    Try
        Dim sqlCon As New OleDbConnection(CnString)
        Dim sqlDA As New OleDbDataAdapter(SQLQuery, sqlCon)
        Dim sqlCB As New OleDbCommandBuilder(sqlDA)
        sqlDT.Reset() ' refresh
        sqlDA.Fill(sqlDT)
    Catch ex As Exception
        MsgBox("Error : " & ex.Message)
    End Try
    Return sqlDT
End Function

A: sqlDT.rows(sqlDT.rows.count-1) will be the last record of your DataTable sqlDT. sqlDT.rows.count-1 will return you the last index of the rows in the filled table. Hope it will help you. Thanks
Imports System.Data.OleDb

Public Class Form1

Public CnString As String = "Provider=SQLOLEDB;Data Source=HP-PC\SQLEXPRESS;Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=Accounts"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim ssql As String = "Select * from TBL_Access"
    Dim dt As DataTable

    dt = ExecuteSQLQuery(ssql)
    TextBox1.Text = dt.Rows(dt.Rows.Count - 1)(0) 'Value of First Column of Last Row of DataTable dt
    TextBox2.Text = dt.Rows(dt.Rows.Count - 1)(1) 'Value of Second Column of Last Row of DataTable dt
End Sub

Public Function ExecuteSQLQuery(ByVal SQLQuery As String) As DataTable
    Try

        Dim sqlCon As New OleDbConnection(CnString)
        Dim sqlDA As New OleDbDataAdapter(SQLQuery, sqlCon)
        Dim sqlCB As New OleDbCommandBuilder(sqlDA)
        Dim sqlDT As New DataTable
        sqlDT.Reset() ' refresh
        sqlDA.Fill(sqlDT)
        Return sqlDT
    Catch ex As Exception
        MsgBox("Error : " & ex.Message)
        Return Nothing

    End Try
End Function

End Class


text:
Q: How to get data in array I am a beginner to python and trying to implement a leaderboard system. I have the below array.
points = [(userid1, 500),(userid2,600),(userid3,100)]
How do I use python to get userid3's points.
Thanks

A: In python, you access the ith element of a list with the syntax list[i-1] (because list indexes start at 0).
Therefore, userid3_info = points[2] will give the variable userid3_info the value (userid3,100).
You do the same thing to access the jth element of a tuple.
So userid3_points = userid3_info[1] will give userid3_points the value 100

A: To get elements of the differents collections of python always use []. Points is a list of tuples, both are collections of data. So to access "userid3" point you should do points[2][1]. Inside the brackets you specify the index of the element, in this case "userid3" is in the position 2 of the list (counting from 0) and the points of it is in position 1.

A: You refer to an array element by referring to the index number.
you can use something like this points[2] it will access tuple. you can get user userid3 point by points[2][1]
refer This Post


text:
Q: Split string by array of characters i want to split a string by array of characters,
so i have this code:
String target = "hello,any|body here?";
char[] delim = {'|',',',' '};
String regex = "(" + new String(delim).replaceAll("(.)", "\\\\$1|").replaceAll("\\|$", ")");
String[] result = target.split(regex);

everything works fine except when i want to add a character like 'Q' to delim[] array,
it throws exception :
java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index 11
(\ |\,|\||\Q)

so how can i fix that to work with non-special characters as well?
thanks in advance

A:
how can i fix that to work with non-special characters as well

Put square brackets around your characters, instead of escaping them. Make sure that if ^ is included in your list of characters, you need to make sure it's not the first character, or escape it separately if it's the only character on the list.
Dashes also need special treatment - they need to go at the beginning or at the end of the regex.
String delimStr = String(delim);
String regex;
if (delimStr.equals("^") {
    regex = "\\^"
} else if (delimStr.charAt(0) == '^') {
    // This assumes that all characters are distinct.
    // You may need a stricter check to make this work in general case.
    regex = "[" + delimStr.charAt(1) + delimStr + "]";
} else {
    regex = "[" + delimStr + "]";
}

A: Using Pattern.quote and putting it in square brackets seems to work:
String regex = "[" + Pattern.quote(new String(delim)) + "]";

Tested with possible problem characters.

A: Q is not a control character in a regex, so you do not have to put the \\ before it (it only serves to mark that you must interpret the following character as a literal, and not as a control character).
Example
`\\.` in a regex means "a dot"

`.` in a regex means "any character"

\\Q fails because Q is not special character in a regex, so it does not need to be quoted.
I would make delim a String array and add the quotes to these values that need it.
 delim = {"\\|", ..... "Q"};


text:
Q: I need help converting awk to stand alone bash script Need help converting the following to stand alone code.
awk '{ for (i=1; i<=NF; i++) {a[NR,i] = $i} }
    NF>p { p = NF }
    END {
        for(j=1; j<=p; j++) {
            str=a[1,j]
            for(i=2; i<=NR; i++)
        {str=str"   "a[i,j];}
        printf str"\n"}
    }' $temp_input

Clarification: I meant stand alone bash script not utilizing AWK. I wrote this utilizing AWK but cant figure out how to structure this without AWK. I played around with this to get it to work, it does but can never replicate this in Bash script. that is why i said stand alone code.
the end format of the returned data never matches when AWK is translated into Bash. it appears to be the same however during testing they are different when writen in Bash not using AWK.

A: I'm not entirely sure I understand the question correctly. If you want a script that executes that awk code on whatever file is supplied as a parameter, you don't need bash at all; you can just make an awk script:
#!/usr/bin/awk -f
{ for (i=1; i<=NF; i++) {a[NR,i] = $i} }
NF>p { p = NF }
END {
    for(j=1; j<=p; j++) {
        str=a[1,j]
        for(i=2; i<=NR; i++)
    {str=str"   "a[i,j];}
    printf str"\n"}
}

If you want a bash wrapper around it, you could do something like this:
#!/bin/bash
awk '{ for (i=1; i<=NF; i++) {a[NR,i] = $i} }
    NF>p { p = NF }
    END {
        for(j=1; j<=p; j++) {
            str=a[1,j]
            for(i=2; i<=NR; i++)
        {str=str"   "a[i,j];}
        printf str"\n"}
    }' "$@"

(Note that "$@" is the standard way to pass on parameter(s) passed to the script.)
In either case, you should add execute permission to the script (e.g. if you named the script rotatefields, you'd use chmod +x rotatefields). Then either place it in one of the directories in your $PATH and just run it by name (e.g. rotatefields filetorotate), or run it from the same directory it's in with ./rotatefields filetorotate, or if it's in some other directory specify the full path (/path/to/rotatefields filetorotate).
(Note: Do not run them with sh rotatefields -- that overrides the shebang line and runs it with plain sh, which can cause trouble.)


text:
Q: Property not being ignored in EntityTypeConfiguration? I have a simple entity class with a list of base classes, which is ignored in the model:
public class MyClass
{
    public int Id {get;set;}
    public List<BaseChild> BaseChildren {get; set;}
}

Which has this configuration:
public class MyClassConfiguration : IEntityTypeConfiguration<MyClass>
{
    public void Configure(EntityTypeBuilder<MyClass> builder)
    {
        builder.Property(o => o.Id).UseHiLo();
        builder.HasKey(o => o.Id);

        builder.Ignore(o => o.BaseChildren);
    }
}

I have classes that inherit from BaseChild and they all use this configuration:
public abstract class BaseChild
{
    public int MyClassId { get; set; }
}

public abstract class BaseChildConfiguration<T> : IEntityTypeConfiguration<T> where T : BaseChild
{
    public virtual void Configure(EntityTypeBuilder<T> builder)
    {
        builder.HasKey(o => o.MyClassId);
        builder.HasOne<MyClass>()
            .WithOne()
            .HasForeignKey<T>(o => o.MyClassId);
    }
}

public class Instance : Component
{
    public long Code { get; set; }
}

public class InstanceConfiguration : BaseChildConfiguration<Instance>
{
}

All the configurations are properly being applied in my OnModelCreating:
protected override void OnModelCreating(ModelBuilder mb)
{
    mb.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}

Yet for some reason I keep getting the following exception:

A key cannot be configured on 'Instance' because it is a derived type. The key must be configured on the root type 'BaseChild'. If you did not intend for 'BaseChild' to be included in the model, ensure that it is not included in a DbSet property on your context, referenced in a configuration call to ModelBuilder, or referenced from a navigation property on a type that is included in the model.


text:
Q: World Map flat Mercator.svg with country names I have found an awesome World Map flat Mercator unfortunately the ids are arbitrary. Anyone know any Flat SVG maps that have Countries names set as the ids?
Example of this is rounded map with country ids:
<path xmlns="http://www.w3.org/2000/svg" id="russia" d="M817.97,72.93l1.76,6.08l3.52,1.01l3.52-5.57l-2.01-3.8l0.75-3.29h5.28l-1.26,2.53l0.5,9.12l-7.54,18.74l0.75,4.05l-0.25,6.84l14.07,20.51l2.76,0.76l0.25-16.71l2.76-2.53l-3.02-6.58l2.51-2.79l-5.53-7.34l-3.02,0.25l-1-12.15l7.79-2.03l0.5-3.55l4.02-1.01l2.26,2.03l2.76-11.14l4.77-8.1l3.77-2.03l3.27,0.25v-3.8l-5.28-1.01l-7.29-6.08l3.52-4.05l-3.02-6.84l2.51-2.53l3.02,4.05l7.54,2.79l8.29,0.76l1.01-3.54l-4.27-4.3l4.77-6.58l-10.81-3.8l-2.76,5.57l-3.52-4.56l-19.85-6.84l-18.85,3.29l-2.76,1.52v1.52l4.02,2.03l-0.5,4.81l-7.29-3.04l-16.08,6.33l-2.76-5.82h-11.06l-5.03,5.32l-17.84-4.05l-16.33,3.29l-2.01,5.06l2.51,0.76l-0.25,3.8l-15.83,1.77l1.01,5.06l-14.58-2.53l3.52-6.58l-14.83-0.76l1.26,6.84l-4.77,2.28l-4.02-3.8l-16.33,2.79l-6.28,5.82l-0.25,3.54l-4.02,0.25l-0.5-4.05l12.82-11.14v-7.6l-8.29-2.28l-10.81,3.54l-4.52-4.56h-2.01l-2.51,5.06l2.01,2.28l-14.33,7.85l-12.31,9.37l-7.54,10.38v4.3l8.04,3.29l-4.02,3.04l-8.54-3.04l-3.52,3.04l-5.28-6.08l-1.01,2.28l5.78,18.23l1.51,0.51l4.02-2.03l2.01,1.52v3.29l-3.77-1.52l-2.26,1.77l1.51,3.29l-1.26,8.61l-7.79,0.76l-0.5-2.79l4.52-2.79l1.01-7.6l-5.03-6.58l-1.76-11.39l-8.04-1.27l-0.75,4.05l1.51,2.03l-3.27,2.79l1.26,7.6l4.77,2.03l1.01,5.57l-4.78-3.04l-12.31-2.28l-1.51,4.05l-9.8,3.54l-1.51-2.53l-12.82,7.09l-0.25,4.81l-5.03,0.76l1.51-3.54v-3.54l-5.03-1.77l-3.27,1.27l2.76,5.32l2.01,3.54v2.79l-3.77-0.76l-0.75-0.76l-3.77,4.05l2.01,3.54l-8.54-0.25l2.76,3.55l-0.75,1.52h-4.52l-3.27-2.28l-0.75-6.33l-5.28-2.03v-2.53l11.06,2.28l6.03,0.51l2.51-3.8l-2.26-4.05l-16.08-6.33l-5.55,1.38l-1.9,1.63l0.59,3.75l2.36,0.41l-0.55,5.9l7.28,17.1l-5.26,8.34l-0.36,1.88l2.67,1.88l-2.41,1.59l-1.6,0.03l0.3,7.35l2.21,3.13l0.03,3.04l2.83,0.26l4.33,1.65l4.58,6.3l0.05,1.66l-1.49,2.55l3.42-0.19l3.33,0.96l4.5,6.37l11.08,1.01l-0.48,7.58l-3.82,3.27l0.79,1.28l-3.77,4.05l-1,3.8l2.26,3.29l7.29,2.53l3.02-1.77l19.35,7.34l0.75-2.03l-4.02-3.8v-4.81l-2.51-0.76l0.5-4.05l4.02-4.81l-7.21-5.4l0.5-7.51l7.71-5.07l9.05,0.51l1.51,2.79l9.3,0.51l6.79-3.8l-3.52-3.8l0.75-7.09l17.59-8.61l13.53,6.1l4.52-4.05l13.32,12.66l10.05-1.01l3.52,3.54l9.55,1.01l6.28-8.61l8.04,3.55l4.27,0.76l4.27-3.8l-3.77-2.53l3.27-5.06l9.3,3.04l2.01,4.05l4.02,0.25l2.51-1.77l6.79-0.25l0.75,1.77l7.79,0.51l5.28-5.57l10.81,1.27l3.27-1.27l1-6.08l-3.27-7.34l3.27-2.79h10.3l9.8,11.65l12.56,7.09h3.77l0.5-3.04l4.52-2.79l0.5,16.46l-4.02,0.25v4.05l2.26,2.79l-0.42,3.62l1.67,0.69l1.01-2.53l1.51,0.51l1,1.01l4.52-1.01l4.52-13.17l0.5-16.46l-5.78-13.17l-7.29-8.86l-3.52,0.51v2.79l-8.54-3.29l3.27-7.09l2.76-18.74l11.56-3.54l5.53-3.54h6.03L805.86,96l1.51,2.53l5.28-5.57l3.02,0.25l-0.5-3.29l-4.78-1.01l3.27-11.9L817.97,72.93L817.97,72.93z"/>

Flat map without proper country ids:
<path xmlns="http://www.w3.org/2000/svg" style="fill:#b9b9b9;fill-opacity:1;stroke:#ffffff" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" inkscape:connector-curvature="0" id="path4123" d="m 997.62384,503.51361 7.83296,-0.167 3.667,2 6,1.333 2.667,2.167 5.5,0.167 1.833,2.833 4.5,1.167 2.667,2.5 1.833,0.667 2,-2.167 -2,-4.167 -2.75,-4 1,-3.5 -1.5,-0.75 -1.25,-2.5 -2.25,-0.75 2.5,-2.75 2,-5.25 0.75,-2 2,2.25 1.667,-1.583 0.333,-2.5 2,-2.667 -1.167,-2 -7.167,-6.833 -1.667,-2.833 2.5,-13.167 5.167,3.667 0.833,-2.5 -0.833,-2.333 1.5,-2 0.083,-3.25 3.083,0.417 3.833,-2.167 0.5,-1.667 3,1 -0.5,2.167 2.167,-1.5 2.333,0.167 2.667,-0.833 2.833,0.833 3.333,3.333 0.667,3.333 1.583,-2.583 1.083,0.417 2.167,1.5 2.167,0.333 2.167,-2.5 h 3.5 l 1.833,1.167 3.833,-1 1.5,2.5 2.833,1.5 2.167,-1.667 3.5,1.333 4.167,-5 -2,-1.333 -2.917,-0.25 -1.25,-2.417 -1.833,-1.167 3.833,-1.667 -0.5,-4.833 6,0.167 -2.75,-4.583 1.75,-1.583 -2.667,-1.333 1.167,-2.667 2.833,0.667 10,-1.667 3,0.333 4,-3.667 7.167,-0.667 2.5,-1.167 3.5,-3.5 3.25,1.25 3.917,0.583 1.083,3.667 1.083,1.333 -0.5,3.167 2.167,1.667 0.667,-1.667 2.583,0.5 0.75,1.5 2.333,-0.833 0.5,1 0.333,2.5 5.833,0.333 1.833,-2.333 2,-0.333 2.5,-4.667 3,-0.167 -1.5,2.667 6.417,7.833 4.75,4.5 3.75,8.25 1.083,2.417 3.333,-3.833 1.833,1 2,3.667 4,-0.167 3,-1 2.667,0.333 2.833,5.667 2.5,-0.167 2.167,3 2.333,-0.333 2.5,-1.333 1.333,2.5 -0.667,1.5 h 4.5 l 1.833,-2.25 3.833,-0.25 1.167,-2.667 2.25,0.667 2.5,-1.75 3.583,-0.583 2.333,-2 1.667,0.333 0.5,-1 2.167,2.167 5.667,-0.167 2.583,2.5 1.25,1 4,-0.333 6.667,1.667 2,-0.667 0.667,-5 -1.833,-0.833 -0.333,-3.5 1.5,-4.667 1.833,1.333 1.167,-3.5 4.333,2.25 6.167,1.75 0.833,1.5 3.75,0.25 -0.583,3.25 1.667,3.333 3.917,1.167 2.417,-0.333 1.833,-1.167 5.333,0.667 1.167,0.833 3.333,-0.167 3.417,3.167 4.25,1.833 4.5,0.917 5.5,1 4.667,-1.25 4.583,-2 1.75,-2.25 1,-2 3.5,-0.917 2.25,0.167 1.75,2.5 0.5,1.333 2.833,-0.667 3.417,1.083 4.417,2.583 2.083,-2.333 1.75,-1.75 1.833,-0.083 -0.083,-2.917 1.917,-4.417 3,-3.5 1.167,-4.333 -1.833,-2.25 -1,-0.5 2.667,-3.75 4.083,-0.5 4.083,-0.167 3.667,-1.083 3.5,2 3.833,1.917 0.5,-1 3.167,2.833 3.75,9.25 3.417,7.25 v 2.833 l 1.333,1.333 6.833,1.167 3.5,5.167 1.167,-0.333 -0.5,2.167 1.5,1.917 v 2.417 l 3.25,1.333 4.75,-1.75 6.25,-1.75 4.583,-1.333 -1.333,2.667 -0.5,3 -1.5,1.667 -0.5,3.5 -2.333,4.333 -1.333,3.833 -1.5,1.5 0.167,1.667 -4.5,-1.583 -1.667,0.583 -1.333,1.917 -1.75,0.25 1.25,5 -0.667,4 -0.167,1.5 -3.333,2.083 1.583,1.667 0.458,-1.5 1.5,0.25 1.625,-0.875 0.75,-2.125 0.25,-1.375 0.5,-0.875 0.375,2.25 1.625,-1 0.75,1.25 2.375,1 1.875,0.75 2.25,-1.5 2,-0.625 3,-2.375 1.625,-2.375 2.375,-3.125 h 1 c 0,0 1.5,-4.25 1.875,-4.5 0.375,-0.25 3.75,-2.375 3.75,-2.375 l 2.625,-5 1.5,-3 1.125,-2.875 1.25,-0.875 0.75,-2.375 2,-2.375 1.625,-2.25 1.5,-2 -0.375,-3.625 1.25,-1.125 -0.125,-3.25 -0.25,-3.25 1.125,-4.75 0.25,-3 1.875,-2 0.875,-1.75 1.125,-0.125 0.25,2.75 1.75,2.875 -0.125,4.25 -0.125,4.375 0.125,5.375 -1.875,4.375 1.25,0.5 0.75,3.625 -0.875,2.25 0.125,4.125 -1.125,2 0.5,3.875 1.5,1.75 0.25,-2.375 0.25,-2.125 1.875,-1.375 c 0,0 1.75,1 2,1.375 0.25,0.375 1.75,2.25 1.75,2.25 l 0.125,-2.125 -2,-3.125 -0.875,-2.125 -2.5,-2 0.625,-3 1,-3.125 0.25,-2.625 2.625,-1.875 h 2.75 l 2.625,3.5 1.375,-0.625 -1.75,-2.125 -2,-3.375 -1.625,-4.75 -0.875,-4.125 -0.625,-3.25 -0.25,-2.375 -1.75,-2.5 0.625,-2.625 0.875,0.75 -0.5,-5.75 -0.625,-3.375 -0.75,-1.875 0.375,-1.125 -0.875,-2.25 -1.375,0.5 -1.75,0.125 2.125,2 -0.125,2.125 -2,1 -1.875,0.875 0.75,2.25 0.5,1.625 -0.75,2.375 -0.375,1.5 -0.125,1.125 h -1.375 l -0.625,-1.5 1.25,-0.125 -0.75,-2.625 -0.75,-1 0.75,-0.875 0.125,-1.75 -1.75,-1.625 -1.875,-1.125 -0.875,-1.375 -2.25,-1.875 -0.375,-0.875 -1.75,0.875 -2.625,-1.375 0.125,2.875 -0.375,2.5 -1.375,-0.25 0.5,-2.625 -1.875,1.25 -0.875,1.75 h -2.5 l 1.875,-2.125 -0.75,-1 0.875,-2 h -2.5 l -1.125,2.125 -0.25,-1.875 0.25,-2.125 -1.625,-1.125 -3.125,0.75 -2,-1.25 0.75,-2.375 2.5,-1.5 2.375,-2 2.625,-2.875 2.875,-2.125 2,-3.75 3.625,-4.125 2.5,-2.125 v -3 h 2.125 l 1.875,-4 3.875,-3 3.125,-2.875 4.25,-0.375 5.875,-0.25 2.5,-1.5 1.875,-0.5 0.875,0.75 1.5,-0.25 1.375,-1.5 2.5,0.875 1.625,0.625 2.375,-0.625 1.75,0.625 1,0.625 2.125,-0.5 -0.875,-1.25 1.125,-1 0.25,-2.375 2.625,0.75 3.625,1.833 3.5,0.167 1.833,1 c 0,0 3.5,1.5 3,1.5 -0.5,0 -5.166,0 -5.166,0 l -0.334,2 2.5,1.167 2.834,-1.5 2.5,0.5 2,-2.167 2.833,1.5 1.5,-2.167 4,0.5 -2.667,-3 h -2.166 l -0.167,-4.167 1.167,1.167 1.666,-4.667 3.334,-2.167 1.833,-3 3.167,-2 -0.334,-2.833 6.834,-2 3.833,-0.833 0.833,1.167 3.167,-1.333 -0.833,4.333 -1,1.5 0.333,3.167 2.167,-1 -1.167,3.333 2.833,-1.667 2.834,-2.333 4.166,-3.667 2,-1.667 1.167,1 0.167,-3.5 0.166,-4.5 2.167,-1.5 4.667,-1 2.333,2.5 -4.333,0.833 -0.667,4.167 -1.167,2.833 0.167,2.5 -1,1.833 -0.5,2.833 -2.667,0.167 -3.5,2.167 -0.166,2.5 -6.5,5.833 -2.834,4 -4,4.833 -3.333,4.5 -2.667,0.667 -2.5,-0.333 v 3.167 l -1.333,3 -3.833,4 -0.667,8.833 v 6.167 l 1,6.5 2,7.667 0.333,4.667 0.667,4.833 1,2 -1.833,1.5 -2.167,1 -2.833,2.167 -0.834,2 v 2 l -1.166,1.833 -1.5,2.167 -2,2.333 -1.334,3.333 -2.333,1.5 -1,2.5 -1.333,2.5 -2.5,1.167 -1.834,2.333 -3.667,2.833 -3,0.833 -2.167,2.833 -2.5,2 h -2.167 l -2.333,-0.5 -1.333,2.333 -3.5,2.667 -1,1.333 -1.667,-0.333 -1.833,2 -0.5,1.833 1.167,-1 2.167,-1.167 0.667,-0.667 2,-1.667 v 1.833 l 2.333,-2.167 2,-1.667 2,-1.333 2.333,-0.833 2,-1.833 0.833,1 1.333,-2 2.333,-1.5 0.5,-1.167 4.833,-3.167 1.5,-0.167 1.5,-1.833 0.5,-1 1.5,-2.5 1.666,-0.833 -0.166,-1.5 0.833,-0.833 0.667,-0.833 1.333,-2 0.667,-1.5 2,-0.667 -0.334,-1.167 1.667,-1.5 1.333,-1.167 -0.666,-1 1,-2.833 2.833,-0.667 1,-2.833 0.833,-0.833 1.167,-1.333 1.5,-1 2.333,-1.667 1.5,-1.667 1.5,-1.833 2.334,-4.833 -0.5,-3.667 v -1 h 2.333 l 2.167,-1.167 2.166,0.833 -0.333,-4.5 -0.333,-1.667 3.5,-4.333 2.333,-0.167 1.333,0.5 2.334,-1.833 -1,-3 -0.667,-3 1.333,-3.333 0.167,-2 3.167,-1.667 -1,3.333 2,1.167 1.5,-3 -1,-1.833 v -2 h -2.167 l 1,-4.833 1,-1.833 -2.667,-1.833 -2.166,1.167 0.333,-3.833 2.167,-3.667 1.333,-3.333 0.833,-2.833 0.834,-3 1.166,-2.167 2.834,-1.667 c 0,0 -0.5,1.833 0,1.333 0.5,-0.5 2.666,-1.5 2.666,-1.5 l 0.167,2.333 4.167,-3.5 2.166,-0.833 -0.666,4.5 1.333,-0.5 3.5,-4.167 3.667,-1 3.833,-0.667 3,2.167 2.333,3.333 3.167,-4.667 3.667,-3 7.166,-7.333 4.667,-3.333 6.5,-2.333 5.167,-3.333 6.5,1 2.166,2.167 1,-3.833 -0.666,-3.833 -2.5,-4.5 -2,-2.333 0.833,-4.833 -0.333,-1.333 -4.667,-0.667 0.167,-4 4.833,1 2.667,-0.833 3.333,-2 3.833,-4.167 -2.166,-4.5 -0.667,-2.667 3.667,-0.833 2.5,-1.167 -0.834,3 1.5,4.167 -2,1.167 5.167,0.333 2.5,-1.167 3.167,1.5 2.5,3.833 -0.834,0.833 3.834,2.5 2.833,-0.5 1.5,2.833 1.667,2.667 3.666,-1 v -3.333 l 2.5,-2.833 1.667,-3.333 -2.333,-2.833 5.333,1.667 1.167,-2 2,-2 3.833,-2.5 -3.667,-3.167 -4.833,-4.333 -3.667,-2.5 -2.5,0.333 -3.166,-2.333 h -3 l 0.666,5.167 -1.5,-2 -1.166,-4 -0.667,-4.5 -3.5,-2.167 0.5,2.333 -3.167,-2.667 0.167,-2 -4,-2.333 -6.167,-4.167 -0.833,-3 -5.667,-3 -4.333,-4.333 -5.333,-1.333 -5,-3.5 -2.5,-2.5 -8.167,0.5 h -6 l -9,-2 -0.334,4.333 -1.333,1.667 3.833,3.333 -0.666,3.667 -4.834,2.333 -3,-2.667 -2.166,-1 -0.334,-4.167 -2.333,-2.5 3,1.333 2.667,-1 -0.167,-2.833 -4.833,-1.167 v 2.167 l -1.667,1.667 -3,1.333 -0.667,2.833 -1.5,-2 -3.833,-0.333 -4.833,-0.167 -3.667,-3.167 -2.5,1.333 -4,0.333 -2.5,2 -3,-1.167 -4.167,-2.5 -2.666,-0.833 1.5,-3 0.5,-2.833 -1.667,-4.167 -2.667,-3.833 -5.666,-1 -6.334,0.333 -10.166,0.5 -3.667,0.167 -2.833,0.167 -0.834,-2.5 -0.666,-3.833 -3.834,0.167 -2.833,-2.667 -2.333,-1.667 -3.833,-0.333 1.833,-1.667 3.833,0.333 -2.167,-4.5 -5.667,-2.667 -5.333,0.333 -2.5,5.167 -3.333,3.333 -3.333,1.333 -0.333,-2.667 1.667,-2.167 3,-3.667 -0.333,5 3.167,-6.833 -3.667,1 -3.167,1 -3.667,-1 0.333,-3 5.5,0.833 3,-0.667 -4.333,-1.667 -4.833,-0.833 -6.167,-1.5 -4.333,-0.167 -3.5,-1.167 -0.333,3.833 -1.667,2 h -4.333 l -2.167,2.833 h 4.5 l -2.833,3.667 3,6.167 -4.5,0.833 -2,-1.833 -3.333,2.5 -2.333,-2.333 h -3.167 l -5.667,-1.167 -4,4.5 -3.667,-2.5 -3.833,-5.167 -3.333,8.167 -0.667,4.5 -2.333,2.167 -3.5,-3.167 -5.167,-3.5 -0.667,-4.5 -0.667,-4.333 1.333,-4 0.833,-7 -0.5,-5 -5.5,-6.833 -6.5,0.333 -6.833,-3.167 -7,-1.667 -1,6 0.667,5.5 -3.667,0.5 -9.333,-0.833 -4.5,-1.167 -2.667,0.833 -1.5,-4.333 2.5,-1 -6.667,-1.667 -9,-1.833 -4.333,1.833 -4.333,0.167 -1,-4.833 -1.333,-1.5 -1.5,4.167 -4.167,-1.667 -0.333,-3.333 -3.833,1.833 -3.167,-0.333 -0.667,4.833 3.167,1 -6,4.167 -8,1 -4.167,1.5 1.333,-3.833 6,-4.833 2.333,-0.833 4.333,-5.167 3.333,-4.833 7,-4.5 2.833,1.833 -4.333,3.333 2.667,3.833 3.5,-1.167 3,-4.5 -4,-1.167 -3.5,-2.833 2.333,-2.667 4,-3.333 2,-4.333 1,-3 -2.833,-2.667 2.333,-1.333 0.167,-3.333 -2.333,-4.167 -0.667,-2.833 -2.667,1.833 -1.5,-6.333 -5.667,-3 -7.833,-0.833 -5.833,1.167 -1.167,2.667 h -7.167 l 5.5,-5.5 1.5,-3.667 -8.167,-1.333 -4.333,0.833 4.167,-5.5 2.5,-3.167 -5.333,-2 -5.5,-1 -7.333,4.833 -5.333,9.5 1.5,3.5 1.5,4.667 -5.833,-0.667 h -4.5 l 3,4.5 -4.333,0.333 -6.5,3.333 -6,2 2.167,-5.167 -7,2 c 0,0 -9.333,0.667 -8.833,1 0.5,0.333 5.5,2.5 5.5,2.5 l -13,4.333 -8.5,4.667 -5,4.333 -3.167,-0.167 -0.833,4.167 -4,1.833 3.333,5.167 c 0,0 -3.333,2 -2.833,2.667 0.5,0.667 7,6.167 7,6.167 l -4.167,2 -6,0.833 -6.333,-0.333 -7,1.667 -5.167,1.667 -2,5.5 2.5,6.333 -0.667,3.667 4.667,3.833 2,1.333 1.667,3.667 2.5,1.833 -0.333,4.833 0.333,7.833 -2.167,-0.833 -2,1.167 v -5.833 l 2.667,-3.667 0.167,-3 -2.833,-0.667 -2.167,1 -4,-3.5 -5.833,-5.167 -4.5,-1 -4,2.833 1.833,2.833 -2.333,1.667 -3.167,-2.5 -3.333,1.833 4.667,7.167 5.667,1.667 -1.333,4 -4.167,-2.833 -4,-0.5 -5,-2.333 1,-6.333 c 0,0 0.333,-5.167 0.333,-5.667 0,-0.5 0,-6.667 0,-6.667 l -2.667,-2.833 v 2.833 l 0.667,4 -1.667,4.667 -6,3.5 -0.833,5.5 4.833,7.333 0.667,5 -2.667,6 -0.167,6.667 2,6 5.833,-2.167 h 5.167 l 4,4.5 0.833,6 1,2.167 -2.167,3.167 2.167,1.667 1.833,1.667 -2.667,0.833 -3.5,-2.167 1.333,-5.333 -1.167,-4 -2.667,-5 -8.5,3 -1.167,5.167 3.333,5.5 -3.5,3.333 -1.5,2.833 -2.167,4 -4.667,3.5 0.167,3.667 -4.667,-1.833 -5,-0.333 3.333,-2.333 3.5,-2 3.167,-4.833 0.833,-3.5 2.833,-2.167 0.167,-5.167 2.333,-4.333 -5.167,-5 -0.167,-7 1.167,-6 -1.667,-4.167 2.333,-0.833 -0.5,-9 -3.333,-5 -0.5,-2.833 1.833,-7.833 1,-5.667 -0.833,-3.167 -4.833,-1.333 -4.5,0.167 1.167,-2.833 4.667,-0.833 -2.167,-3.167 -2.667,-1.667 -3.167,3.667 2.333,2.5 -1.167,2.5 -2.333,-0.833 -1.5,2.667 -0.833,3.333 -1.333,5.333 -1,4.833 -2.333,5 -4.833,4 1.167,2.5 -3,1.833 1.167,1.833 2.333,-1 v 3.333 3.667 l 0.5,2.667 -2.667,1.833 0.833,4.5 1.667,-1.5 3,2.167 0.667,-0.5 v 4 l 2.5,4 1.333,0.167 -0.833,4.333 -1.667,3.833 -2.167,-3.167 -2.333,-3.167 c 0,0 -1.5,-2.5 -2,-2.5 -0.5,0 -3.833,-0.667 -3.833,-0.667 l -5,-3.167 -3.833,-3.833 -4,-1.833 -5,-1.167 -4.5,-0.167 -2.167,0.667 -1.333,-4.167 -6.167,-5 -0.333,3 1.167,3.667 2.833,2.667 3.5,0.5 v 1.333 l 0.667,3.333 1.833,3.5 -0.5,3.5 -3.333,0.833 -0.5,3.833 -2.833,-0.5 v -4.833 l -1.333,-2.667 -3.5,2.667 -3.5,1 -0.167,2 -4,-0.5 -4.5,0.833 -2,4.167 -4.167,-0.5 c 0,0 -4.833,-0.667 -3,-1 1.833,-0.333 4.167,-2.5 4.167,-2.5 v -3.667 l -4.833,-0.167 -3.333,2 0.5,3.833 -3.833,-1.833 -3.833,3.333 -8.833,3.833 -2.333,3.5 -2,5.667 -2.833,2.5 -5.833,-1.667 -1.833,-4.167 0.667,-4.167 2.667,-0.333 2.833,-1.167 -0.833,-2.667 -1.5,-1.833 -1.833,-2.667 -5.667,-0.167 -5.667,-2 3.833,4.167 0.833,3.167 -0.833,4.333 -1.5,3.333 2.333,2.833 1.333,2.833 -0.833,5 0.333,5.667 -3.833,-4.5 -4.333,-1.833 -1.667,2.333 -4.167,3.167 -4.49996,2.833 c 0,0 -1.167,2 -0.833,2.5 0.334,0.5 2.33296,5.833 2.33296,5.833 l 2.167,3.167 -2.5,0.667 -4.49996,-2 -5.333,-1.333 -4.333,-3.167 c 0,0 -3.167,3.333 -2.667,3.667 0.5,0.334 4.167,4.833 4.167,4.833 l 3,-1 1.167,4.833 -2.5,0.167 -4.833,-0.333 -4.167,-3.667 -3,-1.833 -2,-4.667 -0.167,-4.5 0.667,-2.333 0.333,-3.167 -3.167,-3 -2.833,-3 -2.5,-2.833 -2.5,0.333 v -3 l 0.167,-2.333 3.5,1.167 1.333,2.5 4,1.667 3.833,1.667 6.167,2.167 3.5,1.833 6.333,1.333 4.5,-2.5 3.83296,-3.167 3.667,-5.333 -1,-3.167 -1.5,-4 -4.99996,-4.167 -5,-2.833 -5.167,-5.333 -4.667,-4.167 -6.667,-2.833 -5.5,-0.167 -3.833,-1.167 -2.667,-3 -3.333,-0.667 -1.833,1.833 -3.333,-0.667 -1,2 -2.833,1.667 -1,3.333 -1.5,-0.167 -1.333,2.833 v 2.167 l 1.5,3.333 3.833,4 1.167,3.5 1.167,0.667 -4.667,7.667 4.667,13.167 -0.833,1 -0.333,3.833 0.333,3.833 1.333,2.167 0.333,3.5 1.5,2.333 -2.167,3.333 2,3.167 2.5,1 0.667,3 1.167,1 -0.667,2.5 -3.167,3 -3,3 -2.333,4 -2,3.667 -3.667,3 -2.333,3.167 3.333,-1.167 0.333,1.833 3.167,2.333 1.667,-0.167 2.167,2.5 -3.833,-0.167 -1.667,0.167 -3,1.667 -1.333,1.833 0.333,2.667 -2.833,2.833 2,5.667 1.667,1.833 0.833,3.167 0.167,5 -0.167,3.333 0.667,1.833 6.167,0.667 0.833,1.833 3.5,-0.5 1.333,6.333 1.5,5 2.333,2.333 0.167,2 2.333,2 -1.167,3.167 -3.333,-0.167 0.667,2.667 0.833,3.833 2.833,-0.5 2.5,-0.167 h 3.167 l 2,2.667 0.667,5 3,0.167 1.5,4 0.667,1.667 3.5,-0.333 2.833,1.167 2.5,-1.5 1.5,2 2.333,1 2.333,1.833 1.167,-0.167 1,1.333 2.66696,0.167 -0.833,3 -0.49996,1.667 1.66696,3.333 -1.66696,2.667 -2.667,0.167 -1.833,1.833 -2.5,1.5 0.833,2 h 3.667 l -4,2.667 -3.667,0.667 3.167,3.833 -2.5,0.333 -2.167,2.833 -2.167,1 -1,1 2.667,1.5 1.5,2.333 5.333,2.167 c 0,0 1.333,0.5 1.833,0.833 0.5,0.333 1.501,3.008 1.501,3.008 z"/>

QUESTION
Where can I find flat map with country ids on the paths.  Or how can I merge these 2 maps to get a visually flat map with country ids?

A: This page has two with ID set to a country abbreviation and also has a title tag that has the country's name http://www.amcharts.com/svg-maps/?map=world Free for non-commercial use

A: You can edit the id="undesired countryname"
or if no id to edit, just add an id string.


text:
Q: add function to a dict class WITHOUT OVERRIDING IT is there any way to add functionality to dict itself?   IE - I do not want to override it - I want to create essential an extension method or mixin.
There are a log of reasons I would like to do this - but for instance - I'd like to do something like
def safe_get( the_dictionary, key ):
    return None if the_dictionary is None else the_dictionary.get(key)

# this does NOT work, because dict is a built in type
dict.safe_get = safe_get

because this is tolerable:
   result = event.safe_get("request_context").safe_get("identity").safe_get("sourceIp")

and this is ridiculous:
   result = safe_get( safe_get( safe_get( event, 'request_context'), 'identity'), 'sourceIp')

or is there another (shorter == better) way of doing the same thing?
When I google I see people defining their own classes and things - but I don't create "event" - it comes from amazon, so I have no control over it, and can't change it to another type. I could wrap it - but that would be even more code :(

A: The question as-is can't really be answered, but there are two alternative solutions I'd propose:
def safe_get(d, *keys):
    for key in keys:
        d = d.get(key)
        if d is None:
            return None
    return d

result = safe_get(event, "request_context", "identity", "sourceIp")

Or:
class NamespaceWrapper:
    def __init__(self, wrapped: dict):
        self._wrapped = wrapped
    def __getattr__(self, attr):
        if self._wrapped is None:
            return self
        return NamespaceWrapper(self, self._wrapped.get(attr))
    def unwrap(self):
        return self._wrapped

result = NamespaceWrapper(event).request_context.identity.sourceIp.unwrap()

The latter solution could be elaborated on, for example:

*

*Add a __getitem__ to access items that aren't valid identifiers;

*Automatically unwrapping anything that isn't a dict or None;

*Turning NamespaceWrapper into a proxy object for the wrapped dict, so things like len(w), key in w and iteration work;

... but I'm leaving that to you as an excercise.

A: dict.get has two arguments. The second one is optional and defaults to None. Use empty dictionary instead to achieve safity during chaining. Here's an example:
result = event.get("request_context", dict()).get("identity", dict()).get("sourceIp")


text:
Q: C++ string of "1" does not match "1" (tried regex and boolean '==') see gif (Visual Studio debugger showing variables):
http://www.elanhickler.com/transfer/regex_does_not_match.gif
bool stob(string s) {
    regex e("1");
    bool b1 = (s == "1"); // false
    bool b2 = (string(s) == "1"); // false
    bool does_it_match1 = regex_match("1", e); // true
    bool does_it_match2 = regex_match(string(s), e); // false
    bool does_it_match3 = regex_match(string("1"), e); // true
    return does_it_match1;
}

Why is it not matching?

the image shows that the input of s is "1", more specifically characters of 49("1") and 0("\0")
ideone: https://ideone.com/b8luZF (this this demosntrates the problem, figured it out thanks to answers below).
#include <iostream>
#include <regex>
#include <string>
using namespace std;

int main() {
    regex e("1");
    string s = "1,";
    s.back() = '\0';

    cout << regex_match("1", e) << endl;
    cout << regex_match(s, e) << endl;

    return 0;
}

A: Unlike C-strings, which start where the pointer points and end right before the first 0-byte, std::strings can actually contain 0-bytes. And that seems to be exactly the case with your string. According to your debugger, the string contains two characters, the first of which is '1' and the second is '\0'.
So you're comparing a 2-character string to a 1-character string and the result is therefore false.


text:
Q: Target and input must have the same number of elements My input label size is torch.size([30, 2, 96, 96, 96])
My labels size is torch.size([30, 96, 96, 96]), I am feeding them to my loss function which goes like this :
loss = F.binary_cross_entropy(F.sigmoid(output),labels,torch.FloatTensor(CLASS_WEIGHTS).cuda())

When I run this, I however get
Value error:Target and input must have the same number of elements.target nelement(26542080) != input nelement(53084160)

I am a little confused here. I get the input value is twice the target value because it multiplies [30,96,96] by the number of classes, but I am not sure why it is so, and how to rectify it. Any suggestions will be helpful, thanks in advance.

A: Unlike the torch.nn.CrossEntropyLoss layer which takes the label values for target (i.e. if input is of shape (30, C, 96, 96, 96) with C number of classes, target must be (30, 96, 96, 96)), torch.nn.functional.binary_cross_entropy() needs input and target to have the same shape (i.e. target of shape (30, C, 96, 96, 96)), so it needs the one-hot representation of the target labels.
Unless you go for torch.nn.CrossEntropyLoss, you have several ways to one-hot your target labels (e.g. see this thread). A personal solution:

def to_one_hot(x, C=2, tensor_class=torch.FloatTensor):
    """ One-hot a batched tensor of shape (B, ...) into (B, C, ...) """
    x_one_hot = tensor_class(x.size(0), C, *x.shape[1:]).zero_()
    x_one_hot = x_one_hot.scatter_(1, x.unsqueeze(1), 1)
    return x_one_hot

# Demonstration:
num_classes = 2
labels = torch.LongTensor(30, 96, 96, 96).random_(0, num_classes)
one_hot_labels = to_one_hot(labels, C=num_classes)
print(one_hot_labels.shape)
# > torch.Size([30, 2, 96, 96, 96])


text:
Q: Is the function $e^{-|x|^k}$ analytic on any interval not containing zero? Let $k \in(0,\infty)$ , is the function $e^{-|x|^k}$ real analytic for any $(a,b)$ such that $a>0$.
To show analyticity on an interval  $(a,b)$ we need to show that there exists a $C>0$ such that
\begin{align}
\left| \frac{d^m}{dx^m}  e^{-|x|^k} \right| \le C^{m+1} m!, \forall x\in (a,b)
\end{align}
I think, for $|x|>a>0$ can also show the bound of the form
\begin{align}
\left| \frac{d^m}{dx^m}  e^{-|x|^k} \right| \le  C^{m+1} |x|^{2(k-1)}e^{-|x|^k}
\end{align}
which would imply the analyticity?  But I am not sure how to do that.
Edit: By composition theorem, we have that $e^{-|x|^k}$ is analytic on any interval away from zero.  See answers below.
However, I would like to get a proof by showing that a bound of the type holds  $\left| \frac{d^m}{dx^m}  e^{-|x|^k} \right| \le  C^{m+1} |x|^{2(k-1)}e^{-|x|^k}$.

A: Yes: If $a < x < b$, then $|x| = x$, and $|x|^{k} = x^{k}$ is real-analytic (Newton's binomial theorem), and a composition of real-analytic functions is real-analytic.

A: The requested bound cannot hold.
From
$$\left(e^P\right)'=P'e^P,\\\left(Qe^P\right)'=(Q'+QP')e^P=Re^P$$
we deduce that the degree of the polynomial factor in front of the exponential follows the recurrence
$$\begin{cases}q=0\to r=p-1,\\q>0\to r=pq-1.\end{cases}$$
Then with $P=-x^k$, the degrees are $0,k-1,k^2-k-1,k^3-k^2-k-1,\cdots k^m-\frac{k^m-1}{k-1}$, and grow much larger than $2(k-1)$.


text:
Q: Liquibase: Change a INT autoincrement column to BIGINT using modifyDataType refactoring with H2 database I have a primary key column which is an INT column which I would like to change to a BIGINT. Our test and production environment uses MySQL, but for unit tests we use the embedded H2 database.
I have created the following Liquibase refactoring:
...
<changeSet id="1" author="trond">
    <modifyDataType tableName="event" columnName="id" newDataType="BIGINT" />
    <rollback>
        <modifyDataType tableName="event" columnName="id" newDataType="INT" />
    </rollback>
</changeSet>
...

The refactoring works, but when I try to persist an object to the database using Hibernate, I get the following error message (I've wrapped the error message):
ERROR org.hibernate.util.JDBCExceptionReporter [main]: NULL not allowed for column "ID";
    SQL statement: insert into event (id, eventtime, guid, meta, objectguid, originatorid, subtype, type) values (null, ?, ?, ?, ?, ?, ?, '0') [90006-140]

JDBC exception on Hibernate data access:
    SQLException for SQL [insert into event (id, eventtime, guid, meta, objectguid, originatorid, subtype, type) values (null, ?, ?, ?, ?, ?, ?, '0')];
    SQL state [90006]; error code [90006]; could not insert: [event.MyEvent];
    nested exception is org.hibernate.exception.GenericJDBCException: could not insert: [event.MyEvent]

The MyEvent class inherits from a AbstractBaseEvent which has defined the following Hibernate mapping in the code:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

A few points:

*

*The hibernate mapping works before the refactoring of the data type

*Version of Liquibase is 2.0.1

*Whether or not this works with MySQL hasn't been tested yet

A: I tested (Hibernate 3.6.2.Final, H2 1.3.160, dialect: org.hibernate.dialect.H2Dialect)    what is happening in your case:

*

*When GenerationType is AUTO and data type is INT, actual generation
type is SEQUENCE.

*When GenerationType is AUTO and data type is BIGINT, actual
generation type is IDENTITY. As result this will fail, if id-field is
defined as ID BIGINT PRIMARY KEY and not as ID BIGINT IDENTITY
(adding PRIMARY KEY here with H2 would be redundant).

What you can do:
If you want actual generation type to be SEQUENCE, as before, then
@GeneratedValue(strategy = GenerationType.SEQUENCE)

seems to work. No changes needed for sequence itself, because according documentation type is BIGINT anyway. I would do this way, because then nothing really changes and it is clear which way sequence is generated
Other possibility is to define column as IDENTITY with startValue(because of possible existing values) and use GenerationType.AUTO as before.

A: This is an old question and the accepted answer has a very good analysis
but I came across the same problem and have spent 3 hours to find the real issue and a solution, so it's worth leaving it here for future references.
So the real problem is that on liquibase
this statement
<changeSet id="1" author="trond">
    <modifyDataType tableName="event" columnName="id" newDataType="BIGINT" />
    <rollback>
        <modifyDataType tableName="event" columnName="id" newDataType="INT" />
    </rollback>
</changeSet>`

is generating this alter query
ALTER TABLE event ALTER COLUMN id BIGINT

which removes the default sequence value from the id column in H2
As a result, when you try to insert a new row the id is null thus the SQL error is thrown.
Unfortunately, the behavior of ALTER column varies per database vendor so probably the best solution would be to create different migration changelogs for testing (H2) and production (MySQL)
and on H2 you can make the id auto_increment again after the modifyDataType change
<addAutoIncrement
    columnDataType="bigint"
    columnName="id"
    incrementBy="1"
    startWith="1"
    tableName="event"/>
</changeSet>`

A: I would first change your @GenerationType to something specific (like IDENTITY) just to rule out any problems with Hibernate getting weird values from a sequence.  Or remove it altogether.
Your refactoring looks fine, and I can't see any obvious problems.
H2 and Liquibase often don't play together nicely when it comes to quoted identifiers; the H2 database class in Liquibase quotes some and doesn't quote others.  Maybe case conversion is screwing you up?
EclipseLink sometimes has problems when a primitive type is 0 (!) since it sometimes will treat such a value as null or uninitialized, but to my knowledge Hibernate does not suffer from this limitation.
This is not really an answer, I know, but hopefully should get you pointed in the right direction.


text:
Q: How stable is the VMWare vCenter Server OVF and is there a better way to get HA features? I am considering pruchasing Vsphere solely for the HA feature, however, in order to do this, I will also need vCenter Server.
I am not keen on purchasing a copy of Windows especially for this and have seen the vSphere server OVF which is available for download.
I have evaluated it and it appears to run well for the past week, however, it requires 80GB of hard drive space and 4GB of memory.
This infrastructure is never going to have hundreds of servers. At the most, it will be 5 servers - and if possible, I would like vCenter to run on the same HA infrastructure so I don't have to worry about it.
I was just wondering if:

*

*Is vCentre server OVF just for evaluation or is it a fully supported setup?

*Are there any turning guides for it?

*Can I run it on the same infrastructure that I want to make HA?

*Is this a good idea, or can you offer any advice / is it possible to go HA without vCentre server?

A: The Linux-based vCenter appliance works. It's a supported setup. You can run it as a VM virtualized within your cluster. Is it optimal? Meh. Is it used widely? Not in my experience...
There are also limitations surrounding the use of the appliance.

*

*No Update Manager (which can be useful)

*Embedded database, DB2, only supports 5 hosts and 50 VMs (you'd need an external Oracle instance to scale beyond that)

*Oracle is the only supported external database

I tend to think in terms of long-term stability and mindshare for support purposes. Most people run vCenter on Windows. As a result, guides, tuning recommendations and engineering knowledge are biased towards the Windows version.
Given the environment you're describing (hundreds of VM's, 5 hosts), you're probably planning to pay a lot for VMWare licensing, so the cost of a Windows server license shouldn't be the issue. I'd wager that the expertise and support options for your proposed VM infrastructure would point to using Windows over the Linux vCenter.

A: To add to ewwhite's answer, vCenter is only required to get an HA cluster set up. HA works independently of vSphere, meaning you can run the appliance in the same cluster as a supported solution. Keep in mind the vCenter appliance versions come out later than the normal vCenter on Windows product. As of writing, The vCenter 5.01 appliance is not out yet, but 5.0 is available.


text:
Q: Linking sounds? When one word ends in a consonant sound and the next begins with a vowel sound, can you tell me how you say these words in American English?

*

*can I..? (Can nai or Ca nai?)

*take it (teɪ kit or teɪk kit?)

*push it (pu shit or push shit?)

*find out (fain-dout?)

*bridge is (brid- ʒ iz or bri-dʒ iz?)

*Put it in (put tit tin or pud dit din?)

*like a (laiy-ka or laik-ka?)

Should the final sound always be shared between two words or should the final sound jump to the next word? What is the basic rule about that? Or does it depend on the accent? When I hear linking sounds in a long sentence, it's difficult for me to understand. And is it strange if I say them without linking sound?

A: What you are asking about is called relaxed reduction, and I think it is safe to say that many of us naturally do it whenever possible (though many of us tend to enunciate better in situations where we feel the reduction would be confusing).
I think the best way to explain it in most cases is that the words share the linking sound to such an extent that they may appear to be a single word

Cannai
Taikit
Pushit (Only under a very different circumstance would I say push shit.)

Some American dialects do in fact do this more than others (the Southern drawl comes to mind, where Did you eat? can be reduced to jeet? or even yet?).
It is not strange to avoid these reductions, though you are more likely to be picked out as a foreigner (even if your accent is otherwise flawless).

A: We very seldom create explicit separation between the last phoneme of the first word and the first phoneme in the second. In the cases where we do, it's usually if the sounds are the same and we want to make sure the distinction is clear. For example, someone giving his name as Bob Bridger over the phone might put a glottal stop after the first name so that the person on the other end doesn't think he said Bob Ridger.
The words you say above are all spoken fluidly, without stops. In order they would be (sorry, no IPA here)

Canai, taykit, pushit, findout, bridges, pudditin, lyka

Note that the t sounds usually get vocalized except for the final one: "put it in" becomes pudditin.
The sentence "Ed had edited it" sounds like "Eddədeddədədit." Really.


text:
Q: Create a model called inside another model in laravel 4 I defined a model Phone inside another model User with "Has One" relationship, now I need to create a new Phone model, how to do that within controller?
class User extends Eloquent {

public function phone()
{
    return $this->hasOne('Phone');
}

}

A: Your code hasn't defined phone model, it defined the relationship. Create another file with name phone.php and make it extend the eloquent class.
The function you wrote can be used to insert , delete or retrieve all phone records for a particular user.
The parameter Phone  is the name of the model it will look for when you call    phone(). It expects a 'Phone.php' file with Phone model defined ( a class called 'Phone' extending Eloquent).


text:
Q: Backgroundworker not starting copy I am a novice at VB.NET and am working on an app the read the contents of a text file and use the paths therein for a file/folder copy. I am running the copy through a backgroundworker which does not seem to take the line string. To troubleshoot I have placed a MessageBox.Show(line) under the line reading logic to see if it is reading the path. It is not and jumps straight to my BackgroundWorker1_RunWorkerCompleted sub.
Can anyone see where I am going wrong?!
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As ComponentModel.DoWorkEventArgs, Optional ByVal Overwrite As Boolean = True) Handles BackgroundWorker1.DoWork

    Dim deststring As String

    ' Open config.txt with the Using statement.
    Using r As StreamReader = New StreamReader(Application.StartupPath + "\CONFIG.txt")

        Dim line As String

        ' Read first line.
        line = r.ReadLine

        ' Loop over each line in file, While list is Not Nothing.
        Do While (Not line Is Nothing)

            ' Read line and filter based on logic
            If line.StartsWith("*") Then
                r.ReadLine()
            ElseIf line.Contains(Destpath) Then
                r.ReadLine()
            ElseIf line.Equals("%USERPROFILE%\Desktop") Then
                line = desktoppath
            ElseIf line.Equals("%USERPROFILE%\Downloads") Then
                line = downloadsPath
            ElseIf line.Equals("%USERPROFILE%\Contacts") Then
                line = contactspath
            ElseIf line.Equals("%USERPROFILE%\Documents") Then
                line = documentspath
            ElseIf line.Equals("%USERPROFILE%\Favorites") Then
                line = favoritespath
            ElseIf line.Equals("%USERPROFILE%\Links") Then
                line = linkspath
            ElseIf line.Equals("%USERPROFILE%\Music") Then
                line = Musicpath
            ElseIf line.Equals("%USERPROFILE%\Pictures") Then
                line = picturespath
            ElseIf line.Equals("%USERPROFILE%\SavedGames") Then
                line = savedgamespath
            ElseIf line.Equals("%USERPROFILE%\SavedSearches") Then
                line = savedsearchespath
            ElseIf line.Equals("%USERPROFILE%\Videos") Then
                line = videospath
            ElseIf line.Contains("%USERNAME%") Then
                line = line.Replace("%USERNAME%", Username)
            Else

                Console.Writeline(line)

                'Read line and create a full path for the destination
                Dim SubPath As String = line.Split("\").Last
                Dim FullDestPath As String = Destpath & "\" & SubPath

                Console.Writeline(FullDestPath)

                If Not System.IO.Directory.Exists(FullDestPath) Then
                    System.IO.Directory.CreateDirectory(FullDestPath)
                End If

                'Get directory info's
                Dim SourceDir As DirectoryInfo = New DirectoryInfo(line)
                Dim DestDir As DirectoryInfo = New DirectoryInfo(FullDestPath)
                Dim ChildFile As FileInfo

                'Loop through each file in the SourceDir
                For Each ChildFile In SourceDir.GetFiles()

                    'Display file being copied
                    SetLabelText_ThreadSafe(Me.lblStatus, "Copying: " & line & "\" & ChildFile.Name & "")

                    'Do the copy
                    ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), True)

                    deststring = DestDir.ToString & "\" & ChildFile.Name
                    Dim sourcedirstring As String
                    sourcedirstring = SourceDir.ToString & "\" & ChildFile.Name

                    'Open Stream
                    Dim CopyStream As New FileStream(sourcedirstring, FileMode.Open, FileAccess.Read)
                    Dim NewStream As New FileStream(deststring, FileMode.CreateNew)
                    Dim Buffer(100000) As Byte
                    Dim BytesRead As Integer

                    'Try loop for each file
                    Try
                        Do
                            BytesRead = CopyStream.Read(Buffer, 0, Buffer.Length)
                            NewStream.Write(Buffer, 0, BytesRead)
                            PercentComplete = (NewStream.Length / CopyStream.Length * 100)
                            PercentComplete = Decimal.Round((PercentComplete), 2)
                            If PercentComplete > 100 Then
                                PercentComplete = "0"
                            End If

                            'if the file count is only 1 file then make both progress bars the same so that the current file and total are the same
                            If filecount = 1 Then
                                percentage = ((NewStream.Length + filetotalsofarcopied) / Overallsize.ToString * 100)
                                percentage = Decimal.Round((percentage), 2)
                                If percentage > 100 Then
                                    percentage = 0
                                End If
                                SetLabelText_ThreadSafe(Me.lblTotalProgress, "" & percentage & "%")
                            Else
                                Timer6.Start()
                                percentage2 = ((NewStream.Length + filetotalsofarcopied) / Overallsize.ToString * 100)
                                percentage2 = Decimal.Round((percentage2), 2)
                                If percentage2 > 100 Then
                                    percentage2 = 0
                                End If
                                SetLabelText_ThreadSafe(Me.lblTotalProgress, "" & percentage2 & "%")
                            End If

                            SetLabelText_ThreadSafe(Me.lblCurrentFileProgress, "" & PercentComplete & "%")

                            Dim time As Long = Label22.Text

                            'Calculate copy speed
                            Dim kbps As Double = (NewStream.Length + filetotalsofarcopied) / (time * 1024)
                            If kbps < 1024 Then
                                SetLabelText_ThreadSafe(Me.lblCopy, String.Format("Copy Speed: {0:0.00} KB/s", kbps))
                            Else
                                SetLabelText_ThreadSafe(Me.lblCopy, String.Format("Copy Speed: {0:0.00} MB/s", kbps / 1024))
                            End If

                        Loop Until BytesRead = 0 And PercentComplete = 100

                    Catch ex As Exception
                    Finally
                        CopyStream.Dispose()
                        NewStream.Dispose()
                    End Try

                    'File counter
                    int3 = int3 + 1

                    'Calculate data being moved for eta to completion
                    Dim filetotalbytes As Double = ChildFile.Length
                    filetotalsofarcopied = filetotalbytes + filetotalsofarcopied

                    'Check for pending cancel
                    If BackgroundWorker1.CancellationPending = True Then
                        BackgroundWorker1.CancelAsync()
                        Exit Sub
                    End If

                Next

                'Loop through Sub directories of SourceDir
                Dim SubDir As DirectoryInfo
                For Each SubDir In SourceDir.GetDirectories()
                    CopyDirectory(SubDir.FullName, Path.Combine(DestDir.FullName, SubDir.Name), Overwrite)
                Next
            End If

            ' Read in the next line.
            line = r.ReadLine

        Loop

    End Using

End Sub

UPDATE: Included .text file contents:
***DESTINATION***
D:\Test
***Sources***
%USERPROFILE%\Downloads
%USERPROFILE%\Favorites
D:\User Data\Adam\Documents\Test

A: You should remove the calls to ReadLine inside the first two Ifs and replace them with the Continue Do keyword.
In general it is better to have just one call to ReadLine in your code.
For example you could check for End of Stream using the StreamReader.Peek method.
Finally the If block should be closed after the %USERNAME% check
    ' removed
    ' line = r.ReadLine()

    Dim line As String
    Do While r.Peek <> -1
        line = r.ReadLine()
        Console.Writeline(line)

        If line.StartsWith("*") Then
            ' Not significant, skip to the next line
            Continue Do
        ElseIf line.Contains(Destpath) Then
            ' Not significant, skip to the next line
            Continue Do
        ElseIf line.Equals("%USERPROFILE%\Desktop") Then
            line = desktoppath
        ElseIf line.Equals("%USERPROFILE%\Downloads") Then
            line = downloadsPath
        ElseIf line.Equals("%USERPROFILE%\Contacts") Then
            line = contactspath
        ElseIf line.Equals("%USERPROFILE%\Documents") Then
            line = documentspath
        ElseIf line.Equals("%USERPROFILE%\Favorites") Then
            line = favoritespath
        ElseIf line.Equals("%USERPROFILE%\Links") Then
            line = linkspath
        ElseIf line.Equals("%USERPROFILE%\Music") Then
            line = Musicpath
        ElseIf line.Equals("%USERPROFILE%\Pictures") Then
            line = picturespath
        ElseIf line.Equals("%USERPROFILE%\SavedGames") Then
            line = savedgamespath
        ElseIf line.Equals("%USERPROFILE%\SavedSearches") Then
            line = savedsearchespath
        ElseIf line.Equals("%USERPROFILE%\Videos") Then
            line = videospath
        ElseIf line.Contains("%USERNAME%") Then
            line = line.Replace("%USERNAME%", Username)
        End If

        ' Now your line variable should be always correct and
        ' you can execute your copying logic
        ......

        line = r.ReadLine
    Loop


text:
Q: nested loop through xml-nodes using powershell I would like to extract from a xml-file the value of the name-attributes from all window- and all viewpoint-nodes.
<?xml version='1.0' encoding='utf-8' ?>
        <workbook>
            <windows>
                <window class='dashboard' name='D1'>
                  <viewpoints>
                    <viewpoint name='V1'> </viewpoint>
                    <viewpoint name='V2'> </viewpoint>
                    <viewpoint name='V3'> </viewpoint>
                </viewpoints>
                </window>
                <window class='dashboard' name='D2'>
                  <viewpoints>
                    <viewpoint name='V10'> </viewpoint>
                    <viewpoint name='V11'> </viewpoint>
                  </viewpoints>
                 </window>
            </windows>
        </workbook>

This is the code I have written:
[XML]$doc = get-content -path 'W:\Demo1.xml'

$objs = @()
$dashboards = $doc.SelectNodes("//window[@class = 'dashboard']")

foreach ($dashboard in $dashboards)
{
   $worksheets = $dashboard.SelectNodes("//viewpoint[@name]")

    foreach ($worksheet in $worksheets)
    {
        $obj = new-object psobject -prop @{Dashboard=$dashboard.name; Worksheet = $worksheet.name};
        $objs += $obj;

    }
 }

$objs

What I expected:

dashboard   worksheet
D1          V1
D1          V2
D1          V3
D2          V10
D2          V11

What I got:

dashboard   worksheet
D1          V1
D1          V2
D1          V3
D1          V10
D1          V11
D1          V14
D2          V1
D2          V2
D2          V3
D2          V10
D2          V11
D2          V14

What is wrong here? The result is completely contradictory to my understanding of how a nested loop works.

A: An XPath starting with a / character means that it will be begin at the document root node. To create a relative XPath from the context node, you need to put a . before the /.
So your code should be:
[XML]$doc = get-content -path 'W:\Demo1.xml'

$objs = @()
$dashboards = $doc.SelectNodes("//window[@class = 'dashboard']")

foreach ($dashboard in $dashboards)
{
   $worksheets = $dashboard.SelectNodes(".//viewpoint[@name]")

    foreach ($worksheet in $worksheets)
    {
        $obj = new-object psobject -prop @{Dashboard=$dashboard.name; Worksheet = $worksheet.name};
        $objs += $obj;

    }
 }

$objs

A: You could also simplify that and adopt your xpath to select all viewpoint nodes from dashboard window:
[XML]$doc = get-content -path 'W:\Demo1.xml'

$objs = @()
$worksheets = $doc.SelectNodes("//window[@class = 'dashboard']//viewpoint[@name]")

foreach ($worksheet in $worksheets)
{
    $obj = new-object psobject -prop @{Dashboard=$worksheet.ParentNode.ParentNode.name; Worksheet = $worksheet.name};
    $objs += $obj;
}

$objs

And here a solution without xpath:
[XML]$doc = get-content -path 'W:\Demo1.xml'

$objs = $doc.DocumentElement.windows.window | Where class -eq 'dashboard' | foreach {
    $dashboardName = $_.name
    $_.viewpoints.viewpoint | foreach {
        new-object psobject -prop @{Dashboard=$dashboardName; Worksheet = $_.name}
    }
}


text:
Q: Where to call django.setup? I use django_cleanup and wonder what is django.setup() Do I call it in settings?
When I call apps.get_models() I get django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

A: As you may read in official documentation https://docs.djangoproject.com/en/4.1/ref/applications/#initialization-process , django.setup() is method which reads settings, and configure you project, so you may easly use your models.


text:
Q: Make a subset of dtaframe according to column value python I have generated dataframe frame and created a csv file now I want to make a subset of dataframe in which it checks the value of column "dst" (uptill 0) and then take value of Image column.
My current dataframe is:
     Image   Maxval   locx  locy  dst
0    1.jpg    0.99      22    47    0
1    7.jpg    0.46      27    65    18.68
2    11.jpg   0.32      18    29    18.43
8    18.jpg   0.25      7     38    17.49
10   1.jpg    0.99      40    71    0
11   18.jpg   0.56      27    71    17.68
13   7.jpg    0.42      93    17    19.43
19   11.jpg   0.35      70    39    17.49

The image are sorted according to maxval so i don't want to change the order of images.I want my dataframe to be:
   Image    Image
  1.jpg     1.jpg
  7.jpg     18.jpg
  11.jpg    7.jpg
  18.jpg    11.jpg

A: If first value in dst column is always 0 compare value 0 and create new column value by cumsum fo cumulative sum and groups by GroupBy.cumcount, last use DataFrame.pivot:
df['c'] = df['dst'].eq(0).cumsum()
df['g'] = df.groupby('c').cumcount()
df1=df.pivot('g','c','Image').add_prefix('Image_').rename_axis(None).rename_axis(None,axis=1)
print (df1)
  Image_1 Image_2
0   1.jpg   1.jpg
1   7.jpg  18.jpg
2  11.jpg   7.jpg
3  18.jpg  11.jpg

A: Here is another approach:

*

*Get the groups of images based on the dst column

groups = df.groupby(df.dst.eq(0).cumsum())['Image']

*Concat every groups after resetting the index for each of them:

pd.concat([group.rename('Image_' + str(indx)).reset_index(drop=True) for indx, group in groups], axis=1)

Output:
  Image_1 Image_2
0   1.jpg   1.jpg
1   7.jpg  18.jpg
2  11.jpg   7.jpg
3  18.jpg  11.jpg

As you can see I also renamed the columns in the concat function by renaming the series, but that is not necessary if you really want to have the name "image" for every groups.


text:
Q: Visual Studio 2013 debugging does not start after installing WebMatrix Yesterday i installed WebMatrix on my computer. The install did not complete successfully and I ended up uninstalling the program. Now VS2013 will not start the debugger.
What happens is that I select a project, click "Start Debugging" and then the debugger just exits without any exceptions and the browser displaying the error message "Server not found", or (sometimes) I get the error message "Process with an Id of XXXX is not running".
I've tried to run "repair" on IIS Express 8, but it did not help.
How can I make VS2013 start the debugger again?

A: Rather than fixing the problem, can you do a "system restore" to prior to the install of webMatrix?  A windows system restore puts the installed software and registry back to a particular point in time without interfering with your own data.  To do a system restore follow the steps in this microsoft guide:   http://windows.microsoft.com/en-us/windows7/restore-system-files-and-settings.

A: I figured this out after two days of trubleshooting. This post helped me solve the problem.

It turns out that [WebMatrix] adds a new REG_SZ value called
  CustomUserHome at HKEY_CURRENT_USER\Software\Microsoft\IISExpress.
  This points to the Web Matrix Config file and not the IIS Express one.

I deleted the key CustomUserHome and now everything works perfect!


text:
Q: Setting up a rake task which runs for all models and all boolean columns For the following error I need to write a rake task. How should it look exactly? (For example instead of ExampleModel etc)
ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer set to false is deprecated. SQLite databases have used 't' and 'f' to serialize boolean values and must have old data converted to 1 and 0 (its native boolean serialization) before setting this flag to true. Conversion can be accomplished by setting up a rake task which runs
ExampleModel.where("boolean_column = 't'").update_all(boolean_column: 1)
ExampleModel.where("boolean_column = 'f'").update_all(boolean_column: 0)
for all models and all boolean columns, after which the flag must be set to true by adding the following to your application.rb file:
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true


text:
Q: Passing an array of strings as parameter to a function in C I want a simple function that receives a string and returns an array of strings after some parsing. So, this is my function signature:
int parse(const char *foo, char **sep_foo, int *sep_foo_qty) {
    int i;
    char *token;
    ...
    strcpy(sep_foo[i], token); /* sf here */
    ...
}

Then I call it like this:
char sep_foo[MAX_QTY][MAX_STRING_LENGTH];
char foo[MAX_STRING_LENGTH];
int sep_foo_qty, error;

...

error = parse(foo, sep_foo, &sep_foo_qyt);

...

This way I get a warning during compilation:
warning: passing argument 2 of 'parse' from incompatible pointer type

And then a segmentation fault during execution in the line marked with /* sf here */
What is wrong in my C code?
Thanks in advance

A: sep_foo is defined as an array of arrays.  In other words, when you use sep_foo, it points to the beginning of sequential memory.  Here's a model:
(assume MAX_STRING_LENGTH = 16, MAX_QTY = 2)
sep_foo       = &&0000
sep_foo[0]    =  &0000
sep_foo[0][0] = *&0000 = 12
sep_foo[0][8] = *&0008 = 74
sep_foo[1]    =  &0010
sep_foo[1][0] = *&0010 = 12

0000  12 34 56 78  9A BC DE F0  74 10 25 89  63 AC DB FE
0010  12 34 56 78  9A BC DE F0  74 10 25 89  63 AC DB FE

However, your function expects an array of pointers (actually, a pointer to a pointer).  This is modeled as such:
sep_foo_arg       =   &&0000
sep_foo_arg[0]    =  *&&0000 = &0010
sep_foo_arg[0][0] =  *&*&0000 = 12
sep_foo_arg[0][8] = *(&*&0000 + 8) = 74
sep_foo_arg[1]    =  *&&0002 = &0020
sep_foo_arg[1][0] = *&*&0000 = 12

0000  0010 0020  xxxx xxxx  xxxx xxxx  xxxx xxxx

0010  12 34 56 78  9A BC DE F0  74 10 25 89  63 AC DB FE
0020  12 34 56 78  9A BC DE F0  74 10 25 89  63 AC DB FE

Yeah ... Syntax may be a bit confusing for my explanations...
Anyway, you can solve this issue by telling your function how to treat the pointer pointed to.  In particular, you would want to treat it as an array (a sequence of memory):
int parse(const char *foo, char (*sep_foo)[MAX_STRING_LENGTH], int *sep_foo_qty);

A: The warning is exactly right. Your function wants an array of pointers. You're giving it an array of arrays.
Expected:

 sep_foo:
 +------+       +-----+
 |char**|--> 0: |char*|-->"string1"
 +------+       +-----+
             1: |char*|-->"string2"
                +-----+
*sep_foo_qty-1: |...  |
                +-----+

What you provided:

           sep_foo:
           +--------------------------------+
        0: | char[MAX_STRING_LENGTH]        |
           +--------------------------------+
        1: | char[MAX_STRING_LENGTH]        |
           +--------------------------------+
MAX_QTY-1: | ...                            |
           +--------------------------------+

An array with elements of type X can "decay" into a pointer-to-X, or X*. But the value of X isn't allowed to change in that conversion. Only one decay operation is allowed. You'd need it to happen twice. In your case, X is array-of-MAX_STRING_LENGTH-chars. The function wants X to be pointer-to-char. Since those aren't the same, the compiler warns you. I'm a bit surprised it was just a warning since nothing good can come from what the compiler allowed to happen.
In your function, you could write this code:
char* y = NULL;
*sep_foo = y;

That's legal code since sep_foo is a char**, so *sep_foo is a char*, and so is y; you can assign them. But with what you tried to do, *sep_foo wouldn't really be a char*; it would be pointing to an array of char. Your code, in effect, would be attempting to do this:
char destination[MAX_STRING_LENGTH];
char* y = NULL;
destination = y;

You can't assign a pointer into an array, and so the compiler warns that the call is no good.
There are two ways to solve this:

*

*Change the way you declare and allocate sep_foo on the calling side so it matches what the function expects to receive:
char** sep_foo = calloc(MAX_QTY, sizeof(char*));
for (int i = 0; i < MAX_QTY; ++i)
  sep_foo[i] = malloc(MAX_STRING_LENGTH);

or, equivalently
char* sep_foo[MAX_QTY];
for (int i = 0; i < MAX_QTY; ++i)
  sep_foo[i] = malloc(MAX_STRING_LENGTH);

*Change the prototype of the function to accept what you're really giving it:
int parse(const char *foo, char sep_foo[MAX_QTY][MAX_STRING_LENGTH], int *sep_foo_qty);

A: Parameter 2 should be
char sep_foo[][MAX_STRING_LENGTH]

To clarify, you are passing a pointer to parse() and treating it as a pointer to a pointer. A multidimensional array in C is NOT an array of pointers. It is a single block of memory that is pointed to by the array variable. You cannot dereference it twice.

A: If that is your exact code, then I'm guessing the segfault is because of the fact that you haven't allocated memory to the char* token inside your parse function, and then using that in your strcpy.


text:
Q: How come HTML can support Google I just got to know that I can use  tag like:
Google
I have not read this thing ever in my career, might be, I have limited knowledge however it is creating some problem for me, because I am matching "<a href" in content and processing accordingly like making it open in new tab etc.
I tested it on browsers Chrome, Firefox and both allow it to be a link.
Is this standardized?

A: It isn't standard. It is an error. Browsers are very good at error recovery.

A: Looks like a syntactic markup error. Modern browsers will correct this, but older ones may show an error / cause the element to misbehave. If you run the page through a HTML validator it will fail.

A: just add protocol http:// before the link
and
add target="_blanck" for new tab

 Follow

   Follow

    call us


text:
Q: How to wrap input text in text-field using the Racket GUI plugin Just need a basic example of a text-field% that wraps input
(define blogPost%
  (class horizontal-panel%
    (super-new)
    (define (callback button event)
      (define title-new-value (send titleoutput get-value))
      (define new-value (send output get-value))
      (save title-new-value new-value))
      ;;(display title-new-value)
      ;;(display new-value))
    (define button (new button% (label "Submit")
                        (vert-margin 0)
                        (parent this)
                        (callback callback)))
    (define titleoutput (new text-field% (label "    title")
                             (min-height 20)
                             (min-width 200)
                             (parent this)))
    (define output (new text-field% (label "blog")
                        (min-height 450)
                        (min-width 400)
                        (stretchable-width 300)
                        (vert-margin 0)
                        (parent this)))
    ))

(define f (new frame% (label "prism blog post GUI") (min-width 400) (min-height 500)))

(define tib (new blogPost%
                 (parent f)))

(send f show #t)

there is more to this, basically it saves the user's input into a database which we are planning to have accessible and print to the screen. However, as is, the user when typing into the text field, just types horizontally on one line and it never word wraps and the enter button does not go to a new line. is this issue fixable?

A: To allow multi-line inputs into a text field, you need to add [style '(multiple)] to the initialization arguments like this:
    (define output (new text-field% [label "blog"]
                        [style '(multiple)]
                        [min-height 450]
                        [min-width 400]
                        [stretchable-width 300]
                        [vert-margin 0]
                        [parent this]))

Then the text field allows newlines, and it wraps the text when a line gets too long.
The documentation for this is here. In that, it says:

There are two text field styles:

*

*A single line of text is visible, and a special control event is generated when the user presses Return or Enter (when the text field has the focus) and the event is not handled by the text field's frame or dialog (see on-traverse-char in top-level-window<%>).

*Multiple lines of text are visible, and Enter is not handled specially.

Later, it specifies that the style argument is a list of symbols and says:

The style must contain exactly one of 'single or 'multiple; the former specifies a single-line field and the latter specifies a multiple-line field.


text:
Q: Search string , if no match then delete line I am looking for code to open a text file , then read the text file line by line , if the line in the text file (each line will store approx 5 values) does not contain a certain value e.g "hart" then I wand to remove that line. I am using c# and vs2012 , could anyone show me how to do this ? the file being read from is a csv file. I have no code example here as my current code does not work and I feel givin example will only cause more confusion than asking for someone to show me a clean fresh approach to doing this.
I have added the code I currently have which adds all of the data to a text file however the code I need to figure out is to take these results and filter them
     foreach (DataRow dr in this.CalcDataSet.Items)
        {

           foreach (object field in dr.ItemArray)
                {
                    str.Append(field.ToString() + ",");
                }

            str.Replace(",", "\n", str.Length - 1, 1);
        }

        try
      {
            System.IO.File.WriteAllText(Filepath, str.ToString());

        }
        catch (Exception ex)
        {
            MessageBox.Show("Write Error :" + ex.Message);
        }

        var lines = System.IO.File.ReadAllLines(Filepath).ToList();
        var acceptedLines = new List<string>();
        foreach (var line in lines)
            if (Matches(line))
                acceptedLines.Add(line);

        System.IO.File.WriteAllLines(Filepath, acceptedLines);
    }

    private bool Matches(string s)
    {
        if (s == cmbClientList.SelectedText.ToString())
        {
            return true;
        }

        else  return false;
    }

A: Use the TextFieldParser class to open and read the file, and split the values into an array. You can then examine each item on each line to see if it contains the value you want.
If the line contains the value, then write the line to a new file. If it doesn't contain the value, then do not write to the new file.
When you're done, close the input and output files. Then delete the original input file and rename the output file.
You can't easily read and modify a text file in-place.
Another option would be to read using TextFieldParser and write to an in-memory stream. At the end, write from the memory stream back to the original file. This will work if the file is small enough to fit in memory.

A: This will basically do what you want:
var lines = System.IO.File.ReadAllLines("somefile.csv");
var acceptedLines = new List<string>();
foreach (var line in lines)
    if (Matches(line))
        acceptedLines.Add(line);
System.IO.File.WriteAllLines("output.csv", acceptedLines);

private bool Matches(string s) {
    // Whatever you want, return true to include the line, false to exclude)
}

A: you can do this
string[] lines  = File.ReadAllLines("yourfile.csv");
List<string> linesToWrite = new List<string>();
int currentCount = 0;

foreach(string s in lines)
{
  if(s.Contains("YourKeyValue"))
     linesToWrite.Add(s);
}
File.WriteAllLines("yourfile.csv", linesToWrite );


text:
Q: Vulkan proper frame synchronization I'm trying to synchronize frames in Vulkan API, but I have some weird problems. I implemented synchronization like this:
void RenderSystem::OnUpdate(const float deltaTime)
{
    uint32_t frameIndex{};

    auto result = SwapChain->AcquireNextImageIndex(PresentationCompleteSemaphore.get(),
                                                   nullptr,
                                                   &frameIndex);

    InFlightFences[frameIndex]->Wait();
    InFlightFences[frameIndex]->Reset();

    if (result == VK_ERROR_OUT_OF_DATE_KHR)
    {
        Recreate();
        return;
    }
    else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
    {
        throw std::runtime_error("Error when acquiring next image...");
    }

    UpdateModelMatrix(deltaTime, frameIndex); // TODO: Remove this! For testing purposes only

    VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
    GraphicsMainQueue.Submit({ TriangleCommandBuffers[frameIndex].get() },
                             { PresentationCompleteSemaphore.get() },
                             { RenderCompleteSemaphore.get() },
                             InFlightFences[frameIndex].get(),
                             waitStages);

    result = PresentationQueue.Present({ RenderCompleteSemaphore.get() },
                                       { SwapChain.get() },
                                       &frameIndex);

    if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || MainWindow->HasBeenResized())
        Recreate();
    else if (result != VK_SUCCESS)
        throw std::runtime_error("Failed to present result!");
}

And it works on Windows 10 like a charm. Unfortunately on Linux Mint, it doesn't work in some cases. First of all, moving window on Linux is very laggy and sometimes freezes the whole OS for a second, but it's not the biggest problem. Closing the window calls vkDeviceWaitIdle and... it freezes the application. It will never start responding because it will wait for the device forever. The validation layer doesn't report any problem with my code.
I partly solved this problem by moving fences synchronization at the bottom of my function, but in my opinion, it's a suboptimal solution, because I wait for the frame to finish rendering, instead of preparing the next frame.
    // ...

    if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || MainWindow->HasBeenResized())
        Recreate();
    else if (result != VK_SUCCESS)
        throw std::runtime_error("Failed to present result!");

    InFlightFences[frameIndex]->Wait();
    InFlightFences[frameIndex]->Reset();
}

How can I properly synchronize frames not only on Windows but also on Linux? What am I doing wrong? What am I missing?

A: You have only one set of semaphores. That means access to those semaphores might be missynchronized.
Let's see the code without the distractors:
AcquireNextImageIndex( PresentationCompleteSemaphore, frameIndex );
InFlightFences[frameIndex].WaitAndReset();
QSubmit( PresentationCompleteSemaphore, RenderCompleteSemaphore, InFlightFences[frameIndex] );
Present( RenderCompleteSemaphore, frameIndex );

Now, how do we know we can reuse PresentationCompleteSemaphore on Acquire? The Submit waits\unsignals it, and must finish. We could infer this from the fence, but the fence wait happens after the Acquire. So the semaphore still might be in use while Acquire tries to reuse it. This is a possible program flow:
AcquireNextImageIndex( PresentationCompleteSemaphore ) -> frameIndex = 0;
QSubmit( PresentationCompleteSemaphore, RenderCompleteSemaphore, InFlightFences[0] );

// hazard; QSubmit still might be waiting on PresentationCompleteSemaphore
AcquireNextImageIndex( PresentationCompleteSemaphore ) -> frameIndex = 1;

How do we know we can reuse RenderCompleteSemaphore? The QSubmit can only use it when Present is already done with it. Only sane way currently to infer that is when Acquire gives back the same swapchain image. This is a possible program flow:
AcquireNextImageIndex( PresentationCompleteSemaphore ) -> frameIndex = 0;
QSubmit( PresentationCompleteSemaphore, RenderCompleteSemaphore, InFlightFences[0] );
Present( RenderCompleteSemaphore, 0 );

AcquireNextImageIndex( PresentationCompleteSemaphore ) -> frameIndex = 1;
// hazard; RenderCompleteSemaphore might still be waited on by Present
// which presented image 0, but we acquired image 1, so it might be async
QSubmit( PresentationCompleteSemaphore, RenderCompleteSemaphore, InFlightFences[1] );