Q: Coordinate shift when converting from Kivy (origin at bottom left) to MatplotLib pyplot (top left) So I`m making an image annotation tool for images to use them with some tensor flow and OpenCV projects. (yes I know there are already made ones, I do it as part of learning experience) To ensure my script is versatile I first make a json file to store my data easily. Already at this stage I store top left of my rectangle with width and height. Then I use another script to convert my json into xml identical to the one seen in this tutorial: Keras tutorial
The conversion and storage occur in this part of the annotation script:
registration:
def on_touch_up(self, touch):
    if abs(self.current_start_point[0] - touch.pos[0]) > 10 and abs(self.current_start_point[1] - touch.pos[1]) > 10:
        x = math.trunc(self.current_start_point[0] if self.current_start_point[0] < touch.pos[0] else touch.pos[0])
        y = math.trunc(self.current_start_point[1] if self.current_start_point[1] > touch.pos[1] else touch.pos[1])
        w = math.trunc(abs(self.current_start_point[0] - touch.pos[0]))
        h = math.trunc(abs(self.current_start_point[1] - touch.pos[1]))
        debug(CLR=GREEN,MSG=f'Registered rectangle with position {x},{y}.\nIts width is {w} and height {h}')

        self.rectangles.append({'x':x,
                                'y':y,
                                'w':w,
                                'h':h})

    self.current_drag = False
    self.current_start_point = False

and storage:
def do_export(self):
    with open(self.save_file,'r') as fl:
        cur_state = json.loads(fl.read())
        cur_state['root'][self.imname] = self.rectangles
    with open(self.save_file,'w') as fl:
        strung = json.dumps(cur_state,sort_keys=True,indent=4)
        fl.write(strung)

    self.rectangles = []

It works fine and displays rectangles accordingly with such function:
def update(self,dt):
    self.canvas.clear()

    with self.canvas:
        Rectangle(pos=(0,0),size=(self.tex_w,self.tex_h),texture=self.tex)

        Color(0.9,0,0.2,0.5)
        for rect in self.rectangles:
            Rectangle(pos=(rect['x'],rect['y']-rect['h']),size=(rect['w'],rect['h']))

        if self.current_drag:
            dx = self.current_drag[0] if self.current_drag[0] < self.current_start_point[0] else self.current_start_point[0]
            dy = self.current_drag[1] if self.current_drag[1] < self.current_start_point[1] else self.current_start_point[1]
            dw,dh = abs(self.current_start_point[0]-self.current_drag[0]),abs(self.current_start_point[1]-self.current_drag[1])
            Rectangle(pos=(dx,dy),size=(dw,dh))

Then I convert it into xml as such (only the coordinates part):
x_min,y_min,x_max,y_max = item['x'],int(item['y']),item['w'] + item['x'],int(item['y']+item['h'])
        obj = ET.SubElement(root,'object')
        name,pose,truncated,difficult = ET.SubElement(obj,'name'),ET.SubElement(obj,'pose'),ET.SubElement(obj,'truncated'),ET.SubElement(obj,'difficult')
        name.text = 'bob' ; pose.text = 'Unknown' ; truncated.text = str(0) ; difficult.text = str(0)
        bndbox = ET.SubElement(obj,'bndbox')
        min_x,min_y,max_x,max_y = ET.SubElement(bndbox,'xmin'),ET.SubElement(bndbox,'ymin'),ET.SubElement(bndbox,'xmax'),ET.SubElement(bndbox,'ymax')
        min_x.text = str(x_min) ; min_y.text = str(y_min) ; max_x.text = str(x_max) ; max_y.text = str(y_max)

Eventually I load it into the dataset class I copied from same tutorial and use matplotlib to show the mask, which shows something like this:

I clearly see the offset in y but I cant find the origin of it as I clearly pick the top left corner of rectangle in kivy. This is probably something really simple but I just cant find it and I'm stuck on it for couple of days now.
Also JSON for the cat looks like:
{
"root": {
    "images\\0.jpg": [
        {
            "h": 101,
            "w": 99,
            "x": 1052,
            "y": 653
        }
    ]
}

}
and the XML like:
<annotation>
<folder>side</folder>
<filename>0</filename>
<source>Unknown</source>
<size>
    <width>1920</width>
    <height>1080</height>
    <depth>3</depth>
</size>
<segmented>0</segmented>
<object>
    <name>bob</name>
    <pose>Unknown</pose>
    <truncated>0</truncated>
    <difficult>0</difficult>
    <bndbox>
        <xmin>1052</xmin>
        <ymin>653</ymin>
        <xmax>1151</xmax>
        <ymax>754</ymax>
    </bndbox>
</object>

Thank you very much in advance, and sorry if it`s something very simple.

A: My apologies to everyone, I'm retarded. For anyone who has same issue just have screen height - the y coordinate to convert, cuz even if u pick different corner the system itself stays.


Q: Adding Razorviews/.chtml files non-dynamically in .NET 6.0 I'm learning how to make a website and I want to add new views through a method. Instead of physically clicking add view and then editing it.
The method would take in a Novel object, which is connected to a database. If that novel doesn't already have a view. A new view would be created based off a template view that I make. Some areas in the template would be changed based off the difference in object properties. Ex. Novel Name, Synopsis, Author, Chapters, Rating, Genres, and Tags.
I already have a form that takes in information and makes an update to the sql database adding that object.
There are a lot of guides on how to do this dynamically, but later on I want to add reviews, comments, pageview trackers, and such.
Something similar to what I want.
MVC 4: Create new Razor View from string not from file path
That method doesn't seem to work anymore or I'm just not that familiar with the syntax.


Q: How to accelerate DFT by specifying region of interest in frequency domain Note: This question is originally asked at OpenCV forum a couple of days ago.
I'm building an image processing program which extensively uses 2-dimensional dft, discrete Fourier transform. I'm trying to speed up so as to run in real-time.
In that application I only use a part of dft output specified by a rectangular ROI. My current implementation follows the steps below:

*

*Compute dft of the input image f (typically size of 512x512) and get the entire dft result F

*Crop F into a pre-specified region of interest (ROI, typically size of 32x32, located arbitrary), R
This process basically works well, but involves useless calculation since I only need partial information of F. I'm looking for a way to accelerate this calculation only by computing necessary part of dft.
I found OpenCV with Intel IPP computes dft with Intel IPP functions, which results in an order of magnitude faster than naive OpenCV implementation. I'm wondering if I can even accelerate this computation by only computing pre-specified frequency domain of dft.
Since I'm new to OpenCV, I've lost my way here, so I hope you could provide a way to do this.
Kindly note that I don't mean to do a dft to an ROI of an image, i.e. dft(ROI(f)), but I want to compute ROI(dft(f)).
Thanks in advance.

A: Just a partial idea.
The DFT is separable. It is always computed by first applying the FFT algorithm to rows of the image, then to the columns of the result (or the other way around, the order doesn't matter).
If you want only an ROI of the output, in the second step you only need to process the columns that fall within the ROI.
I don't think you'll find a way to compute only a subset of frequencies along each 1D row/column. That would likely entail hacking your own FFT, which will likely be more computationally expensive than using the one in IPP or FFTW.


Q: Check if record exists in python. If exists then skip else process I have a function for extracting frames from videos. I have a csv file which has the names of the videos already processed. I want to check if the name of a newly added video file is present in the csv file. If present then exit the code else process the function to extract frames from the new video
def extractFrames(m):
    global vid_name

    vid_files=glob(m)

    for v_f in range(len(vid_files)):
        print("path of video========>>>>.",vid_files[v_f])

        #latest_file=max(vid_files, key=os.path.getctime)

        #print(latest_file)

        v1=os.path.basename(vid_files[v_f])
        try:
            vid_name = os.path.splitext(v1)[0]

            vidcap = cv2.VideoCapture(vid_files[v_f])
        except cv2.error as e:
            print(e)
        except:
                print('error')
        #condition
        fsize=os.stat(vid_files[v_f])
        print('=============size of video ===================:' , fsize.st_size)
        try:

            if (fsize.st_size > 1000):

                fps = vidcap.get(cv2.CAP_PROP_FPS)      # OpenCV2 version 2 used "CV_CAP_PROP_FPS"
                frameCount = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
                duration = frameCount/fps
                minutes = int(duration/60)
                print('fps = ' + str(fps))
                print('number of frames = ' + str(frameCount))
                print('duration (S) = ' + str(duration))
                if (duration > 1):
                    success,image = vidcap.read()

                    count=0

                    success=True

                    while success:

                        img_name = vid_name + '_f' + str(count) + ".jpg"

                        success,image = vidcap.read()
                        if count % 10 == 0 or count ==0:
                            target_non_target(img_name, image)

                        count+=1

                    vidcap.release()

                    cv2.destroyAllWindows()
        except:
            print("error")

        print('finished processing video ', vid_files[v_f])
        with open("C:\\multi_cat_3\\models\\research\\object_detection\\my_imgs"+'/video_info.csv', 'a') as csv_file:
            fieldnames = ['Video_Name','Process']
            file_is_empty = os.stat("C:\\multi_cat_3\\models\\research\\object_detection\\my_imgs"+'/video_info.csv').st_size == 0
            writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
            if file_is_empty:
                writer.writeheader()
            writer.writerow({'Video_Name':vid_name,'Process':'done'})

if __name__ == "__main__":

    x="C:\\Python36\\videos\\*.mp4"

    extractFrames(x)

Suppose a folder has 2 videos V1 and V2 from which frames have already been extracted and the names V1 and V2 are added in the csv file. Now when i add video V3 the code should check if V3 exists already in the csv. If it exists then the code should be skipped else frames from V3 should be processed and V3 should be added in the csv file after extraction of the frames

A: Without the details you have code like this
def extractFrames(m):
    # do stuff
    vid_files=glob(m)

    for v_f in range(len(vid_files)):
        #find vid_name
        #do stuff
        save_as_done(vid_name)

if __name == '__main__':
    x="C:\\Python36\\videos\\*.mp4"
    extractFrames(x)

If you pass in a list of things that have been done, something like
done = ['first.mp4', 'second.mp4']

you can check if a filename has been done like this:
>>> 'first.mp4' in done
True

So, if you save the filenames (fully pathed) of what you've done to a file and load them into a list, like this
def load_done_list():
    with open('video_info.csv') as f: #or full path, maybe pass in the file name?
      return f.readlines()
you can check the list
def extractFrames(m, done):
    # do stuff
    vid_files=glob(m)

    for v_f in range(len(vid_files)):
        #find vid_name
        if vid_name not in done:  #,--- check if done already
            #do stuff
            save_as_done(vid_name)

if __name == '__main__':
    x="C:\\Python36\\videos\\*.mp4"
    done = load_done_list() #<--- You need to load this into a list
    extractFrames(x, done)  #<--- and pass it in to your function

This need something that just saves the filenames as they are done:
def save_as_done(vid_name):
    with open('video_info.csv', 'a') as f: #maybe pass in the file name so you only define it once?
        f.write(vid_name + '\n')

I haven't filled in all the details, but have shown where you can do loading and saving and checking.
The written file only has the filenames in - there doesn't seem much point in having "done" on the end of each line.
This will keep opening and closing the file as the files are processed. This may slow thing down but might not matter: you could pass in a file handle to write to, to keep it open. You have options.

A: I think you might need a function to get the list completed/done videos from the csv file.
Something like this, might need to tweak a bit for the header row.
def get_completed_videos():
    completed_videos = []
    with open(".../video_info.csv") as csv_file:
        for row in csv.reader(csv_file):
            completed_videos.append(row[0])
    return completed_videos

Then exclude them in the extracting func
def extractFrames(m):
    global vid_name

    vid_files=glob(m)
    complete_videos = get_completed_videos()
    new_vid_files = [x for x in vid_files if x not in complete_videos]

    ...

A: def extractFrames(m,done):
    global vid_name

    vid_files=glob(m)

    for v_f in range(len(vid_files)):
        print("path of video========>>>>.",vid_files[v_f])

        v1=os.path.basename(vid_files[v_f])
        vid_name = os.path.splitext(v1)[0]

        if vid_name not in done:
            try:
                vidcap = cv2.VideoCapture(vid_files[v_f])
            except cv2.error as e:
                print(e)
            except:
                print('error')
        #condition
            fsize=os.stat(vid_files[v_f])
            print('=============size of video ===================:' , fsize.st_size)
            try:

                if (fsize.st_size > 1000):

                    fps = vidcap.get(cv2.CAP_PROP_FPS)      # OpenCV2 version 2 used "CV_CAP_PROP_FPS"
                    frameCount = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
                    duration = frameCount/fps
                    minutes = int(duration/60)
                    print('fps = ' + str(fps))
                    print('number of frames = ' + str(frameCount))
                    print('duration (S) = ' + str(duration))
                    if (duration > 1):
                        success,image = vidcap.read()

                        count=0

                        success=True

                        while success:

                            img_name = vid_name + '_f' + str(count) + ".jpg"

                            success,image = vidcap.read()
                            if count % 10 == 0 or count ==0:
                                target_non_target(img_name, image)

                            count+=1

                        vidcap.release()

                        cv2.destroyAllWindows()
            except:
                print("error")

            print('finished processing video ', vid_files[v_f])
            with open("C:\\multi_cat_3\\models\\research\\object_detection\\my_imgs\\"+'video_info.csv', 'a') as csv_file:
                fieldnames = ['Video_Name','Process']
                file_is_empty = os.stat("C:\\multi_cat_3\\models\\research\\object_detection\\my_imgs\\"+'video_info.csv').st_size == 0
                writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
                if file_is_empty:
                    writer.writeheader()
                writer.writerow({'Video_Name':vid_name,'Process':'done'})

if __name__ == "__main__":

    x="C:\\Python36\\videos\\*.mp4"

    y="C:\\multi_cat_3\\models\\research\\object_detection\\my_imgs\\video_info.csv"

    done=list(y)
    extractFrames(x,done)


Q: Python3 pika channel.basic_consume() causing MySQL too many connections I had using pika to make a connection to RabbitMQ and consume message, once I start the script on ubuntu prod environment it is working as expected but is opening mysql connection and never closes them and ends up in Too many connection on mysql server.
Will appreciate any recommendation on the code below, as well can not understand what is going wrong. Thanking you in advance.
The flow is the following

*

*Starting pika on Python3

*Subscribe to a channel and waiting for messages

*In callback i do various validation and save or update data inside MySql

*The result that is showing the problem is the at the end of question a screenshot from ubuntu htop, that is showing new connection on MySql and keep adding them on the top

Pika Verion = 0.13.0
For MySql I use pymysql.
Pika Script
def main():
    credentials = pika.PlainCredentials(tunnel['queue']['name'], tunnel['queue']['password'])

    while True:
        try:
            cp = pika.ConnectionParameters(
                host=tunnel['queue']['host'],
                port=tunnel['queue']['port'],
                credentials=credentials,
                ssl=tunnel['queue']['ssl'],
                heartbeat=600,
                blocked_connection_timeout=300
            )

            connection = pika.BlockingConnection(cp)
            channel = connection.channel()

            def callback(ch, method, properties, body):
                if 'messageType' in properties.headers:
                    message_type = properties.headers['messageType']

                    if events.get(message_type):
                        result = Descriptors._reflection.ParseMessage(events[message_type]['decode'], body)
                        if result:
                            result = protobuf_to_dict(result)
                            model.write_response(external_response=result, message_type=message_type)
                    else:
                        app_log.warning('Message type not in allowed list = ' + str(message_type))
                        app_log.warning('continue listening...')

            channel.basic_consume(callback, queue=tunnel['queue']['name'], no_ack=True)
            try:
                channel.start_consuming()
            except KeyboardInterrupt:
                channel.stop_consuming()
                connection.close()
                break
        except pika.connection.exceptions.ConnectionClosed as e:
            app_log.error('ConnectionClosed :: %s' % str(e))
            continue
        except pika.connection.exceptions.AMQPChannelError as e:
            app_log.error('AMQPChannelError :: %s' % str(e))
            continue
        except Exception as e:
            app_log.error('Connection was closed, retrying... %s' % str(e))
            continue

if __name__ == '__main__':
    main()

Inside the script i have a model that doing inserts or updated in the database, code below
def write_response(self, external_response, message_type):
    table_name = events[message_type]['table_name']
    original_response = external_response[events[message_type]['response']]
    if isinstance(original_response, list):
        external_response = []
        for o in original_response:
            record = self.map_keys(o, message_type, events[message_type].get('values_fix', {}))
            external_response.append(self.validate_fields(record))
    else:
        external_response = self.map_keys(original_response, message_type, events[message_type].get('values_fix', {}))
        external_response = self.validate_fields(external_response)

    if not self.mysql.open:
        self.mysql.ping(reconnect=True)

    with self.mysql.cursor() as cursor:
        if isinstance(original_response, list):
            for e in external_response:
                id_name = events[message_type]['id_name']
                filters = {id_name: e[id_name]}
                self.event(
                    cursor=cursor,
                    table_name=table_name,
                    filters=filters,
                    external_response=e,
                    message_type=message_type,
                    event_id=e[id_name],
                    original_response=e  # not required here
                )
        else:
            id_name = events[message_type]['id_name']
            filters = {id_name: external_response[id_name]}
            self.event(
                cursor=cursor,
                table_name=table_name,
                filters=filters,
                external_response=external_response,
                message_type=message_type,
                event_id=external_response[id_name],
                original_response=original_response
            )
    cursor.close()
    self.mysql.close()

    return

On ubuntu i use systemd to run the script and restart in case something goes wrong, below is systemd file
[Unit]
Description=Pika Script
Requires=stunnel4.service
Requires=mysql.service
Requires=mongod.service

[Service]
User=user
Group=group
WorkingDirectory=/home/pika_script
ExecStart=/home/user/venv/bin/python pika_script.py
Restart=always

[Install]
WantedBy=multi-user.target

Image from ubuntu htop, how the MySql keeps adding in the list and never close it

Error
tornado_mysql.err.OperationalError: (1040, 'Too many connections')

A: i have found the issue, posting if will help somebody else.
the problem was that mysqld went into infinite loop trying to create indexing to a specific database, after found to which database was trying to create the indexes and never succeed and was trying again and again.
solution was to remove the database and recreate it, and the mysqld process went back to normal. and the infinite loop to create indexes dissapeared as well.

A: I would say increasing connection may solve your problem temperately.
1st find out why the application is not closing the connection after completion of task.
2nd Any slow queries/calls on the DB and fix them if any.
3rd considering no slow queries/calls on DB and also application is closing the connection/thread after immediately completing the task, then consider playing with "wait_timeout" on mysql side.

A: According to this answer, if you have MySQL 5.7 and 5.8 :

It is worth knowing that if you run out of usable disc space on your
server partition or drive, that this will also cause MySQL to return
this error. If you're sure it's not the actual number of users
connected then the next step is to check that you have free space on
your MySQL server drive/partition.

From the same thread. You can inspect and increase number of MySQL connections.


Q: How can I do for my Items inside a ListView start at the right to left? I want make my Items inside a ListView going right to left.
At the moment I have default settings:

As you can see I have a hole in the right and I want to reverse this, put a hole in the left.
Hope you understand the problem.
 <telerikDataControls:RadListView ItemsSource="{Binding CatalogSizes, Source={x:Reference ExtendedContentView}}" >
    <telerikDataControls:RadListView.ItemTemplate>
        <DataTemplate>
            <listView:ListViewTemplateCell>
                <listView:ListViewTemplateCell.View>
                    <Frame Padding="0" CornerRadius="3.5" BackgroundColor="{Binding IsEnabled, Converter={StaticResource Batata}, ConverterParameter={x:Reference Name=MainColorGrid}}">
                        <Label Text="{Binding Quantity}" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
                     </Frame>
                 </listView:ListViewTemplateCell.View>
             </listView:ListViewTemplateCell>
          </DataTemplate>
      </telerikDataControls:RadListView.ItemTemplate>
      <telerikDataControls:RadListView.LayoutDefinition>
          <listView:ListViewGridLayout SpanCount="3" HorizontalItemSpacing="3" />
       </telerikDataControls:RadListView.LayoutDefinition>
</telerikDataControls:RadListView>

A: You can change the Direction, to RTL. In CSS is just:
 direction: rtl;

You can see a sample here.


Q: ActiveRecord conditional count In my application, I'm trying to sort items by views within the last 10 days. I'm using the Impressionist gem, which creates a model called impression and records every view here.
I've managed to get to this piece of code:
@items = Item.joins("left join impressions on impressions.impressionable_id = items.id and impressions.impressionable_type = 'Item'")
                   .select("count(distinct(ip_address)) as counter, impressionable_id, items.title, items.id, items.image")
                   .group('items.id')
                   .order("counter desc")
                   .page(params[:page])
                   .per_page(9)

This sorts the items by total unique views. However, I want to only count the impressions which have been made within the last 10 days. This led me to add a where method as such:
  time_range = (Time.now - 10.days)..Time.now

  @items = Item.joins("left join impressions on impressions.impressionable_id = items.id and impressions.impressionable_type = 'Item'")
   .select("count(distinct(ip_address)) as counter, impressionable_id, items.title, items.id, items.image")
   .where('impressions.created_at' => time_range)
   .group('items.id')
   .order("counter desc")
   .page(params[:page])
   .per_page(9)

However, this excludes the items which has no views, which is not what I want. These should be represented with 0 view.
Any suggestions how to fix this problem?

A: I had to use CASE, along with some modifications to make it run on heroku's postgres server.
  start_date = (Time.now - 10.days)
  end_date = Time.now
  joins("left join impressions on impressions.impressionable_id = items.id and impressions.impressionable_type = 'Item'")
      .select("count(distinct(case when (impressions.created_at BETWEEN '#{start_date}' AND '#{end_date}') then ip_address end)) as counter, impressionable_id, items.gender, items.title, items.id, items.image")
      .group('items.id', 'impressions.impressionable_id')
      .order("counter desc")


Q: not able to click the login button through selenium
please create a selenium code for us where i am not able to hit the Login Button. see my code below and do the correction :
    driver.findElement(By.id("Log In")).click();
    driver.findElement(By.className("submit")).click();
    driver.findElement(By.cssSelector(".sbt-btn-wrap relative .submit")).click();
    driver.findElement(By.className("formButton")).click();

A: Try this below xpath.
Explanation: User value attribute of input tag.
driver.findElement(By.xpath("//input[@value='Log In']")).click();

For click on Lock and Edit button use this code.
 driver.findElement(By.xpath("//input[@value='Lock & Edit']")).click();


Q: In Asp.net, why is the request input stream position sometimes not at position 0 in my controller? Two methods in my ASP.NET MVC3 web service behave differently when I POST to them.
/project
/project/{id}/snapshots

In the first method I can read the POST'ed JSON from the Request.InputStream however in the second method the input stream is not at position 0 and I have to seek to the beginning. Even with nearly identical code in both controllers (except for the parameter of course) the input stream position is still different.
My question is why are the streams in different positions?


Q: How do I map two lists to one list in Automapper? I have the following setup:
public class ClassA
{
    public int Id { get; set; }
    public int JoinId { get; set; }
}

public class ClassB
{
    public string Name { get; set; }
    public int JoinId { get; set; }
}

public class ClassC
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int JoinId { get; set; }
}

I have a list of ClassA and a list of ClassB
I want a list of ClassC using Automapper. The result should be a Full Outer Join on JoinId.
How can I achieve this?

A: Why not just write the code for it?
var listOfA = new List<A>();
var listOfB = new List<A>();
... // Code for adding values
listOfA.ToC(listOfB);

public static class OuterJoinExtension
{
    public static List<C> ToC(this List<A> listOfA, List<B> listOfB)
    {
        var listOfC = new List<C>();
        listOfA.ForEach(a => listOfB.ForEach(b =>
        {
            if (b.JoinId == a.JoinId)
            {
                listOfC.Add(new C { Id = a.Id, JoinId = b.JoinId, Name = b.Name });
            }
        }));
        return listOfC;
    }
}

A: For simplicity I'll assume these are contained within another class:
class Original
{
    List<ClassA> ClassAs { get; set; }
    List<ClassB> ClassBs { get; set; }
}

class Result
{
    List<ClassC> ClassCs { get; set; }
}

You can map the former to the latter using
Mapper.CreateMap<Original, Result>().ForMember(x => x.ClassCs,
    x => x.MapFrom(x.ClassAs.Join(
                        y.ClassBs,
                        xEntry => xEntry.JoinId,
                        yEntry => yEntry.JoinId,
                        (xEntry, yEntry) => new ClassC {
                                              Id = xEntry.Id,
                                              Name = yEntry.Name,
                                              JoinId = xEntry.JoinId});


Q: How to add a PNG-File-Array to an ArrayList - Java I have this method:
private ArrayList<Image> imageArray(File files[]) {

    ArrayList<Image> images = null;

    for(int x = 0; files.length > x; x++) {

        //I want to add each PNG-File to the Image-Array

        try {
            images.add(x, ImageIO.read(files[x])); //Demo.imageArray(Demo.java:23)
        }catch(IOException | ArrayIndexOutOfBoundsException exception) {
            exception.printStackTrace();
        }

        //Now I scale each Image, so it fits the screenSize

        int newWidth = (int) screenSize.getWidth(),
            newHeight = newWidth * images.get(x).getHeight(null) / images.get(x).getWidth(null);

        if(newHeight > screenSize.getHeight()) {

            newHeight = (int) screenSize.getHeight();
            newWidth = newHeight * images.get(x).getWidth(null) / images.get(x).getHeight(null);
        }

        images.set(x, images.get(x).getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH));
    }

    return images;
}

which causes this Exception :
Exception in thread "main" java.lang.NullPointerException
    at Demo.imageArray(Demo.java:23) //I've marked the position in the code!
    at Demo.main(Demo.java:47) // Just, when I want to use the method anywhere

Why do I get that Error and how can I work around it? I have added a parameter, when I wanted to use the method, which looks like this :
imageArray(new File[] {new File("filePath to PNG-Image"),
            new File("filePath to PNG-Image")})

A: A simple solution would be to initialize images.
So instead of just doing this:
ArrayList<Image> images = null;

Do this:
ArrayList<Image> images = new ArrayList<>();


Q: Adding url to mysql row in python I am trying to add a url to a text row in mysql using python and the MySQLdb library, but when I run my code it says there is an error in my sql syntax. Can you tell me what im doing wrong?
Here is my code:
import MySQLdb as mdb
connection = mdb.connect("Localhost", "root", "", "db")
cursor = connection.cursor()
url = mdb.escape_string("http://www.google.com")
cursor.execute("""INSERT INTO index(url) VALUES(%s)""", (url,))

Here is the error:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner
self.run()
File "E:\prospector\webworker.py", line 77, in run
cursor.execute("INSERT INTO index(url) VALUES('%s')", (url_t,))
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 202, in execute
self.errorhandler(self, exc, value)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index(url) VALUES('http://www.google.com/')' at line 1")

A: I was able to replicate your problem like this:
mysql> create table `index` (url varchar(50));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into index(url) values ('http://www.google.com');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index(url) values ('http://www.google.com')' at line 1

mysql> insert into `index`(url) values ('http://www.google.com');
Query OK, 1 row affected (0.00 sec)

index is a keyword in MySQL. Your life will be easier if you do not use it as a table name.
However, if you really want to, you can use it, but then you have to quote it:
cursor.execute("""INSERT INTO `index`(url) VALUES(%s)""", (url,))

PS: No need to call
url = mdb.escape_string("http://www.google.com")

MySQLdb will do that automatically for you when you call
cursor.execute("""INSERT INTO index(url) VALUES(%s)""", (url,))

In fact, since cursor.execute calls mdb.escape_string for you, doing it yourself could cause undesired values to be inserted into the database depending on the value of url:
In [105]: MySQLdb.escape_string("That's all folks")
Out[105]: "That\\'s all folks"

In [106]: MySQLdb.escape_string(MySQLdb.escape_string("That's all folks"))
Out[106]: "That\\\\\\'s all folks"


Q: How to use output file in another powershell command? I'm using auto-editor first to cut out motionless parts, then Mp4Box to add my intro.
I can't figure out how to automatically use the output from auto-editor into Mp4Box.
This is what I have so far.
Get-ChildItem -Filter *.mp4 | ForEach -Process {mp4box -add c:\intro.mp4 -cat $_ -new $a($_.BaseName + '.mp4') -force-cat && del $_ && auto-editor $a --edit_based_on motion --motion_threshold 0.000001% --no_open}

I tried adding $a to make the output into a variable but that doesn't work. I have the script reversed for testing purposes as Mp4Box is a lot faster than auto-editor.

A: You have to create the variable $a on a separate statement, before calling any of the commands that uses it.
Get-ChildItem -Filter *.mp4 | ForEach {
     $a = $_.BaseName + '.mp4'
     mp4box -add c:\intro.mp4 -cat $_ -new $a -force-cat &&
     del $_ &&
     auto-editor $a --edit_based_on motion --motion_threshold 0.000001% --no_open
}

I've also added some line breaks to make the code more readable.


Q: How to configure a Daphne server to invite clients to add the Certificate Authority that issued my certificate if they hadn't done it yet? If I make a request to my Daphne/Django server in Postman or the Android app we're developing, Daphne serves the certificate, but it's rejected. If I first make a simple get request to https://letsencrypt.org/ and then make a request to my server, the certificate is accepted.
How can I make sure a client will trust my certificate, even if it's the first time this client is seeing a certificate issued by this CA?
Everything bellow can serve as a history of how I studied the problem.
Original title: SSL Certificate works in browser but can't be verified by Postman
I have an AWS EC2 instance running Ubuntu 18.04, with python 3, Django, a bunch of project dependencies, Daphne running with ASGI, with a certificate by Let's Encrypt. Daphne is using port 8000 for HTTP and por 4430 for HTTPS, iptables is configured to redirect requests from port 80 to 8000 and from port 443 to 4430. Django is configured to enforce secure connections with SECURE_SSL_REDIRECT=True in the settings.py file.
There's a "Site in Construction" temporary page being served, and it's properly accessible from every browser and every device I tested so far. If I explicitly type http, I get redirected to https and the certificate is accepted. Every browser I tested (Firefox, Brave, Chrome, Chrome for Android) says cert is good.
Curl outputs the HTML content returned from the server. I don't know if it accepts the certificate or ignores it.

The Problem
Postman, however, says "Error: unable to verify the first certificate". Only works when I disable "SSL certificate verification", which doesn't answer my question: why Postman is unable to verify my Let's Encrypt certificate?
I'm building an API that runs on the same server, using the same domain, and it's meant to be consumed by a mobile app. Currently, the Android app is throwing a "TypeError: Network request failed", which I suspect could be caused by the same thing Postman is complaining about.
When I spin the server locally and configure 1) the app to use http://localhost:8000 and 2) the server not to enforce SSL, it works in browsers, Postman and in the Android app.
I've being looking for answers in many places for days, so any clue will be very welcome.
EDIT
Interesting clue:
If I make a request to my Daphne/Django server, it servers the certificate, which is rejected. But if I first make a request to https://letsencrypt.org/ and then make a request to my server, it works!
This pattern holds true in both Postman and our Android app.
It also happens when I first make a request to https://alloy.city (instead of letsencrypt.org), which is served by a Node.js app, and uses a certificate also issued by the Let's Encrypt CA.
So maybe the question should be: how to configure my server to politely invite clients to add the CA that issued my certificate if they hadn't done it yet?.
Apparently, that's what my Node.js server does.

A: Yes, in settings, tap ssl verification off
File > Settings > General > SSL Certificate Verification > off


Q: Python XML Parser not Returning XML Elemements I am trying to find a way to use Python to parse data from several .xml files that contain part numbers and descriptions for a system my team is working on. Here's what the files look like:
Note: Actual data sanitized for confidentiality reasons.
<DOCUMENT>
<config>
<lruname>NFS</lruname>
<swpn>123-A-456-7890</swpn>
<swname>00 NFS ABC DEFGHI XYZ JKL</swname>
<swver>Appid: abc-defghi-xyz  PN: 123-A-456-7890</swver>
</config>
</DOCUMENT>

I'd like to pull the  and  datatypes from several of these files into .csv format. My initial thought was to try to parse these data types out into a dictionary using the built in xml.etree library, but for some reason it's not finding the elements:
import xml.etree.ElementTree as ET

data = '''
<DOCUMENT>
<config>
<lruname>NFS</lruname>
<swpn>123-A-456-7890</swpn>
<swname>00 NFS ABC DEFGHI XYZ JKL</swname>
<swver>Appid: abc-defghi-xyz  PN: 123-A-456-7890</swver>
</config>
</DOCUMENT>
'''

tree = ET.fromstring(data)
PartNo = tree.find('swpn')
Desc = tree.find('swname')

print(PartNo)

The above code returns 'None' for some reason, but I would expect it to return the xml element I'm calling.

A: I think you're missing the config level in your XML hierarchy, you could do:
part_number = tree.find('config').find('swpn').text
part_desc = tree.find('config').find('swname').text

Alternately you can loop through all the elements if you don't want to have to know the structure and use conditionals to find the elements you care about with tree.iter.
for e in tree.iter():
    if e.tag == 'sqpn':
        part_number = e.text
    if e.tag == 'swname':
        part_desc = e.text

A: ElementTree and etree's find functionality searchers for direct children.
You can still use it by specifying the entire branch:
tree.find('config').find('swpn')
tree.find('config/swpn')

If you always want to look for swpn, but disregard the structure (e.g. you don't know if it's going to be a child of config), you might find it easier to use the xpath functionality in etree (and not in ElementTree):
tree = etree.fromstring(data)
tree.xpath('//swpn')

In this case, the // basically mean that you are looking for elements in tree, no matter where they are
If the xml files are small, and you don't care about performance, you can use minidom which IMHO is more convenient compared to lxml. In this case, your code could be something like this:
from xml.dom.minidom import parseString
xml = parseString(data)
PartNo = xml.getElementsByTagName('swpn')[0]
Desc = xml.getElementsByTagName('swname')[0]
print(PartNo.firstChild.nodeValue)


Q: Location of css file in a GWT project I have css file named Sample.css which contain the below contents.
         .bandit-report{
       margin-left: 20px;
          }
         .bandit-report1{
         margin-left: 50px;
          }

I have the ABCD.gwt.xml where I have made the below entry for the css file
    <stylesheet src='Sample.css' />

I set the style name using setStyleName(String) method. However the margin-left changes are not getting reflected. I dont know where to place the Sample.css file. I have currently place both ABCD.gwt.xml and Sample.css in the same directory.
Kindly Help.

A: Relative paths in <stylesheet> in a gwt.xml files are relative to the "module base URL" (returned by GWT.getModuleBaseURL() on the client-side code; this is the folder into which GWT will generate the nocache.js file and everything else). Having a file output in this directory is as easy as putting it in your public path, which by default is a public subfolder of your GWT module (next to your client subpackage). It's worth noting that public paths are inherited from modules you <inherit>; this is how GWT's built-in themes work.
If you put your stylesheet in your war folder, then you shouldn't inject it from your gwt.xml, you should rather load it with a <link rel=stylesheet> in your HTML host page.

A: I changed the entry made in ABCD.gwt.xml to as below. Now its working.
     <stylesheet src='/Sample.css' />

A: Use your browser developer panel to find out the location of css file.

A: You should create a folder named public in the same place where your client, server and shared folders are and put it in there, that's the default location it will look.


Q: Compiling .xsl files into .class files I'm currently working on a Java web project (Spring) which involves heavy use of xsl transformations. The stylesheets seldom change, so they are currently cached. I was thinking of improving performance by compiling the xsl-s into class files so they wouldn't have to be interpreted on each request.
I'm new to Java, so I don't really know the ecosystem that well. What's the best way of doing this (libraries, methods etc.)?
Thanks,
Alex

A: You might not have to compile to .class to achieve your goal, you can compile the xsl once per run and re-use the compiled instance for all transformations.
To do so you create a Templates object, like:
TransformerFactory factory = TransformerFactory.newInstance();
factory.setErrorListener(new ErrorListener( ... ));
xslTemplate = factory.newTemplates(new StreamSource( ... ));

and use the template to get a transformer to do the work:
Transformer transformer = xslTemplate.newTransformer();

Depending on the XSL library you use your mileage may vary.

A: You'll need a Template and a stylesheet cache:
http://onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=9
Do be careful about thread safety, because Transformers aren't thread safe.  Best to do your transformations in a ThreadLocal for isolation.

A: Consider using Gregor/XSLT compiler


Q: netlink on ClearOS 7.3 issue I am trying following simple program on ClearOS 7.3, 64 bit
#include <sys/socket.h>
#include <linux/netlink.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

int main()
{
    int flags =0;
    int bus = NETLINK_NETFILTER;

    int sock_fd = socket(AF_NETLINK, SOCK_RAW | flags, bus);
    if(sock_fd<0)
    {
        printf("\nsocket failed with error no = %d and error msg = %s\n",
                                errno, strerror(errno));

        return -1;
    }

    printf("\nOP completed successfully..!\n");
    return 0;
}

I am getting following error:

socket failed with error no = 93 and error msg = Protocol not
  supported

My OS details are:

*

*ClearOS release 7.3.0 (Final)

*Linux 3.10.0-514.26.2.v7.x86_64 #1 SMP Wed Jul 5 10:37:54 MDT 2017
x86_64 x86_64 x86_64 GNU/Linux

Please help.

A: Works for me.
The NETLINK_NETFILTER protocol is registered by the nfnetlink module.
In my case, the kernel registers the module automatically since this code uses it, but if yours doesn't, try inserting it manually:
$ sudo modprobe nfnetlink

And then try opening the socket again.


Q: Copying a dynamic array of structs to another dynamic array of structs I am trying to copy the contents of a dynamic array of structs to another dynamic array of structs, but I am getting the error, 'invalid array assignment' and was hoping someone could point me in the right direction.
Here is my struct:
struct Agent
{
    char name[C_STRING_SIZE];
    int idNum;
    double years;
    char location[C_STRING_SIZE];
};

My function:
Agent *copyEncryptArray(Agent *agentArr, int numOfAgents)
{
    Agent *encryptArr = new Agent[numOfAgents];

    for (int i = 0; i < numOfAgents; i++)
    {
        encryptArr[i].name = agentArr[i].name;
        encryptArr[i].idNum = agentArr[i].idNum;
        encryptArr[i].years = agentArr[i].years;
        encryptArr[i].location = agentArr[i].location;
    }

    return encryptArr;
}

Ultimately, I am trying to encrypt the contents of the agentArr then copy it to encryptArr but I am just trying to figure out how to copy for now. This is for a course and we have not covered memcpy yet so that is not an option.

A: It's easier than you think.
for (int i = 0; i < numOfAgents; i++)
    encryptArr[i] = agentArr[i];

Each value in the array is something that meets all requirements of an "object", and can be copied/moved as a whole. No need to bother copying each member of the struct.

A: You should use std::string instead of char arrays. It is assignable and there are more merits including almost unlimited length of string.
struct Agent
{
    std::string name;
    int idNum;
    double years;
    std::string location;
};

If you are unfortunately forced to use arrays for some reason, you will have to assign each elements.
If it is guaranteed that the contents of the arrays will always be strings (sequences of characters terminated by null-character), you can use strcpy() to copy them.
(I will show only code for name, but location should also be treated like this)
        strcpy(encryptArr[i].name, agentArr[i].name);

If you cannot guarantee this, you should use memmove() (because memcpy() is banned here).
        memmove(encryptArr[i].name, agentArr[i].name, sizeof(encryptArr[i].name));

If memmove() is also unfortunately banned, the last option will be assigning the elements one-by-one.
        for (int j = 0; j < C_STRING_SIZE; j++)
        {
            encrypyArr[i].name[j] = agentArr[i].name[j];
        }


Q: Convert Java loop to Kotlin I'm studying implementation with Kotlin. When I implement Kotlin version by below situation, I can't imagine cool way.
for(i = 0 ; i + 8 <= table.size; i++){
 for(j = 0 ; j + 8 <= table[0].size; j++{
  whatever
 }
}

Above code is Java version
for(i in 0 until table.size){
 if(i+8 > table.size)break
  for(j in until table[0].size){
    if(j+8 > table[0].size)break
      whatever
   }
}

Above is Kotlin version which I think.
Is this fine way?

A: You can just move the -8 into the upper limit, and since you include (<=) the upper limit you shouldn't be using until, but the regular range expansion with two dots.
So it becomes:
for (i in 0..table.size-8){
    for (j in 0..table[i].size-8){}
}

(I imagine you would also want to replace the magical number eight with a variable with a meaningful name)


Q: Uploading in IE fails while using jQuery to click on the input tags for file and submit in a form So I am trying to get this uploading script to work inside of IE.  It works fine in other browsers but when I try it in IE the form doesn't submit.  I am using jQuery and CSS to build my own form instead of using what the  and  tags show, and then i use jQuery to click on those  tags.  However in IE when I select a file and submit the form, IE says there is nothing in the file input and doesn't run the PHP script specified in the action attribute of the form.  Any ideas?  I haven't been able to find any help for this just by searching.


Q: How to repeat an html element n number of times using javascript I'm trying to print an element, in my case an hr tag some number of times according to the length of a word. This code is for a hangman game I'm trying to recreate. I have looked up similar questions and its not quite what I'm lookin for.
This is my javascript code so far.
var words = ['Quaffle', 'Bludger', 'Golden Snitch', 'Time-Turner',
'Pensieve', 'Mirror of Erised'];

function getRandomWord(){
   var randomIndex = words[Math.floor(Math.random()* words.length)];
   alert(randomIndex);
}

function printDashes(){
   var dashes = document.getElementById("dash")
}

getRandomWord()
printDashes()

I'm not sure what to add after retrieving the element. Can someone guide me on how to go about this?

A: You can also create div's so you can enter letters when the user inputs a character. I've attached an example below.
UPDATE: Added example code to update the dashes with letters based on word

var elem = document.getElementById('container');
var guess = document.getElementById('guess');
var word = "Hello";

// draw empty dashes
var drawDashes = function(numberOfDashes) {
  for (var i = 0; i < numberOfDashes; i++) {
    var el = document.createElement('div');
    el.classList = 'dash';

    // we draw an empty character inside so that the element
    // doesn't adjust height when we update the dash later with a
    // letter inside
    el.innerHTML = ' ';

    elem.appendChild(el);
  }
}

// update dash with a letter based on index
var updateDash = function(index, letter) {
  elem.children[index].innerHTML = letter;
}

guess.addEventListener('keyup', function(evt) {

  // split the word up into characters
  var splitWord = word.split('');

  // check to see if the letter entered matches any of the
  // words characters
  for (var i = 0; i < splitWord.length; i++ ) {

    // it is important we convert them to lowercase or
    // else we might get a mismatch because of case-sensitivity
    if (evt.key.toLowerCase() === splitWord[i].toLowerCase()) {

      // update dash with letter based on index
      updateDash(i, evt.key.toLowerCase());
    }
  }

  // clear out the value
  this.value = '';
});

drawDashes(word.length);
body {
  font-family: sans-serif;
}

.dash {
  height: 50px;
  width: 50px;
  margin: 0 10px;
  display: inline-block;
  border-bottom: 2px solid black;
  font-size: 32px;
  font-weight: bold;
  text-align: center;
}

#guess {
  height: 50px;
  width: 50px;
  padding: 0;
  font-size: 32px;
  text-align: center;
}

Type a letter

<input id="guess" type="text"/>

A: Say your word is in some variable named myWord.
Get the length of the word by doing:
var myWordLen = myWord.length;

Then you can create HTML elements using Javascript createElement method and appending child elements, information etc as needed. But since you want as many elements as the length of a word, use a loop. Eg:
for(var i=0; i < myWordLen; i++)
{
    var tr1 = document.createElement("hr");
    var someEle = document.getElementById("someID");
    someEle.appendChild(tr1);
}

A: What about this way?
myElement.innerHTML = `<...>`.repeat(words.length)


Q: HTML content encoded, started with '' sign I have received an email and the body is formed in HTML format. However, I was wondering how can I decode the encoded content as following:
<a href=3Dhttp://０．ｇｇ/DFt2U>
Could anyone tell me how to decode the string? The transfer encoding is Qouted-printable, and the charset is big5. However, I tried to decode the content with qp-decoder and nothing works. Thanks.

A: Try the link below:
http://toolswebtop.com/text/process/decode/BIG-5
I tried your link and got 3Dhttp://０．ｇｇ/DFt2U


Q: How can I get my templated function to see other global methods defined later? (Oktalist gave a great answer below, check it out and the comments under it, to help demonstrate everything we've discussed, I've added a full, compiling solution at the bottom of my question that demonstrates everything discussed.)
I have a collection of namespace global methods and templated methods like the following:
namespace PrettyPrint
{
    String to_string(bool val);
    String to_string(char val);
    String to_string(int val);
    String to_string(uint val);
    // ETC...

    template <typename T> String to_string(const T* val)
    {
        if (! val) return U("NULL");
        return String().copy_formatted("(%p)-> %S", (const void*)val, to_string(*val).uchars());
    }

    // ... and more templates to help with containers and such
}

The "String" type is not the C++ string, it's a special class derived off of IBM's ICU library, but not really relevant for this question.  Point is, I have a bunch of namespace global methods called to_string and also some templated functions that override them.  So far, so good, everything works great.  But, now I have another header where I have something like the following defined:
namespace User
{
    struct Service {
        int code;
        String name;
    }
    //...
}
namespace PrettyPrint
{
    String to_string(const User::Service& val) { return val.name; }
}

So, now I have defined some other type somewhere else, and I've also defined another to_string override in my PrettyPrint namespace to indicate how to convert my new type to a String.  Toss both headers into a file, something like this:
#include <the to_string and templates header>
#include <the User::Service header>

main() {
    User::Service s = {1, U("foo")};
    User::Service *p = &s;
    PrettyPrint::to_string(s);
    PrettyPrint::to_string(p);
}

(Yes, the to_string methods should actually be returning a value somewhere, not the point.) The point is that the second call gives a compiler error (gcc, btw) saying that in the templated to_string method there is no matching function for call to 'to_string(const User::Service&)', which of-course exactly matches my method that is defined and included. If I reverse the #include ordering it works just fine.
So, I surmise that the template is only looking at methods defined ahead of it.  Is there any fix for this?  Given the scope of my project and number of complicated #include's, simply saying "always make sure they come in the right order" is not a tractable solution, and would introduce too much complicated fragility in the code.  The base to_string defintions is one of those files that will tend to get included high up in a lot of places, so making sure that any other random type definitions that happen to include a to_string override come first just isn't going to work.
The other solution I have that works in some places is that I've defined a Printable interface in the base file:
namespace PrettyPrint
{
    class Printable {
    public:
        virtual String pretty_print_to_string() const = 0;
    }

    String to_string(const Printable& obj) { return obj.pretty_print_to_string(); }
}

That definition comes before the template methods in the same file.  So, that works great for classes where I can simply add in that interface and implement it.  Short of any great solutions here, I'm going to simply try to always use that, but there are places where it is not convenient and I'd also just like to understand if there is any way to get the method overloading solution to work without being dependent on #include ordering to work.
Anyhow, what do you all think of these options?  Is there an approach that I haven't thought of that might work nicely?
Solution inspired from answer Oktalist gave
This code actually does compile so you can copy it off and play with it, I think I've captured all the relevant use cases along with what works and what doesn't and why.
#include <iostream>

using namespace std;

namespace PrettyPrint
{
    void sample(int val) { cout << "PrettyPrint::sample(int)\n"; }
    void sample(bool val) { cout << "PrettyPrint::sample(bool)\n"; }
    template<typename T> void sample(T* val) { cout << "PrettyPrint::sample(pointer); -> "; sample(*val); }
}

namespace User
{
    struct Foo {
        int i;
        bool b;
    };

    void sample(const Foo& val) {
        //below doesn't work un-qualified, tries to convert the int (val.i) into a Foo to make a recursive call.
        //meaning, it matches the User namespace version first
        //sample(val.i); doesn't work, tries to call User::sample(const Foo&)

        cout << "User::sample(const Foo&); -> {\n";
        cout << '\t'; PrettyPrint::sample(val.i); //now it works
        cout << '\t'; PrettyPrint::sample(val.b);
        cout << "}\n";
    }
}

namespace Other
{
    void test(User::Foo* fubar) {
        cout << "In Other::test(User::Foo*):\n";
        //PrettyPrint::sample(*fubar); //doesn't work, can't find sample(const User::Foo&) in PrettyPrint
        PrettyPrint::sample(fubar); //works, by argument-dependent lookup (ADL) from the template call
        sample(*fubar); //works, finds the method by ADL
        //sample(fubar); //doesn't work, only sees User::sample() and can't instantiate a Foo& from a Foo*
    }

    void test2(User::Foo* happy) {
        using PrettyPrint::sample; //now both work! this is the way to do it.
        cout << "In Other::test2(User::Foo*):\n";
        sample(*happy);
        sample(happy);
    }
}

int main() {
    int i=0, *p = &i;
    bool b=false;
    User::Foo f = {1, true}, *pf = &f;

    //sample(i);  <-- doesn't work, PrettyPrint namespace is not visible here, nor is User for that matter.
    PrettyPrint::sample(i); //now it works
    //PrettyPrint::sample(f); //doesn't work, forces search in PrettyPrint only, doesn't see User override.

    using namespace PrettyPrint;  // now they all work.
    sample(p);
    sample(b);

    sample(f);
    sample(pf);

    Other::test(pf);
    Other::test2(pf);

    return 0;
}

This results in the following output:
PrettyPrint::sample(int)
PrettyPrint::sample(pointer); -> PrettyPrint::sample(int)
PrettyPrint::sample(bool)
User::sample(const Foo&); -> {
    PrettyPrint::sample(int)
    PrettyPrint::sample(bool)
}
PrettyPrint::sample(pointer); -> User::sample(const Foo&); -> {
    PrettyPrint::sample(int)
    PrettyPrint::sample(bool)
}
In Other::test(User::Foo*):
PrettyPrint::sample(pointer); -> User::sample(const Foo&); -> {
    PrettyPrint::sample(int)
    PrettyPrint::sample(bool)
}
User::sample(const Foo&); -> {
    PrettyPrint::sample(int)
    PrettyPrint::sample(bool)
}
In Other::test2(User::Foo*):
User::sample(const Foo&); -> {
    PrettyPrint::sample(int)
    PrettyPrint::sample(bool)
}
PrettyPrint::sample(pointer); -> User::sample(const Foo&); -> {
    PrettyPrint::sample(int)
    PrettyPrint::sample(bool)
}

A: During the first phase of two phase lookup, when the template is defined, unqualified lookup looks for dependent and non-dependent names in the immediate enclosing namespace of the template and finds only those to_string overloads which appear before the template definition.
During the second phase of two phase lookup, when the template is instantiated, argument-dependent lookup looks for dependent names in the namespaces associated with any class types passed as arguments to the named functions. But because your to_string(const User::Service&) overload is in the PrettyPrint namespace, it will not be found by argument-dependent lookup.
Move your to_string(const User::Service&) overload into the User namespace to make use of argument-dependent lookup, which will find any overloads declared at the point of template instantiation, including any declared after the point of template definition.
See also http://clang.llvm.org/compatibility.html#dep_lookup

A: What the compiler does when instantiating a template is essentially expanding it (more or less like a macro), and compiling the result on the fly. To do that, any functions (or other stuff) mentioned must be visible at that point. So make sure any declarations used are mentioned beforehand (in the same header file, most probably).

A: I don't entirely understand what's going on here, but it appears that if you want the later defined methods to be used, then they need to be template specializations.  The compiler won't see function overrides later in the program.
First off, we reproduce the problem.  I do so with this program in gcc-4.8.2:
// INCLUDE FILE 1
template <class T> void to_string (T const * a) {
  to_string (*a);
}
// INCLUDE FILE 1 END

// INCLUDE FILE 2
// How do we make this program work when this is necessarily declared after to_string(T const * A)?
void to_string(int const & a) {
  return;
}
// INCLUDE FILE 2 END

int main (void) {
  int i = 5;
  int * p = &i;

  to_string(i);
  to_string(p);
  to_string(&i);

  return 0;
}

In order to get it working, we need to do this...
// INCLUDE FILE 1
// The pointer version needs something to call...
template <class T> void to_string (T const & a);

// This can't be T const * a.  Try it.  So weird...
template <class T> void to_string (T * a) {
  foo (*a);
}
// INCLUDE FILE 1 END

// INCLUDE FILE 2
// This has to specialize template<> void to_string.  If we just override, we get a linking error.
template<> void to_string <int> (int const & a) {
  return;
}
// INCLUDE FILE 2 END

int main (void) {
  int i = 5;
  int * p = &i;

  to_string(i);
  to_string(p);
  to_string(&i);

  return 0;
}


Q: LiveData Duplicate Observers Concern I won't explain why this code is needed, but my question is whether the following code will lead to duplicate Observers or not:

  override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initializeRecyclerView()
        viewModel = ViewModelProvider(this).get(TestViewModel::class.java)

        updateUI()

        viewModel.getNewItems().observe(viewLifecycleOwner, {
            if (it != null && it == true){
                updateUI()
            }
        })
    }

    fun updateUI(){
        viewModel.getItems().observe(viewLifecycleOwner, Observer {
            adapter.values = it
            adapter.notifyDataSetChanged()
        })
    }

    fun initializeRecyclerView() {
        recyclerView.adapter = adapter
    }
}

As updateUI() gets called multiple times, does this create duplicate observers of viewmodel.getItems()??


Q: Azure Redis Cache vs Redis Cloud service on Azure I need to use it in a .NET (webapi) app & using stackexchange.redis nuget package.
Appreciate if someone please point me to appropriate resources for following -
1) Can I choose any of Azure Redis cache or Redis cloud service if I interface through stackexchange.redis nuget?
2) Azure Redis Cache vs Redis Cloud - differences & implications of choosing one over the other - if this info already available.
Thanks

A: Disclaimer: I work for Redis Labs, the company providing Redis Cloud.

1) Can I choose any of Azure Redis cache or Redis cloud service if I interface through stackexchange.redis nuget?

Yes - both Azure Redis and Redis Cloud provide a Redis database that you can use with the StackEchange.Redis client from your app.

2) Azure Redis Cache vs Redis Cloud - differences & implications of choosing one over the other - if this info already available.

While both are essentially a hosted Redis service, there are several differences between them. Most notably, Azure Redis Cache is deeply integrated in the Azure platform so you have everything (management, metrics, etc...) accessible from your management portal. OTOH, Redis Cloud is cloud-agnostic (it is available on multiple clouds) and offers more features than any other Redis-as-a-Service service. I think that the fact that Redis Cloud is the only service that can scale infinitely and w/o downtime/migration is perhaps the strongest differentiator, but feel free to refer to this comparison table for a high level overview: https://redislabs.com/redis-comparison


Q: Use Intl.NumberFormat to format square foot units I'm trying to use Intl.NumberFormat to format numbers with units and I have some units of square feet.
When I try
new Intl.NumberFormat('en-US', { useGrouping: true, style: "unit", unit: "square-foot" }).format(56)

Uncaught RangeError: Invalid unit argument for Intl.NumberFormat() 'square-foot'

The MDN documentation links to small list of approved units which were taken from a much larger list. The larger list has square feet but the smaller list does not, so that all makes sense.
I see they allow compound units though.

Pairs of simple units can be concatenated with "-per-" to make a compound unit. This suggests that it's only ratios of simple units, not products of two units.

new Intl.NumberFormat('en-US', { useGrouping: true, style: "unit", unit: "foot-per-second" }).format(56)
outputs --> "56 ft/s"

Again, a link from MDN I see this page which suggests this is possible with this type="power2" argument but that's in some XML implementation of this which is not Javascript not totally clear on the relationship between unicode.org and what's implemented in a browser)
Is there some way to get square feet as a the unit?


Q: Awk, Shell Scripting I have a file which has the following form:
#id|firstName|lastName|gender|birthday|creationDate|locationIP|browserUsed
111|Arkas|Sarkas|male|1995-09-11|2010-03-17T13:32:10.447+0000|192.248.2.123|Midori

Every field is separated with "|". I am writing a shell script and my goal is to remove the "-" from the fifth field (birthday), in order to make comparisons as if they were numbers.
For example i want the fifth field to be like |19950911|
The only solution I have reached so far, deletes all the "-" from each line which is not what I want using sed.
i would be extremely grateful if you show me a solution to my problem using awk.

A: If this is a homework writing the complete script will be a disservice.  Some hints: the function you should be using is gsub in awk. The fifth field is $5 and you can set the field separator by -F'|' or in BEGIN block as FS="|"
Also, line numbers are in NR variable, to skip first line for example, you can add a condition NR>1

A: An awk one liner:
awk 'BEGIN { FS="|" } { gsub("-","",$5); print }' infile.txt

A: To keep "|" as output separator, it is better to define OFS value as "|" :
... | awk 'BEGIN { FS="|"; OFS="|"} {gsub("-","",$5); print $0 }'


Q: How can i match the exact text in XML I want to match the exact text "puts" in the (xml file) for a .tmTheme file for sublime text but I've come here as my last resort. I don't really know about regex please help.
i'm trying to match the puts Ruby print keyword. for example:
puts "cat"

output
cat

My main aim is to only highlight the puts keyword as i can't find any other way to highlight its scope. It's for a syntax highlighting package.
the seventh line with the --- <> --- is where i'm struggling with. Any help will be greatly appreciated.
<dict>
    <key>name</key>
    <string>output</string>
    <key>scope</key>
    <string>source.ruby</string>
    <key>match</key>
    --- <string>>p[\'"]?([^\'" >]+)s</string> ---
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#ff0</string>
    </dict>
</dict>


Q: Network operation could not be completed - Alamofire I am using Alamofire in a Swift app I am developing. Recently whenever I try to perform a network call in the simulator iPhone5 8.1 (or any simulator 8.1) I am getting:
Optional(Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x7f9d148ac2c0 {NSErrorFailingURLStringKey=https:[URL REMOVED], NSErrorFailingURLKey=https:[URL REMOVED], _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x7f9d1273f0a0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"})

This use to work fine up until about a day ago. The only things I have changed are the servers are now sitting on Windows/IIS EC2 instances behind a load balancer and the request is no longer a HTTP but it is HTTPS.
I had app transport configured when using HTTP but removed now everything is over HTTPS. I tried putting it back but still nothing.
I have disabled keepalive headers on IIS but I can't seem to get any connection to go through.
I have read through the comments here https://github.com/AFNetworking/AFNetworking/issues/2314 but nothing in that post works.
Help please?!?!


Q: "sequenced before" and "Every evaluation in the calling function" in c++ Every evaluation in the calling function (including other function calls) that is not otherwise specifically sequenced before or after the execution of the body of the called function is indeterminately sequenced with respect to the execution of the called function.
In other words, function executions do not interleave with each other.
what is the meaning of "Every evaluation".
#include <iostream>
using namespace std;
int a = 0;
ing b = 0;
int f(int,int)
{
    cout << "call f, ";
    cout << "a=" << a << ", ";
    cout << "b=" << b << ", ";
    return 1;
}

int g()
{
    cout << "call g, ";
    cout << "a=" << a << ", ";
    cout << "b=" << b << ", ";
    return 1;
}

int main()
{
    f(a++, b++) + g();
    return 0;
}

*

*it menas evaluation of function call expression f(a++, b++), so evaluation of a++, evaluation of b++, and execution of f are all sequenced before or after the execution of g.
In this case, there are two kinds of results. If evaluation of expression f(a++, b++) is sequenced before the execution of g:
call f, a=1, b=1, call g, a=1, b=1,
If execution of g issequenced before evaluation of expression f(a++, b++):
call g, a=0, b=0, call f, a=1, b=1,
2.It means evaluation of a++, evaluation of b++, or execution of f.
So evaluation of a++ may be sequenced before execution of g, evaluation of b++ and execution of f may be sequenced after execution of g.
call g, a=1, b=0, call f, a=1, b=1,

*It means value computation or side effect.

So value computation of a++ may be sequenced before execution of g, side effect of a++, evaluation of b++ and execution of f may be sequenced after execution of g.
call g, a=0, b=0, call f, a=1, b=1,

In this case,
f(a++, b++) + (a = g());
1.value computation of a++
2.execution of g
3.side effect of a++
4.side effect of = (a = 0)
5.evaluation of b++
6.execution of f

call g, a=0, b=0, call f, a=0, b=1,

Which one is right? Or other answer?
I'm not an English speaker, and I'm not very good at English.
I hope you can understand what i say
f(h1(), h2()) + g(h3(), h4())
h1 and h2 are sequenced before f, h3 and h4 are sequenced before g.
Is it possible:

*

*h1

*h4

*h2

*f

*h3

*g

A:
[expr.post.incr]/1 ... The value computation of the ++ expression is sequenced before the modification of the operand object. With respect to an indeterminately-sequenced function call, the operation of postfix
  ++ is a single evaluation. [ Note: Therefore, a function call shall not intervene between the lvalue-to-rvalue conversion and the side effect associated with any single postfix ++ operator. —end note ]...

My reading of this is that the side effects of a++ and b++ must complete before the body of f is executed, and therefore within f it must be that a==1 and b==1. Your examples #2 and #3 are not possible with a conforming implementation.
A call to g is indeterminately sequenced with a call to f, and thus can observe either pre-increment or post-increment values.

A: f(a++, b++) + g();

Compiler can decide the order of execution of f() and g() in the above statement.
These are only 2 possibilities not 3.
Either f() will call first and modifies variables a and b
OR
g() will get call first.


Q: Reverse Indexing in Python? I know that a[end:start:-1] slices a list in a reverse order.
For example
a = range(20)
print a[15:10:-1] # prints [15, ..., 11]
print a[15:0:-1] # prints [15, ..., 1]

but you cannot get to the first element (0 in the example). It seems that -1 is a special value.
print a[15:-1:-1] # prints []

Any ideas?

A: In Python2.x, the simplest solution in terms of number of characters should probably be :
>>> a=range(20)

>>> a[::-1]
[19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

Though i want to point out that if using xrange(), indexing won't work because xrange() gives you an xrange object instead of a list.
>>> a=xrange(20)
>>> a[::-1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sequence index must be integer, not 'slice'

After in Python3.x, range() does what xrange() does in Python2.x but also has an improvement accepting indexing change upon the object.
>>> a = range(20)
>>> a[::-1]
range(19, -1, -1)
>>> b=a[::-1]
>>> for i in b:
...     print (i)
...
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
>>>

the difference between range() and xrange() learned from source: http://pythoncentral.io/how-to-use-pythons-xrange-and-range/
by author: Joey Payne

A: You can assign your variable to None:
>>> a = range(20)
>>> a[15:None:-1]
[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>>>

A: Omit the end index:
print a[15::-1]

A: >>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> print a[:6:-1]
[19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7]
>>> a[7] == a[:6:-1][-1]
True
>>> a[1] == a[:0:-1][-1]
True

So as you can see when subsitute a value in start label :end: it will give you from start to end exclusively a[end].
As you can see in here as well:
>>> a[0:2:]
[0, 1]

-1 is the last value in a:
>>> a[len(a)-1] == a[-1]
True

A: EDIT: begin and end are variables
I never realized this, but a (slightly hacky) solution would be:
>>> a = range(5)
>>> s = 0
>>> e = 3
>>> b = a[s:e]
>>> b.reverse()
>>> print b
[2, 1, 0]

A: If you use negative indexes you can avoid extra assignments, using only your start and end variables:
a = range(20)
start = 20
for end in range(21):
    a[start:-(len(a)+1-end):-1]


Q: How to create a XY chart in Java which reads data from two variables? I have difficulties understanding how to add my data to the chart object. I am simulating a supermarket activity in java program. After the simulation time is up. I have two variables
 time and customers. What should I use if I want the data to be added to an XY chart in java.
Thanks, in advance. I have looked at JFreeChart but it seems overly complicated.

A: JFreeChart is not overcomplicated. You have to try Time Series chart in your case. See here the example of how they use it.
Although they leave behind the scene the main thing, which should create the data source for chart: see line
 final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
I used this TimeSeries charts before, and as I remember you have to create this object and put there series of your values (probably iterating over your own values and inserting them one by one in cycle)


Q: jQuery .fadeIn() setup I have a few elements which I want to $('.hidden_item').fadeIn() when the button is clicked.
So in order to do that I need to first hide them. I tried using
$(document).ready(function(){
    $('.hidden_item').hide();
});

But sometimes page onload sends heartbeat and my elements hidden_elements stay visible for some time. So I would like to hide them with CSS.
What styling I should use to correctly hide them for later $('.hidden_item').fadeIn()?

A: use
.hidden_item{
  display:none;
}


Q: xpdf (pdftotext) with language pack call from different directory I am experimenting with xpdf (pdftotext) on a macOS Terminal. I use one language package (Japanese). Everything works fine if I call the executable like this (from the lib directory):
lib kelly$ ./p2t -enc UTF-8 jp.pdf

and my data structure
files/lib/pdftotext
files/lib/xpdfrc
files/lib/jp.pdf #file to convert
files/options/Enc/jp/ # Here I have the language package files

and the following edited xpdfrc configuration file:
#----- begin Japanese support package (2011-sep-02)
cidToUnicode    Adobe-Japan1    ../options/Enc/jp/Adobe-Japan1.cidToUnicode
unicodeMap  ISO-2022-JP ../options/Enc/jp/ISO-2022-JP.unicodeMap
unicodeMap  EUC-JP      ../options/Enc/jp/EUC-JP.unicodeMap
unicodeMap  Shift-JIS   ../options/Enc/jp/Shift-JIS.unicodeMap
cMapDir     Adobe-Japan1    ../options/Enc/jp/CMap
toUnicodeDir            ../options/Enc/jp/CMap
#----- end Japanese support package

the problem I have is to call 'pdftoext' from a different directory, for example from 'files'. In this case, the files that the configuration files is pointing to are not seen.
files kelly$ ./lib/p2t -enc UTF-8 ./lib/jp.pdf

I get the following error:
Syntax Error: Unknown character collection 'Adobe-Japan1'

And the generated file is garbage.
Any idea on how the configuration file needs to be changed?

A: I was able to solve a similar problem.
I installed pdftotext with a brew cask.
The installation was done with the following command
$ brew cask install pdftotext
$ pdftotext -v
pdftotext version 3.03
Copyright 1996-2011 Glyph & Cog, LLC

and place the xpdfrc/language support packages in the following directory I did.
ls /usr/local/etc/xpdfrc
/usr/local/etc/xpdfrc

I downloaded the Japanese Language Pack from here.
https://www.xpdfreader.com/download.html
$ tree /usr/local/share/xpdf
/usr/local/share/xpdf
└── japanese
    ├── Adobe-Japan1.cidToUnicode
    ├── CMap
    │   ├── 78-EUC-H
    │   ├── 78-EUC-V
    │   ├── 78-H
    │   ├── 78-RKSJ-H
    │   ├── 78-RKSJ-V
    │   ├── 78-V
    │   ├── 78ms-RKSJ-H
    │   ├── 78ms-RKSJ-V
    │   ├── 83pv-RKSJ-H
    │   ├── 90ms-RKSJ-H
    │   ├── 90ms-RKSJ-UCS2
    │   ├── 90ms-RKSJ-V
    │   ├── 90msp-RKSJ-H
    │   ├── 90msp-RKSJ-V
    │   ├── 90pv-RKSJ-H
    │   ├── 90pv-RKSJ-UCS2
    │   ├── 90pv-RKSJ-UCS2C
    │   ├── 90pv-RKSJ-V
    │   ├── Add-H
    │   ├── Add-RKSJ-H
    │   ├── Add-RKSJ-V
    │   ├── Add-V
    │   ├── Adobe-Japan1-0
    │   ├── Adobe-Japan1-1
    │   ├── Adobe-Japan1-2
    │   ├── Adobe-Japan1-3
    │   ├── Adobe-Japan1-4
    │   ├── Adobe-Japan1-5
    │   ├── Adobe-Japan1-6
    │   ├── Adobe-Japan1-UCS2
    │   ├── EUC-H
    │   ├── EUC-V
    │   ├── Ext-H
    │   ├── Ext-RKSJ-H
    │   ├── Ext-RKSJ-V
    │   ├── Ext-V
    │   ├── H
    │   ├── Hankaku
    │   ├── Hiragana
    │   ├── Katakana
    │   ├── NWP-H
    │   ├── NWP-V
    │   ├── RKSJ-H
    │   ├── RKSJ-V
    │   ├── Roman
    │   ├── UniJIS-UCS2-H
    │   ├── UniJIS-UCS2-HW-H
    │   ├── UniJIS-UCS2-HW-V
    │   ├── UniJIS-UCS2-V
    │   ├── UniJIS-UTF16-H
    │   ├── UniJIS-UTF16-V
    │   ├── UniJIS-UTF32-H
    │   ├── UniJIS-UTF32-V
    │   ├── UniJIS-UTF8-H
    │   ├── UniJIS-UTF8-V
    │   ├── UniJIS2004-UTF16-H
    │   ├── UniJIS2004-UTF16-V
    │   ├── UniJIS2004-UTF32-H
    │   ├── UniJIS2004-UTF32-V
    │   ├── UniJIS2004-UTF8-H
    │   ├── UniJIS2004-UTF8-V
    │   ├── UniJISPro-UCS2-HW-V
    │   ├── UniJISPro-UCS2-V
    │   ├── UniJISPro-UTF8-V
    │   ├── UniJISX0213-UTF32-H
    │   ├── UniJISX0213-UTF32-V
    │   ├── UniJISX02132004-UTF32-H
    │   ├── UniJISX02132004-UTF32-V
    │   ├── V
    │   └── WP-Symbol
    ├── EUC-JP.unicodeMap
    ├── ISO-2022-JP.unicodeMap
    ├── README
    ├── Shift-JIS.unicodeMap
    └── add-to-xpdfrc

2 directories, 76 files

The contents of xpdfrc are as follows
$ cat /usr/local/etc/xpdfrc
cidToUnicode    Adobe-Japan1    /usr/local/share/xpdf/japanese/Adobe-Japan1.cidToUnicode
unicodeMap  ISO-2022-JP /usr/local/share/xpdf/japanese/ISO-2022-JP.unicodeMap
unicodeMap  EUC-JP      /usr/local/share/xpdf/japanese/EUC-JP.unicodeMap
unicodeMap  Shift-JIS   /usr/local/share/xpdf/japanese/Shift-JIS.unicodeMap
cMapDir     Adobe-Japan1    /usr/local/share/xpdf/japanese/CMap
toUnicodeDir            /usr/local/share/xpdf/japanese/CMap


Q: Scrapy Response Changes After Visiting Page in Web Browser Below is a spider I wrote to crawl an RSS feed and extract the first link and image title, and save them to a text file:
import scrapy

class artSpider(scrapy.Spider):
    name = "metart"

    start_urls = ['https://www.metmuseum.org/art/artwork-of-the-day?rss=1']

    def parse(self, response):
        title = response.xpath('//item/title/text()').extract_first().replace(" ", "_")
        description = response.xpath('//item/description/text()').extract_first()

        lnkstart = description.find("https://image")
        lnkcut1 = description.find("web-highlight")
        lnkcut2 = lnkcut1 + 13
        lnkend = description.find(".jpg") + 4

        link = description[lnkstart:lnkcut1] + "original" + description[lnkcut2:lnkend]

        ttlstart = description.find("who=") + 4
        ttlend = description.find("&rss=1")

        filename = "/path/to/save/folder/" + description[ttlstart:ttlend].replace("+", "_") + "-" + title + ".jpg"

        print(filename)
        print(link)

        filename_file = open('filename_metart.txt', 'w')
        filename_file.write(filename)
        filename_file.close
        link_file = open('link_metart.txt', 'w')
        link_file.write(link)
        link_file.close

It goes over the Met Museum "Artwork of the Day" RSS feed and finds the newest artwork. Then parses the title and the link to the original (the link in the RSS feed is for a thumbnail) and saves them to individual text files. The title is used to generate a filename when downloading the image.
I know the parse function is a mess and that the way I am saving the links and filenames is ugly. I am just starting out with Scrapy and just wanted to get the spider working because it is only a part of the broader project I am working on.
The project itself draws from artwork/image/photo of the day feeds and websites, downloads the images and sets them as a desktop background slideshow.
My issue is that when I set the spider off it comes back with a response of "NoneType". BUT if I go to the RSS feed in a browser (https://metmuseum.org/art/artwork-of-the-day?rss=1) AND THEN run the spider it works correctly.
Process that fails

*

*Call scrapy crawl metart

*

*Output shows that the variable title has the type NoneType

*Repeating step 1 results in the same output

Process that works

*

*Open https://metmuseum.org/art/artwork-of-the-day?rss=1 in a web browser

*Call scrapy crawl metart

*

*Successfully saves the link and filename to the relevant text files

Some troubleshooting I have already done
I have used a Scrapy shell to replicate exactly the process that the spider goes through and this worked fine. I went through each step that the spider goes through starting with:
fetch("https://metmuseum.org/art/artwork-of-the-day?rss=1")

Then typing in each line of the parse function. This works fine and results in the correct link and filename being saved WITHOUT having to open the URL in a web browser first.
Just for completeness below is my Scrapy project settings.py file:
BOT_NAME = 'wallpaper_scraper'

SPIDER_MODULES = ['wallpaper_scraper.spiders']
NEWSPIDER_MODULE = 'wallpaper_scraper.spiders'

# Crawl responsibly by identifying yourself (and your website) on the user-agent
USER_AGENT = 'cchowgule for a wallpaper slideshow'

# Obey robots.txt rules
ROBOTSTXT_OBEY = True

I am very confused as to how the act of opening the URL in a web browser could possibly affect the response of the spider.
Any help cleaning up my parse function would also be lovely.
Thanks
Update
At 0535 UTC I ran scrapy crawl metart and got the following response:
2018-06-23 11:02:54 [scrapy.utils.log] INFO: Scrapy 1.5.0 started (bot: wallpaper_scraper)
2018-06-23 11:02:54 [scrapy.utils.log] INFO: Versions: lxml 4.2.1.0, libxml2 2.9.8, cssselect 1.0.3, parsel 1.4.0, w3lib 1.19.0, Twisted 17.9.0, Python 2.7.15 (default, May  1 2018, 05:55:50) - [GCC 7.3.0], pyOpenSSL 17.5.0 (OpenSSL 1.1.0h  27 Mar 2018), cryptography 2.2.2, Platform Linux-4.16.0-2-amd64-x86_64-with-debian-buster-sid
2018-06-23 11:02:54 [scrapy.crawler] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'wallpaper_scraper.spiders', 'SPIDER_MODULES': ['wallpaper_scraper.spiders'], 'ROBOTSTXT_OBEY': True, 'USER_AGENT': 'cchowgule for a wallpaper slideshow', 'BOT_NAME': 'wallpaper_scraper'}
2018-06-23 11:02:54 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
 'scrapy.extensions.logstats.LogStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.corestats.CoreStats']
2018-06-23 11:02:54 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware',
 'scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
 'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
 'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
 'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
 'scrapy.downloadermiddlewares.retry.RetryMiddleware',
 'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
 'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
 'scrapy.downloadermiddlewares.stats.DownloaderStats']
2018-06-23 11:02:54 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
 'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
 'scrapy.spidermiddlewares.referer.RefererMiddleware',
 'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
 'scrapy.spidermiddlewares.depth.DepthMiddleware']
2018-06-23 11:02:54 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2018-06-23 11:02:54 [scrapy.core.engine] INFO: Spider opened
2018-06-23 11:02:54 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2018-06-23 11:02:54 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2018-06-23 11:02:56 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.metmuseum.org/robots.txt> (referer: None)
2018-06-23 11:02:56 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.metmuseum.org/art/artwork-of-the-day?rss=1> (referer: None)
2018-06-23 11:02:56 [scrapy.core.scraper] ERROR: Spider error processing <GET https://www.metmuseum.org/art/artwork-of-the-day?rss=1> (referer: None)
Traceback (most recent call last):
  File "/home/cchowgule/.local/lib/python2.7/site-packages/twisted/internet/defer.py", line 653, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
  File "/home/cchowgule/WD/pyenvscrapy/wallpaper_scraper/wallpaper_scraper/spiders/metart.py", line 9, in parse
    title = response.xpath('//item/title/text()').extract_first().replace(" ", "_")
AttributeError: 'NoneType' object has no attribute 'replace'
2018-06-23 11:02:57 [scrapy.core.engine] INFO: Closing spider (finished)
2018-06-23 11:02:57 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 646,
 'downloader/request_count': 2,
 'downloader/request_method_count/GET': 2,
 'downloader/response_bytes': 1725,
 'downloader/response_count': 2,
 'downloader/response_status_count/200': 2,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2018, 6, 23, 5, 32, 57, 65104),
 'log_count/DEBUG': 3,
 'log_count/ERROR': 1,
 'log_count/INFO': 7,
 'memusage/max': 52793344,
 'memusage/startup': 52793344,
 'response_received_count': 2,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'spider_exceptions/AttributeError': 1,
 'start_time': datetime.datetime(2018, 6, 23, 5, 32, 54, 464466)}
2018-06-23 11:02:57 [scrapy.core.engine] INFO: Spider closed (finished)

I ran scrapy crawl metart 5 times with the same result.
Then I opened a browser, went to https://metmuseum.org/art/artwork-of-the-day?rss=1 and ran scrapy crawl metart again. This time it worked correctly...... I just don't get it.


Q: How to create a floating widget hovering other widgets on Windows? Assume we have a wxWebView control in both window hierarchy and sizer hierarchy. How do we create a static text "loading" hovering above the wxWebView on Windows? Thanks.
It's straightforward on Linux. Create a wxStaticText of which the parent/owner is the same as the wxWebView and that's all. Unfortunately, it won't work on Windows. The wxStaticText is invisible because it is covered by the wxWebView. I've tried many ways, including calling their method Lower and Raise to adjust their z-orders, but in vain.
I also tried putting the text into a wxFrame and use samples/shaped/ as an example, but on the second thought, the new top-level frame may cover the GUI of other processes. So it isn't a good design.
Any suggestion? Thanks.

A: wxWidgets doesn't support overlapping child controls, so you would need to use a different top level window for your floating control, typically a wxPopupWindow -- then you could either draw your text in it or make wxStaticText its child.


Q: Include files in sdist but not wheel I have a Python C extension that contains header files in the include folder.
I am currently trying to build wheels and a source distribution.
Because wheels are pre-compiled, they don't need to contain header files but the sdist does.
According to the Python docs, the following files are included in a sdist:

*

*all Python source files implied by the py_modules and packages options

*all C source files mentioned in the ext_modules or libraries options

*scripts identified by the scripts option See Installing Scripts.

*anything that looks like a test script: test/test*.py (currently, the Distutils don’t do anything with test scripts except include them in source distributions, but in the future there will be a standard for testing Python module distributions)

*Any of the standard README files (README, README.txt, or README.rst), setup.py (or whatever you called your setup script), and setup.cfg.

*all files that matches the package_data metadata. See Installing Package Data.

*all files that matches the data_files metadata. See Installing Additional Files.

These files are also included in the wheels as well.
How can I add the header files to a sdist but not a wheel?


Q: Which class provides implementation for RequestDispatcher forward() and include() method Does  RequestDispatcher object exits as it is an interface and as for i know we cant create an object to interface.
So what is happening in following code
RequestDispatcher requestDispatcher = request.getRequestDispatcher('somePage');

Are we creating object to RequestDispatcher or to subclass that implements RequestDispatcher.
Thanks in advance.

A: RequestDispatcher is an interface and we can't create an object obviously with that. So, it is an object of the class that implements RequestDispatcher that you get when the calling getRequestDispatcher().
You need to have the source code of the Servlet implementation(this depends on the container that you are using) to see the class that is providing the implementation.

A: You are right, RequestDispatcher is an interface you we can not create an object of this.
Now see:
request.getRequestDispatcher('somePage');  This method returns a class which implements RequestDispatcher and that class is totally depends upon the server which you are using.
For Ex. In case of Glass Fish server, it returns org.apache.catalina.core.ApplicationDispatcher object and it has already told by @Pshemo.


Q: c# ValueInjecter : Mapping the whole object Graph I just started using ValueInjecter for my Entity Mappings(DTO <-> Entity).
Heres my DTO :
public class IncidentDTO
{
    int ID { get; set; }
    string Name { get; set; }
    AgencyDTO agencyDTO { get; set; }
}

public class AgencyDTO
{
    int ID { get; set; }
    string Name { get; set; }
    List<IncidentTypeDTO> incidentTypeDTOList { get; set; }
}

public class IncidentTypeDTO
{
    int ID { get; set; }
    string TypeName { get; set; }
}

Heres my NHibernate Proxy classes :
 public class Incident
{
    int ID { get; set; }
    string Name { get; set; }
    Agency agency { get; set; }
}

public class Agency
{
    int ID { get; set; }
    string Name { get; set; }
}

public class IncidentType
{
    int ID { get; set; }
    string TypeName { get; set; }
}

public class AgencyIncidentType
{
    int ID { get; set; }
    Agency agency { get; set; }
    IncidentType incidentType { get; set; }
}

Now, I need to query IncidentDTO from Repository.
Repository query Incident & AgencyIncidentType tables from database and map Incident -> IncidentDTO using ValueInjecter and return IncidentDTO.
What is the best possible way to do the above mapping using ValueInjecter??
Thanks,
Prateek

A: If you want to map Incident to IncidentDTO while retaining and mapping the Agency object in the agency property (to an AgencyDTO) of an Incident instance I'd suggest renaming the agencyDTO property to agency in your IncidentDTO and then use a tweak to the CloneInjection sample from the Value Injector documentation as described here: omu.valueinjecter deep clone unlike types


Q: /bin/bash - Alfred 3 workflow does not detect php So I downloaded this plugin https://github.com/vmitchell85/alfred-vuejs-docs and I got the Powerpack. Here is me trying to execute the workflow but pressing enter at this point does nothing:

After I press space and enter "vue events", I get in the debug:
[2018-09-02 16:56:33][ERROR: input.scriptfilter] Code 127: /bin/bash: php: command not found
Which is strange because I fire up my Terminal.app (Which uses bash) and I do php -v which gives me: PHP 7.2.8 (cli) (built: Jul 19 2018 12:15:24) ( NTS ). Same thing on my zsh profile.
What do I do?

A: Look at the image you posted. There's a Script Filter object on the Alfred Editor. You just have to double-click on it and replace php vuejs.php "{query}" with /usr/local/bin/php vuejs.php "{query}".


Q: How to focus to a block when cursor at start of line with Slate JS? I am using Slate JS.
I have some code, which should focus a given block (move the cursor there).
The use case here is: press / to open a modal, then when the modal closes, we want to refocus to the block we were at before.
To do this, we use Transforms.select().
Something like this:
getCurrentBlock(editor: Editor) {
  const { selection } = editor;

  if (!selection) {
    return { block: null, anchor: null, focus: null };
  }

  const { anchor, focus } = selection;
  const { path } = anchor
  const block = editor.children[path[0]] as Block;
  return { block, anchor, focus };
}

const focusBlock = (editor, path) => {
  ReactEditor.focus(editor);

  Transforms.select(editor, {
    anchor: { path: [path[0], 0], offset: 0 },
    focus: { path: [path[0], 0], offset: 0 },
  });
}

It generally works in all cases like this:
const { block, anchor, focus} = getCurrentBlock(editor)
const { path } = anchor
focusBlock(editor, path)

However, it does not work when the position of the cursor is at the start of a line.
i.e. when offset = 0.
In this case, the focus moves the cursor to the very top of the page.
Why might this be happening, and how can I make it focus the block in question, even when the cursor is at the start of the line?

A: Solved this by doing:
refocusEditor({ editor }: { editor: Editor }) {
   const block = Editor.above(editor, {
    match: (n) => Editor.isBlock(editor, n),
  });

  const path = block ? block[1] : [];
  ReactEditor.focus(editor);
  // @ts-ignore
  Transforms.setSelection(editor, path);
}


Q: QObject::connect: no such signal. Also, Qtimer not calling I have a class, myClass:
class myClass : public QObject
{
    Q_OBJECT
public:
    QQuickWidget* widget;
    QString mystring;
    myClass (QQuickWidget* quickWidget, QString string);
    void myfunction();

public slots:
    void slot();
signals:
    void clicked();
};

myClass::myClass(QQuickWidget* quickWidget, QString string) :
    widget(quickWidget), mystring(string)
{
    QTimer::singleShot(60000, this, SLOT(slot()));
    myfunction();
}

void myClass::slot()
{

}

void myClass::myfunction()
{
    widget->setVisible(true);
    widget->setSource(QUrl("qrc:/qmlsource.qml"));
    connect(widget, SIGNAL(clicked()), this, SLOT(slot()));
}

What I want to do is to call the slot() function 60 seconds after I create a myClass object. That doesn't happen. Also, at the connect line I get
QObject::connect: No such signal QQuickWidget::clicked()

message.
I would appreciate if someone could help me.

A: So, I think you have a few issues here.
1. QWidget
The big one is that QWidget (which QQUickWidget inherits from) does not have a signal called "clicked", so the message QObject::connect: No such signal QQuickWidget::clicked() is quite right ;)
What you need to do is create your own object that inherits from QQuickWidget and then re-implement/overload the function void QWidget::mousePressEvent(QMouseEvent * event) and/or void QWidget::mouseReleaseEvent(QMouseEvent * event)
These are the functions that are called in the widget that you can then emit your signal. Which means you also need to add a new signal into you your widget. So your new class header may look a bit like (just including the main elements):
class MyQQuickWidget: public QQuickWidget
{
    Q_OBJECT

public:
    MyQQuickWidget(QWidget *parent = 0);

signals:
    void clicked();

protected:
    void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;

};

And then in your implementation:
void MyQQuickWidget::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        emit clicked();
    }
}

Then when you connect your MyQQuickWidget signal clicked() to MyClass slot slot() it will connect ok.
2. QTimer
It looks like your timer should fire... but there appears to be no debug in the slot slot() so how would you know if this is working or not?


Q: How to properly get the int for totalEntries in MySQL database using PHP? I'm using PHP and a MySQL database to build a website.
However, I find PHP quite horrible compared to other languages I have learnt previously. Largely because I seem to find a lot of instructions online which are over 5 years old and they just don't work.
For example the accepted answer here: select count(*) from table of mysql in php
I have this code so far, but it gives me error (undefined index $recordCount = $row['totalEntries'];).
// create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// check connection
if ($conn->connect_error) {
die("connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM games ORDER BY id DESC LIMIT $startRow, $rowsPerPage";
$result = $conn->query($sql);

$sql = "SELECT COUNT(*) as totalEntries FROM games";
$results = $conn->query($sql);
$row = $result->fetch_assoc();
$recordCount = $row['totalEntries'];
echo "
 record count = " . $recordCount;

$totalPages = ceil($recordCount / $rowsPerPage);
$pagination = "
";

for ($i = 0; $i <= $totalPages; $i++) {
 $pagination .= "" . $i . "";
echo 'wtf!';
}

$pagination .= "
";
echo '
 pagination = ' . $pagination;

I also tried:
  $recordCount = Count($row);

and
   $recordCount = Count($result->num_rows);

and many other parameters passed into Count but they always return either 1 or 7(which is the number of COLUMNS)
I guess I find PHP so hard to learn because I don't have  a good IDE for it and am using Notepad++. Can anyone tell me how we get the Count of all entries in the table after I have done the SELECT statement as in the above code?

A:     $conn = new \mysqli('127.0.0.1', 'dev', 'SoMuchDev', 'test', '3306');
    $result = $conn->query('select * from test');
    while ($row = $result->fetch_assoc()) {
        $res[] = $row;
    }
    $res['total'] = $result->num_rows;
    echo "
";
    var_export($res);die();

http://php.net/manual/en/class.mysqli-result.php
As for editors, PhpStorm is widely used but afaik there's only a 30 day trial use. You could also give notepad ++ a try, I think it has some php plugins for autocomplete and what not.