问:
Linux: Screen desktop video capture over network, and VNC framerate
Sorry for the wall of text - TL;DR:

What is the framerate of VNC connection (in frames/sec) - or rather, who determines it: client or server?

Any other suggestions for desktop screen capture - but "correctly timecoded"/ with unjittered framerate (with a stable period); and with possibility to obtain it as uncompressed (or lossless) image sequence?

Briefly - I have a typical problem that I am faced with: I sometimes develop hardware, and want to record a video that shows both commands entered on the PC ('desktop capture'), and responses of the hardware ('live video'). A chunk of an intro follows, before I get to the specific detail(s).

Intro/Context

My strategy, for now, is to use a video camera to record the process of hardware testing (as 'live' video) - and do a desktop capture at the same time. The video camera produces a 29.97 (30) FPS MPEG-2 .AVI video; and I want to get the desktop capture as an image sequence of PNGs at the same frame rate as the video. The idea, then, would be: if the frame rate of the two videos is the same; then I could simply

align the time of start of the desktop capture, with the matching point in the 'live' video

Set up a picture-in-picture, where a scaled down version of the desktop capture is put - as overlay - on top of the 'live' video

(where a portion of the screen on the 'live' video, serves as a visual sync source with the 'desktop capture' overlay)

Export a 'final' combined video, compressed appropriately for the Internet

In principle, I guess one could use a command line tool like ffmpeg for this process; however I would prefer to use a GUI for finding the alignment start point for the two videos.

Eventually, what I also want to achieve, is to preserve maximum quality when exporting the 'final' video: the 'live' video is already compressed when out of the camera, which means additional degradation when it passes through the Theora .ogv codec - which is why I'd like to keep the original videos, and use something like a command line to generate a 'final' video anew, if a different compression/resolution is required. This is also why I like to have the 'desktop capture' video as a PNG sequence (although I guess any uncompressed format would do): I take measures to 'adjust' the desktop, so there aren't many gradients, and lossless encoding (i.e. PNG) would be appropriate.

Desktop capture options

Well, there are many troubles in this process under Ubuntu Lucid, which I currently use (and you can read about some of my ordeals in 10.04: Video overlay/composite editing with Theora ogv - Ubuntu Forums). However, one of the crucial problems is the assumption, that the frame rate of the two incoming videos is equal - in reality, usually the desktop capture is of a lower framerate; and even worse, very often frames are out of sync.

This, then, requires the hassle of sitting in front of a video editor, and manually cutting and editing less-than-a-second clips on frame level - requiring hours of work for what will be in the end a 5 minute video. On the other hand, if the two videos ('live' and 'capture') did have the same framerate and sync: in principle, you wouldn't need more than a couple of minutes for finding the start sync point in a video editor - and the rest of the 'merged' video processing could be handled by a single command line. Which is why, in this post, I would like to focus on the desktop capture part.

As far as I can see, there are only few viable (as opposed to 5 Ways to Screencast Your Linux Desktop) alternatives for desktop capture in Linux / Ubuntu (note, I typically use a laptop as target for desktop capturing):

Have your target PC (laptop) clone the desktop on its VGA output; use a VGA-to-composite or VGA-to-S-video hardware to obtain a video signal from VGA; use video capture card on a different PC to grab video

Use recordMyDesktop on the target PC

Set up a VNC server (vino on Ubuntu; or vncserver) on the target PC to be captured; use VNC capture software (such as vncrec) on a different PC to grab/record the VNC stream (which can, subsequently, be converted to video).

Use ffmpeg with x11grab option

*(use some tool on the target PC, that would do a DMA transfer of a desktop image frame directly - from the graphics card frame buffer memory, to the network adapter memory)

Please note that the usefulness of the above approaches are limited by my context of use: the target PC that I want to capture, typically runs software (utilizing the tested hardware) that moves around massive ammounts of data; best you could say about describing such a system is "barely stable" :) I'd guess this is similar to problems gamers face, when wanting to obtain a video capture of a demanding game. And as soon as I start using something like recordMyDesktop, which also uses quite a bit of resources and wants to capture on the local hard disk - I immediately get severe kernel crashes (often with no vmcore generated).

So, in my context, I typically do assume involvement of a second computer - to run the capture and recording of the 'target' PC desktop. Other than that,  the pros and cons I can see so far with the above options, are included below.

(Desktop preparation)

For all of the methods discussed below, I tend to "prepare" the desktop beforehand:

Remove desktop backgrounds and icons

Set the resolution down to 800x600 via System/Preferences/Monitors (gnome-desktop-properties)

Change color depth down to 16 bpp (using xdpyinfo | grep "of root" to check)

... in order to minimize the load on desktop capture software. Note that changing color depth on Ubuntu requires changes to xorg.conf; however, "No xorg.conf (is) found in /etc/X11 (Ubuntu 10.04)" - so you may need to run sudo Xorg -configure first.

In order to keep graphics resource use low, also I usually had compiz disabled - or rather, I'd have 'System/Preferences/Appearance/Visual Effects' set to "None". However, after I tried enabling compiz by setting 'Visual Effects' to "Normal" (which doesn't get saved), I can notice windows on the LCD screen are redrawn much faster; so I keep it like this, also for desktop capture. I find this a bit strange: how could more effects cause a faster screen refresh? It doesn't look like it's due to a proprietary driver (the card is "Intel Corporation N10 Family Integrated Graphics Controller", and no proprietary driver option is given by Ubuntu upon switch to compiz) - although, it could be that all the blurring and effects just cheat my eyes :) ).

Cloning VGA

Well, this is the most expencive option (as it requires additional purchase of not just one, but two pieces of hardware: VGA converter, and video capture card); and applicable mostly to laptops (which have both a screen + additional VGA output - for desktops one may also have to invest in an additional graphics card, or a VGA cloning hardware).

However, it is also the only option that requires no additional software of the target PC whatsoever (and thus uses 0% processing power of the target CPU) - AND also the only one that will give a video with a true, unjittered framerate of 30 fps (as it is performed by separate hardware - although, with the assumption that clock domains misalignment, present between individual hardware pieces, is negligible).

Actually, as I already own something like a capture card, I have already invested in a VGA converter - in expectation that it will eventually allow me to produce final "merged" videos with only 5 mins of looking for alignment point, and a single command line; but I am yet to see whether this process will work as intended. I'm also wandering how possible it will be to capture desktop as  uncompressed video @ 800x600, 30 fps.

recordMyDesktop

Well, if you run recordMyDesktop without any arguments - it starts first with capturing (what looks like) raw image data, in a folder like /tmp/rMD-session-7247; and after you press Ctrl-C to interrupt it, it will encode this raw image data into an .ogv. Obviously, grabbing large image data on the same hard disk as my test software (which also moves large ammounts of data), is usually a cause for an instacrash :)

Hence, what I tried doing is to setup Samba to share a drive on the network; then on the target PC, I'd connect to this drive - and instruct recordMyDesktop to use this network drive (via gvfs) as its temporary files location:

```<code>recordmydesktop --workdir /home/user/.gvfs/test\ on\ 192.168.1.100/capture/ --no-sound --quick-subsampling --fps 30 --overwrite -o capture.ogv
</code>```

Note that, while this command will use the network location for temporary files (and thus makes it possible for recordMyDesktop to run in parallel with my software) - as soon as you hit Ctrl-C, it will start encoding and saving capture.ogv directly on the local hard drive of the target (though, at that point, I don't really care :) )

First of my nags with recordMyDesktop is that you cannot instruct it to keep the temporary files, and avoid encoding them, on end: you can use Ctrl+Alt+p for pause - or you can hit Ctrl-C quickly after the first one, to cause it to crash; which will then leave the temporary files (if you don't hit Ctrl-C quickly enough the second time, the program will "Cleanning up cache..."). You can then run, say:

```<code>recordmydesktop --rescue /home/user/.gvfs/test\ on\ 192.168.1.100/capture/rMD-session-7247/
</code>```

... in order to convert the raw temporary data. However, more often than not, recordMyDesktop will itself segfault in the midst of performing this "rescue". Although, the reason why I want to keep the temp files, is to have the uncompressed source for the picture-in-picture montage. Note that the "--on-the-fly-encoding" will avoid using temp files altogether - at the expence of using more CPU processing power (which, for me, again is cause for crashes.)

Then, there is the framerate - obviously, you can set requested framerate using the '--fps N' option; however, that is no guarantee that you will actually obtain that framerate; for instance, I'd get:

```<code>recordmydesktop --fps 25
...
Saved 2983 frames in a total of 6023 requests
...
</code>```

... for a capture with my test software running; which means that the actually achieved rate is more like 25*2983/6032 = 12.3632 fps!

Obviously, frames are dropped - and mostly that shows as video playback is too fast. However, if I lower the requested fps to 12 - then according to saved/total reports, I achieve something like 11 fps; and in this case, video playback doesn't look 'sped up'.  And I still haven't tried aligning such a capture with a live video - so I have no idea if those frames that actually have been saved, also have an accurate timestamp.

VNC capture

The VNC capture, for me, consists of running a VNC server on the 'target' PC, and running vncrec (twibright edition) on the 'recorder' PC. As VNC server, I use vino, which is "System/Preferences/Remote Desktop (Preferences)". And apparently, even if vino configuration may not be the easiest thing to manage, vino as a server seems not too taxing to the 'target' PC; as I haven't experienced crashes when it runs in parallel with my test software.

On the other hand, when vncrec is capturing on the 'recorder' PC, it also raises a window showing you the 'target' desktop as it is seen in 'realtime'; when there are large updates (i.e. whole windows moving) on the 'target' - one can, quite visibly, see problems with the update/refresh rate on the 'recorder'. But, for only small updates (i.e. just a cursor moving on a static background), things seem OK.

This makes me wonder about one of my primary questions with this post - what is it, that sets the framerate in a VNC connection?

I haven't found a clear answer to this, but from bits and pieces of info (see refs below), I gather that:

The VNC server simply sends changes (screen changes + clicks etc) as fast as it can, when it receives them ; limited by the max network bandwidth that is available to the server

The VNC client receives those change events delayed and jittered by the network connection, and attempts to reconstruct the desktop "video" stream, again as fast as it can

... which means, one cannot state anything in terms of a stable, periodic frame rate (as in video).

As far as vncrec as a client goes, the end videos I get usually are declared as 10 fps, although frames can be rather displaced/jittered (which then requires the cutting in video editors). Note that the vncrec-twibright/README states: "The sample rate of the movie is 10 by default or overriden by VNCREC_MOVIE_FRAMERATE environment variable, or 10 if not specified."; however, the manpage also states "VNCREC_MOVIE_FRAMERATE - Specifies frame rate of the output movie. Has an effect only in -movie mode. Defaults to 10. Try 24 when your transcoder vomits from 10.". And if one looks into "vncrec/sockets.c" source, one can see:

```<code>void print_movie_frames_up_to_time(struct timeval tv)
{
  static double framerate;
  ....
  memcpy(out, bufoutptr, buffered);
  if (appData.record)
    {
      writeLogHeader (); /* Writes the timestamp */
      fwrite (bufoutptr, 1, buffered, vncLog);
    }
</code>```

... which shows that some timestamps are written - but whether those timestamps originate from the "original" 'target' PC, or the 'recorder' one, I cannot tell.
EDIT: thanks to the answer by @kanaka, I checked through vncrec/sockets.c again, and can see that it is the writeLogHeader function itself calling gettimeofday; so the timestamps it writes are local - that is, they originate from the 'recorder' PC (and hence, these timestamps do not accurately describe when the frames originated on the 'target' PC).

In any case, it still seems to me, that the server sends - and vncrec as client receives - whenever; and it is only in the process of encoding a video file from the raw capture afterwards, that some form of a frame rate is set/interpolated.

I'd also like to state that on my 'target' laptop, the wired network connection is broken; so the wireless is my only option to get access to the router and the local network - at far lower speed than the 100MB/s that the router could handle from wired connections. However, if the jitter in captured frames is caused by wrong timestamps due to load on the 'target' PC, I don't think good network bandwidth will help too much.

Finally, as far as VNC goes, there could be other alternatives to try - such as VNCast server (promising, but requires some time to build from source, and is in "early experimental version"); or MultiVNC (although, it just seems like a client/viewer, without options for recording).

ffmpeg with x11grab

Haven't played with this much, but, I've tried it in connection with netcat; this:

```<code># 'target'
ffmpeg -f x11grab -b 8000k -r 30 -s 800x600 -i :0.0 -f rawvideo - | nc 192.168.1.100 5678
# 'recorder'
nc -l 0.0.0.0 5678 > raw.video  #
</code>```

... does capture a file, but ffplay cannot read the captured file properly; while:

```<code># 'target'
ffmpeg -f x11grab -b 500k -r 30 -s 800x600 -i :0.0 -f yuv4mpegpipe -pix_fmt yuv444p - | nc 192.168.1.100 5678
# 'recorder'
nc -l 0.0.0.0 5678 | ffmpeg -i - /path/to/samplimg%03d.png
</code>```

does produce .png images - but with compression artifacts (result of the compression involved with yuv4mpegpipe, I guess).

Thus, I'm not liking ffmpeg+x11grab too much currently - but maybe I simply don't know how to set it up for my needs.

*( graphics card -> DMA -> network )

I am, admittedly, not sure something like this exists - in fact, I would wager it doesn't :) And I'm no expert here, but I speculate:

if DMA memory transfer can be initiated from the graphics card (or its buffer that keeps the current desktop bitmap) as source, and the network adapter as destination - then in principle, it should be possible to obtain an uncompressed desktop capture with a correct (and decent) framerate. The point in using DMA transfer would be, of course, to relieve the processor from the task of copying the desktop image to the network interface (and thus, reduce the influence the capturing software can have on the processes running on the 'target' PC - especially those dealing with RAM or hard-disk).

A suggestion like this, of course, assumes that: there are massive ammounts of network bandwidth (for 800x600, 30 fps at least 800*600*3*30 = 43200000 bps = 42 MiB/s, which should be OK for local 100 MB/s networks); plenty of hard disk on the other PC that does the 'recording' - and finally, software that can afterwards read that raw data, and generate image sequences or videos based on it :)

The bandwidth and hard disk demands I could live with - as long as there is guarantee both for a stable framerate and uncompressed data; which is why I'd love to hear if something like this already exists.

-- -- -- -- --

Well, I guess that was it - as brief as I could put it :) Any suggestions for tools - or process(es), that can result with a desktop capture

in uncompressed format (ultimately convertible to uncompressed/lossless PNG image sequence), and

with a "correctly timecoded", stable framerate

..., that will ultimately lend itself to 'easy', single command-line processing for generating 'picture-in-picture' overlay videos - will be greatly appreciated!

Thanks in advance for any comments,

Cheers!

References

Experiences Producing a Screencast on Linux for CryptoTE - idlebox.net

The VideoLAN Forums • View topic - VNC Client input support (like screen://)

VNCServer throttles user inpt for slow client - Kyprianou, Mark - com.realvnc.vnc-list - MarkMail

Linux FAQ - X Windows: How do I Display and Control a Remote Desktop using VNC

How much bandwidth does VNC require? RealVNC - Frequently asked questions

x11vnc: a VNC server for real X displays

HowtoRecordVNC (an X11 session) - Debian Wiki

Alternative To gtk-RecordMyDesktop in Ubuntu

(Ffmpeg-user) How do I use pipes in ffmpeg

(ffmpeg-devel) (PATCH) Fix segfault in x11grab when drawing Cursor on Xservers that don't support the XFixes extension

答:
You should get a badge for such a long well though out question. ;-)

In answer to your primary question, VNC uses the RFB protocol which is a remote frame buffer protocol (thus the acronym) not a streaming video protocol. The VNC client sends a FrameBufferUpdateRequest message to the server which contains a viewport region that the client is interested in and an incremental flag. If the incremental flag is not set then the server will respond with a FrameBufferUpdate message that contains the content of the region requested. If the incremental flag is set then the server may respond with a FrameBufferUpdate message that contains whatever parts of the region requested that have changed since the last time the client was sent that region.

The definition of how requests and updates interact is not crisply defined. The server won't necessarily respond to every request with an update if nothing has changed. If the server has multiple requests queued from the client it is also allowed to send a single update in response. In addition, the client really needs to be able to respond to an asynchronous update message from the server (not in response to a request) otherwise the client will fall out of sync (because RFB is not a framed protocol).

Often clients are simply implemented to send incremental update requests for the entire frame buffer viewport at a periodic interval and handle any server update messages as they arrive (i.e. no attempt is made to tie requests and updates together).

Here is a description of FrameBufferUpdateRequest messages.

Body:
Sorry for the wall of text - TL;DR:

What is the framerate of VNC connection (in frames/sec) - or rather, who determines it: client or server?

Any other suggestions for desktop screen capture - but "correctly timecoded"/ with unjittered framerate (with a stable period); and with possibility to obtain it as uncompressed (or lossless) image sequence?

Briefly - I have a typical problem that I am faced with: I sometimes develop hardware, and want to record a video that shows both commands entered on the PC ('desktop capture'), and responses of the hardware ('live video'). A chunk of an intro follows, before I get to the specific detail(s).

Intro/Context

My strategy, for now, is to use a video camera to record the process of hardware testing (as 'live' video) - and do a desktop capture at the same time. The video camera produces a 29.97 (30) FPS MPEG-2 .AVI video; and I want to get the desktop capture as an image sequence of PNGs at the same frame rate as the video. The idea, then, would be: if the frame rate of the two videos is the same; then I could simply

align the time of start of the desktop capture, with the matching point in the 'live' video

Set up a picture-in-picture, where a scaled down version of the desktop capture is put - as overlay - on top of the 'live' video

(where a portion of the screen on the 'live' video, serves as a visual sync source with the 'desktop capture' overlay)

Export a 'final' combined video, compressed appropriately for the Internet

In principle, I guess one could use a command line tool like ffmpeg for this process; however I would prefer to use a GUI for finding the alignment start point for the two videos.

Eventually, what I also want to achieve, is to preserve maximum quality when exporting the 'final' video: the 'live' video is already compressed when out of the camera, which means additional degradation when it passes through the Theora .ogv codec - which is why I'd like to keep the original videos, and use something like a command line to generate a 'final' video anew, if a different compression/resolution is required. This is also why I like to have the 'desktop capture' video as a PNG sequence (although I guess any uncompressed format would do): I take measures to 'adjust' the desktop, so there aren't many gradients, and lossless encoding (i.e. PNG) would be appropriate.

Desktop capture options

Well, there are many troubles in this process under Ubuntu Lucid, which I currently use (and you can read about some of my ordeals in 10.04: Video overlay/composite editing with Theora ogv - Ubuntu Forums). However, one of the crucial problems is the assumption, that the frame rate of the two incoming videos is equal - in reality, usually the desktop capture is of a lower framerate; and even worse, very often frames are out of sync.

This, then, requires the hassle of sitting in front of a video editor, and manually cutting and editing less-than-a-second clips on frame level - requiring hours of work for what will be in the end a 5 minute video. On the other hand, if the two videos ('live' and 'capture') did have the same framerate and sync: in principle, you wouldn't need more than a couple of minutes for finding the start sync point in a video editor - and the rest of the 'merged' video processing could be handled by a single command line. Which is why, in this post, I would like to focus on the desktop capture part.

As far as I can see, there are only few viable (as opposed to 5 Ways to Screencast Your Linux Desktop) alternatives for desktop capture in Linux / Ubuntu (note, I typically use a laptop as target for desktop capturing):

Have your target PC (laptop) clone the desktop on its VGA output; use a VGA-to-composite or VGA-to-S-video hardware to obtain a video signal from VGA; use video capture card on a different PC to grab video

Use recordMyDesktop on the target PC

Set up a VNC server (vino on Ubuntu; or vncserver) on the target PC to be captured; use VNC capture software (such as vncrec) on a different PC to grab/record the VNC stream (which can, subsequently, be converted to video).

Use ffmpeg with x11grab option

*(use some tool on the target PC, that would do a DMA transfer of a desktop image frame directly - from the graphics card frame buffer memory, to the network adapter memory)

Please note that the usefulness of the above approaches are limited by my context of use: the target PC that I want to capture, typically runs software (utilizing the tested hardware) that moves around massive ammounts of data; best you could say about describing such a system is "barely stable" :) I'd guess this is similar to problems gamers face, when wanting to obtain a video capture of a demanding game. And as soon as I start using something like recordMyDesktop, which also uses quite a bit of resources and wants to capture on the local hard disk - I immediately get severe kernel crashes (often with no vmcore generated).

So, in my context, I typically do assume involvement of a second computer - to run the capture and recording of the 'target' PC desktop. Other than that,  the pros and cons I can see so far with the above options, are included below.

(Desktop preparation)

For all of the methods discussed below, I tend to "prepare" the desktop beforehand:

Remove desktop backgrounds and icons

Set the resolution down to 800x600 via System/Preferences/Monitors (gnome-desktop-properties)

Change color depth down to 16 bpp (using xdpyinfo | grep "of root" to check)

... in order to minimize the load on desktop capture software. Note that changing color depth on Ubuntu requires changes to xorg.conf; however, "No xorg.conf (is) found in /etc/X11 (Ubuntu 10.04)" - so you may need to run sudo Xorg -configure first.

In order to keep graphics resource use low, also I usually had compiz disabled - or rather, I'd have 'System/Preferences/Appearance/Visual Effects' set to "None". However, after I tried enabling compiz by setting 'Visual Effects' to "Normal" (which doesn't get saved), I can notice windows on the LCD screen are redrawn much faster; so I keep it like this, also for desktop capture. I find this a bit strange: how could more effects cause a faster screen refresh? It doesn't look like it's due to a proprietary driver (the card is "Intel Corporation N10 Family Integrated Graphics Controller", and no proprietary driver option is given by Ubuntu upon switch to compiz) - although, it could be that all the blurring and effects just cheat my eyes :) ).

Cloning VGA

Well, this is the most expencive option (as it requires additional purchase of not just one, but two pieces of hardware: VGA converter, and video capture card); and applicable mostly to laptops (which have both a screen + additional VGA output - for desktops one may also have to invest in an additional graphics card, or a VGA cloning hardware).

However, it is also the only option that requires no additional software of the target PC whatsoever (and thus uses 0% processing power of the target CPU) - AND also the only one that will give a video with a true, unjittered framerate of 30 fps (as it is performed by separate hardware - although, with the assumption that clock domains misalignment, present between individual hardware pieces, is negligible).

Actually, as I already own something like a capture card, I have already invested in a VGA converter - in expectation that it will eventually allow me to produce final "merged" videos with only 5 mins of looking for alignment point, and a single command line; but I am yet to see whether this process will work as intended. I'm also wandering how possible it will be to capture desktop as  uncompressed video @ 800x600, 30 fps.

recordMyDesktop

Well, if you run recordMyDesktop without any arguments - it starts first with capturing (what looks like) raw image data, in a folder like /tmp/rMD-session-7247; and after you press Ctrl-C to interrupt it, it will encode this raw image data into an .ogv. Obviously, grabbing large image data on the same hard disk as my test software (which also moves large ammounts of data), is usually a cause for an instacrash :)

Hence, what I tried doing is to setup Samba to share a drive on the network; then on the target PC, I'd connect to this drive - and instruct recordMyDesktop to use this network drive (via gvfs) as its temporary files location:

recordmydesktop --workdir /home/user/.gvfs/test\ on\ 192.168.1.100/capture/ --no-sound --quick-subsampling --fps 30 --overwrite -o capture.ogv

Note that, while this command will use the network location for temporary files (and thus makes it possible for recordMyDesktop to run in parallel with my software) - as soon as you hit Ctrl-C, it will start encoding and saving capture.ogv directly on the local hard drive of the target (though, at that point, I don't really care :) )

First of my nags with recordMyDesktop is that you cannot instruct it to keep the temporary files, and avoid encoding them, on end: you can use Ctrl+Alt+p for pause - or you can hit Ctrl-C quickly after the first one, to cause it to crash; which will then leave the temporary files (if you don't hit Ctrl-C quickly enough the second time, the program will "Cleanning up cache..."). You can then run, say:

recordmydesktop --rescue /home/user/.gvfs/test\ on\ 192.168.1.100/capture/rMD-session-7247/

... in order to convert the raw temporary data. However, more often than not, recordMyDesktop will itself segfault in the midst of performing this "rescue". Although, the reason why I want to keep the temp files, is to have the uncompressed source for the picture-in-picture montage. Note that the "--on-the-fly-encoding" will avoid using temp files altogether - at the expence of using more CPU processing power (which, for me, again is cause for crashes.)

Then, there is the framerate - obviously, you can set requested framerate using the '--fps N' option; however, that is no guarantee that you will actually obtain that framerate; for instance, I'd get:

recordmydesktop --fps 25
...
Saved 2983 frames in a total of 6023 requests
...

... for a capture with my test software running; which means that the actually achieved rate is more like 25*2983/6032 = 12.3632 fps!

Obviously, frames are dropped - and mostly that shows as video playback is too fast. However, if I lower the requested fps to 12 - then according to saved/total reports, I achieve something like 11 fps; and in this case, video playback doesn't look 'sped up'.  And I still haven't tried aligning such a capture with a live video - so I have no idea if those frames that actually have been saved, also have an accurate timestamp.

VNC capture

The VNC capture, for me, consists of running a VNC server on the 'target' PC, and running vncrec (twibright edition) on the 'recorder' PC. As VNC server, I use vino, which is "System/Preferences/Remote Desktop (Preferences)". And apparently, even if vino configuration may not be the easiest thing to manage, vino as a server seems not too taxing to the 'target' PC; as I haven't experienced crashes when it runs in parallel with my test software.

On the other hand, when vncrec is capturing on the 'recorder' PC, it also raises a window showing you the 'target' desktop as it is seen in 'realtime'; when there are large updates (i.e. whole windows moving) on the 'target' - one can, quite visibly, see problems with the update/refresh rate on the 'recorder'. But, for only small updates (i.e. just a cursor moving on a static background), things seem OK.

This makes me wonder about one of my primary questions with this post - what is it, that sets the framerate in a VNC connection?

I haven't found a clear answer to this, but from bits and pieces of info (see refs below), I gather that:

The VNC server simply sends changes (screen changes + clicks etc) as fast as it can, when it receives them ; limited by the max network bandwidth that is available to the server

The VNC client receives those change events delayed and jittered by the network connection, and attempts to reconstruct the desktop "video" stream, again as fast as it can

... which means, one cannot state anything in terms of a stable, periodic frame rate (as in video).

As far as vncrec as a client goes, the end videos I get usually are declared as 10 fps, although frames can be rather displaced/jittered (which then requires the cutting in video editors). Note that the vncrec-twibright/README states: "The sample rate of the movie is 10 by default or overriden by VNCREC_MOVIE_FRAMERATE environment variable, or 10 if not specified."; however, the manpage also states "VNCREC_MOVIE_FRAMERATE - Specifies frame rate of the output movie. Has an effect only in -movie mode. Defaults to 10. Try 24 when your transcoder vomits from 10.". And if one looks into "vncrec/sockets.c" source, one can see:

void print_movie_frames_up_to_time(struct timeval tv)
{
  static double framerate;
  ....
  memcpy(out, bufoutptr, buffered);
  if (appData.record)
    {
      writeLogHeader (); /* Writes the timestamp */
      fwrite (bufoutptr, 1, buffered, vncLog);
    }

... which shows that some timestamps are written - but whether those timestamps originate from the "original" 'target' PC, or the 'recorder' one, I cannot tell.
EDIT: thanks to the answer by @kanaka, I checked through vncrec/sockets.c again, and can see that it is the writeLogHeader function itself calling gettimeofday; so the timestamps it writes are local - that is, they originate from the 'recorder' PC (and hence, these timestamps do not accurately describe when the frames originated on the 'target' PC).

In any case, it still seems to me, that the server sends - and vncrec as client receives - whenever; and it is only in the process of encoding a video file from the raw capture afterwards, that some form of a frame rate is set/interpolated.

I'd also like to state that on my 'target' laptop, the wired network connection is broken; so the wireless is my only option to get access to the router and the local network - at far lower speed than the 100MB/s that the router could handle from wired connections. However, if the jitter in captured frames is caused by wrong timestamps due to load on the 'target' PC, I don't think good network bandwidth will help too much.

Finally, as far as VNC goes, there could be other alternatives to try - such as VNCast server (promising, but requires some time to build from source, and is in "early experimental version"); or MultiVNC (although, it just seems like a client/viewer, without options for recording).

ffmpeg with x11grab

Haven't played with this much, but, I've tried it in connection with netcat; this:

# 'target'
ffmpeg -f x11grab -b 8000k -r 30 -s 800x600 -i :0.0 -f rawvideo - | nc 192.168.1.100 5678
# 'recorder'
nc -l 0.0.0.0 5678 > raw.video  #

... does capture a file, but ffplay cannot read the captured file properly; while:

# 'target'
ffmpeg -f x11grab -b 500k -r 30 -s 800x600 -i :0.0 -f yuv4mpegpipe -pix_fmt yuv444p - | nc 192.168.1.100 5678
# 'recorder'
nc -l 0.0.0.0 5678 | ffmpeg -i - /path/to/samplimg%03d.png

does produce .png images - but with compression artifacts (result of the compression involved with yuv4mpegpipe, I guess).

Thus, I'm not liking ffmpeg+x11grab too much currently - but maybe I simply don't know how to set it up for my needs.

*( graphics card -> DMA -> network )

I am, admittedly, not sure something like this exists - in fact, I would wager it doesn't :) And I'm no expert here, but I speculate:

if DMA memory transfer can be initiated from the graphics card (or its buffer that keeps the current desktop bitmap) as source, and the network adapter as destination - then in principle, it should be possible to obtain an uncompressed desktop capture with a correct (and decent) framerate. The point in using DMA transfer would be, of course, to relieve the processor from the task of copying the desktop image to the network interface (and thus, reduce the influence the capturing software can have on the processes running on the 'target' PC - especially those dealing with RAM or hard-disk).

A suggestion like this, of course, assumes that: there are massive ammounts of network bandwidth (for 800x600, 30 fps at least 800*600*3*30 = 43200000 bps = 42 MiB/s, which should be OK for local 100 MB/s networks); plenty of hard disk on the other PC that does the 'recording' - and finally, software that can afterwards read that raw data, and generate image sequences or videos based on it :)

The bandwidth and hard disk demands I could live with - as long as there is guarantee both for a stable framerate and uncompressed data; which is why I'd love to hear if something like this already exists.

-- -- -- -- --

Well, I guess that was it - as brief as I could put it :) Any suggestions for tools - or process(es), that can result with a desktop capture

in uncompressed format (ultimately convertible to uncompressed/lossless PNG image sequence), and

with a "correctly timecoded", stable framerate

..., that will ultimately lend itself to 'easy', single command-line processing for generating 'picture-in-picture' overlay videos - will be greatly appreciated!

Thanks in advance for any comments,

Cheers!

References

Experiences Producing a Screencast on Linux for CryptoTE - idlebox.net

The VideoLAN Forums • View topic - VNC Client input support (like screen://)

VNCServer throttles user inpt for slow client - Kyprianou, Mark - com.realvnc.vnc-list - MarkMail

Linux FAQ - X Windows: How do I Display and Control a Remote Desktop using VNC

How much bandwidth does VNC require? RealVNC - Frequently asked questions

x11vnc: a VNC server for real X displays

HowtoRecordVNC (an X11 session) - Debian Wiki

Alternative To gtk-RecordMyDesktop in Ubuntu

(Ffmpeg-user) How do I use pipes in ffmpeg

(ffmpeg-devel) (PATCH) Fix segfault in x11grab when drawing Cursor on Xservers that don't support the XFixes extension


来源: stackexchange

问:
VHDL: Concise formulation of conditional signal assignment
The following code is a 4:1 multiplexer. If the dis signal is '1' then the output should be 0 on all output pins. Is there a concise way to state that if dis is high, then the output should be 0, regardless of sel, without
having to permute through each combination of sel?

I am aware that in some cases, if conditional assignment are left ambiguous, then there becomes potential for unintended latch generation, and other undesired side effects.

```<code>architecture dataflow of mux8_4 is
begin
    q <=d0 when sel = "00" and dis = '0' else
        d1 when sel = "01" and dis = '0' else
        d2 when sel = "10" and dis = '0' else
        d3 when sel = "11" and dis = '0' else
        "00000000" when sel = "00" and dis = '1' else
        "00000000" when sel = "01" and dis = '1' else
        "00000000" when sel = "10" and dis = '1' else
        "00000000" when sel = "11" and dis = '1';
end architecture dataflow;
</code>```

My attempt (I understand the omission of all possible statements to be bad
practice, however)

```<code>architecture dataflow of mux8_4 is
begin
    q <=    "00000000" when dis = '1' else
        d0 when sel = "00" and dis = '0' else
        d1 when sel = "01" and dis = '0' else
        d2 when sel = "10" and dis = '0' else
        d3 when sel = "11" and dis = '0';
end architecture dataflow;
</code>```

答:
There's also selected signal assignment:

```<code>architecture foo of mux8_4 is
    subtype choice_type is std_logic_vector (2 downto 0);
begin
    with choice_type'(dis & sel) select
        q <= d0          when "000",
             d1          when "001",
             d2          when "010",
             d3          when "011",
             "00000000"  when others;
end architecture;
</code>```

Where the case expression may be a qualified expression with a type mark that has a locally static subtype.

See IEEE Std 1076-1993 9.5.2 Selected signal assignments, 8.8 Case statement or IEEE Std 1076-2008 11.6 Concurrent signal assignment statements, 10.5.4 Selected signal assignment statements, 10.9 Case statement.

This (and your) concurrent signal assignment statements have equivalent processes containing equivalent sequential signal assignment statements. Both conditional and selected signal assignment statements are allowed as sequential statements in -2008. There is an equivalent case statement for a selected signal assignment.

Providing only binary values for dis and select can be done for synthesis where the weak values 'H' and 'L' are mapped to the strong values '1' and '0' respectively. For simulation you can use conversion functions to insure dis and sel represent a binary value if they can have weak values.

If your four mux data inputs can be expresses as an array value you describe a multiplexer a little more compactly:

```<code>architecture fum of mux8_4 is
    type mux4 is array (0 to 3) of std_logic_vector(7 downto 0);
    use ieee.numeric_std.all;
    signal mux:      mux4;
begin
    mux <= (d0, d1, d2, d3);
    q <= mux(to_integer(unsigned(sel))) when dis = '0' else (others => '0');

end architecture;
</code>```

An index name requires an array object with a locally static name so a type declaration is used in declaring an array object (mux) that is assigned an aggregate value of type mux4.

After that we can use an index converted to a natural from sel as an index when dis = '0' in a conditional signal assignment, with an else value of all '0's.

Both of these architectures analyze. If you had provided a Minimal, Complete and Veriable example with an entity declaration and a testbench they could have been elaborated and simulated, demonstrating functionality. (They both analyze with an added entity declaration).

If your sel signal had been a constrained integer subtype the indexed name index would be even more compact and readable. The to_integer conversion function found in package numeric_std maps weak levels representing binary values to strong and generates a warning if sel contains metavalue element values (which would be mapped to '0').

ContentLicense: CC BY-SA 3.0

Body:
The following code is a 4:1 multiplexer. If the dis signal is '1' then the output should be 0 on all output pins. Is there a concise way to state that if dis is high, then the output should be 0, regardless of sel, without
having to permute through each combination of sel?

I am aware that in some cases, if conditional assignment are left ambiguous, then there becomes potential for unintended latch generation, and other undesired side effects.

architecture dataflow of mux8_4 is
begin
    q <=d0 when sel = "00" and dis = '0' else
        d1 when sel = "01" and dis = '0' else
        d2 when sel = "10" and dis = '0' else
        d3 when sel = "11" and dis = '0' else
        "00000000" when sel = "00" and dis = '1' else
        "00000000" when sel = "01" and dis = '1' else
        "00000000" when sel = "10" and dis = '1' else
        "00000000" when sel = "11" and dis = '1';
end architecture dataflow;

My attempt (I understand the omission of all possible statements to be bad
practice, however)

architecture dataflow of mux8_4 is
begin
    q <=    "00000000" when dis = '1' else
        d0 when sel = "00" and dis = '0' else
        d1 when sel = "01" and dis = '0' else
        d2 when sel = "10" and dis = '0' else
        d3 when sel = "11" and dis = '0';
end architecture dataflow;

Body:
There's also selected signal assignment:

architecture foo of mux8_4 is
    subtype choice_type is std_logic_vector (2 downto 0);
begin
    with choice_type'(dis & sel) select
        q <= d0          when "000",
             d1          when "001",
             d2          when "010",
             d3          when "011",
             "00000000"  when others;
end architecture;

Where the case expression may be a qualified expression with a type mark that has a locally static subtype.

See IEEE Std 1076-1993 9.5.2 Selected signal assignments, 8.8 Case statement or IEEE Std 1076-2008 11.6 Concurrent signal assignment statements, 10.5.4 Selected signal assignment statements, 10.9 Case statement.

This (and your) concurrent signal assignment statements have equivalent processes containing equivalent sequential signal assignment statements. Both conditional and selected signal assignment statements are allowed as sequential statements in -2008. There is an equivalent case statement for a selected signal assignment.

Providing only binary values for dis and select can be done for synthesis where the weak values 'H' and 'L' are mapped to the strong values '1' and '0' respectively. For simulation you can use conversion functions to insure dis and sel represent a binary value if they can have weak values.

If your four mux data inputs can be expresses as an array value you describe a multiplexer a little more compactly:

architecture fum of mux8_4 is
    type mux4 is array (0 to 3) of std_logic_vector(7 downto 0);
    use ieee.numeric_std.all;
    signal mux:      mux4;
begin
    mux <= (d0, d1, d2, d3);
    q <= mux(to_integer(unsigned(sel))) when dis = '0' else (others => '0');

end architecture;

An index name requires an array object with a locally static name so a type declaration is used in declaring an array object (mux) that is assigned an aggregate value of type mux4.

After that we can use an index converted to a natural from sel as an index when dis = '0' in a conditional signal assignment, with an else value of all '0's.

Both of these architectures analyze. If you had provided a Minimal, Complete and Veriable example with an entity declaration and a testbench they could have been elaborated and simulated, demonstrating functionality. (They both analyze with an added entity declaration).

If your sel signal had been a constrained integer subtype the indexed name index would be even more compact and readable. The to_integer conversion function found in package numeric_std maps weak levels representing binary values to strong and generates a warning if sel contains metavalue element values (which would be mapped to '0').


问:
How to map through an array in React without ids?
I have a fairly standard array:

```<code>["value","value","value"]
</code>```

If I want to iterate through it, each list item needs a unique key. But how would I do this in this case?

JSONs often come with an id -but in this case I don't have any id's, and the values also aren't unique, so I cannot just use them as the key.

```<code>{someArray.map(object => {
                return (<span key=???> {object} </span>); })}
</code>```

答:
each list item needs a unique key

It doesn't really. React's warnings here are very over-blown I feel. The unique keys are only needed if you need better performance, and I believe also some stuff about maintaining component state. It's worth noting that if you do dom.div(null, ["text"]) you will receive a warning, but if you do dom.div(null, ...["text"]) you will receive no warning despite the same array being passed in both cases. In the latter case React simply uses the index as the key, which is also totally fine in the former case but React warns about it for no real reason.

If the render function is stateless and you don't need better performance, just give them a key of their index in the array to silence the warning, or use the spread operator.

Body:
I have a fairly standard array:

["value","value","value"]

If I want to iterate through it, each list item needs a unique key. But how would I do this in this case?

JSONs often come with an id -but in this case I don't have any id's, and the values also aren't unique, so I cannot just use them as the key.

{someArray.map(object => {
                return ( {object} ); })}


问:
Android AltBeacon library stop find beacons every 1 second when app in background on galaxy s7
I'm using AltBeacon library inside service to find my beacon every 1 second when the app on foreground.
On Galaxy s7 when the app go's to background it stop find the beacon every second,
instead it return data every few seconds between 5 - 30 secs.
I can see that "didRangeBeaconsInRegion" call every second but it return with out beacons most of the time.

I need to keep the behavior of foreground when the app is in background.

This is my BeaconManager configuration:

```<code>private static long EXIT_PERIOD = 16500;
private static long SCAN_PERIOD = 1150;
.
.
.
beaconManager = BeaconManager.getInstanceForApplication(this);
BeaconManager.setRegionExitPeriod(EXIT_PERIOD);
beaconManager.setBackgroundScanPeriod(SCAN_PERIOD);
beaconManager.setForegroundScanPeriod(SCAN_PERIOD);
beaconManager.setBackgroundBetweenScanPeriod(0);
</code>```

Tnx

答:
Some builds of Android 7.x for Samsung devices put Bluetooth scans into low power mode when an app has no activities in the foreground.  The reason you see Les frequent detections is because that is how low power scans on Android behave.

You can read more about this issue here:

https://github.com/AltBeacon/android-beacon-library/issues/483

To be clear, this is appears to be a Samsung-specific customization to Android.  There is no known workaround to keep the OS from overriding a low latency scan with a low power one.

Body:
I'm using AltBeacon library inside service to find my beacon every 1 second when the app on foreground.
On Galaxy s7 when the app go's to background it stop find the beacon every second,
instead it return data every few seconds between 5 - 30 secs.
I can see that "didRangeBeaconsInRegion" call every second but it return with out beacons most of the time.

I need to keep the behavior of foreground when the app is in background.

This is my BeaconManager configuration:

private static long EXIT_PERIOD = 16500;
private static long SCAN_PERIOD = 1150;
.
.
.
beaconManager = BeaconManager.getInstanceForApplication(this);
BeaconManager.setRegionExitPeriod(EXIT_PERIOD);
beaconManager.setBackgroundScanPeriod(SCAN_PERIOD);
beaconManager.setForegroundScanPeriod(SCAN_PERIOD);
beaconManager.setBackgroundBetweenScanPeriod(0);

Tnx


问:
HTML5 output explanation
These two simplified HTML5 codes gets the same result:

code #1:

```<code><html>
<head>
    <title>test</title>
</head>
<body>
    <p>test1</p>
</body>
</html>
</code>```

--

code #2:

```<code><html>
<head>
    <title>test</title>
</head>
<body>
    test1
</body>
</html>
</code>```

====

The output is the same in both cases, the screen prints the word "test1", so what the use of the tag
 ? how does the browser understand the two codes? please note that the file code is .html extension

答:
The
 tag stands for paragraph, which is used for text, and you can read more about it at MDN: https://developer.mozilla.org/en/docs/Web/HTML/Element/p

If you take a a good look you'll see the output is not the same, the p is slightly far down the page because it has a default margin set, which for example a div does not.

The browser parse through the code/markup and render the content in each tag accordingly to that particular tags default layout settings.

Title: HTML5 output explanation

Body:
These two simplified HTML5 codes gets the same result:

code #1:

    <title>test</title>

test1

--

code #2:

    <title>test</title>

    test1

====

The output is the same in both cases, the screen prints the word "test1", so what the use of the tag
 ? how does the browser understand the two codes? please note that the file code is .html extension

Body:
The <p> tag stands for paragraph, which is used for text, and you can read more about it at MDN: https://developer.mozilla.org/en/docs/Web/HTML/Element/p

If you take a a good look you'll see the output is not the same, the p is slightly far down the page because it has a default margin set, which for example a div does not.

The browser parse through the code/markup and render the content in each tag accordingly to that particular tags default layout settings.


问:
Adding hours to a Javascript date in a loop
I'm getting some strange results from adding hours to a date.  I'm basically adding 0, 6, 12, 18, 24, 30, etc hours to a Javascript date.  I came across some of the recommendations online (like this: Adding hours to Javascript Date object?), but when in a loop it was skipping ahead many hours/months.  It seemed to be keeping the new version of the date and just adding hours to it...when I really just want to add the hours to the original date.

So, here's the basics of what I have.

```<code>for (var i = 1; i < 4; i++) {

hour_date.setHours(hour_date.getHours() + hour);

output.push(hour_date...)
}
//where hour is 6, 12, 18, 24, etc in a loop
//and where hour_date is defined earlier and is
//Sun Apr 02 2017 12:00:00 GMT-0700 (Pacific Daylight Time)
</code>```

So I'm trying to figure out how to simply add 6 hours to an initial date variable...so I can push those values out to an array.  I understand the push part...but I'm just trying to add the hours correctly within the loop.

Thanks very much for any help!

答:
You need a new object each time. Currently you are modifying the same object over and over and pushing the same reference to each index of the array

Try:

```<code>for (var i= 1; i < 4; i++) {
    var newDate = new Date(hour_date);
    hour += 6;
    newDate.setHours(hour_date.getHours() + hour);
    output.push(newDate);
}
</code>```

var hour_date = new Date(), output = [],  hour = 0;
for (var i = 1; i < 10; i++) {
  var newDate = new Date(hour_date);
  hour += 6;
  newDate.setHours(hour_date.getHours() + hour);
  output.push(newDate);
}

console.log(JSON.stringify(output, null, ' '))```

Body:
I'm getting some strange results from adding hours to a date.  I'm basically adding 0, 6, 12, 18, 24, 30, etc hours to a Javascript date.  I came across some of the recommendations online (like this: Adding hours to Javascript Date object?), but when in a loop it was skipping ahead many hours/months.  It seemed to be keeping the new version of the date and just adding hours to it...when I really just want to add the hours to the original date.

So, here's the basics of what I have.

for (var i = 1; i < 4; i++) {

hour_date.setHours(hour_date.getHours() + hour);

output.push(hour_date...)
}
//where hour is 6, 12, 18, 24, etc in a loop
//and where hour_date is defined earlier and is
//Sun Apr 02 2017 12:00:00 GMT-0700 (Pacific Daylight Time)

So I'm trying to figure out how to simply add 6 hours to an initial date variable...so I can push those values out to an array.  I understand the push part...but I'm just trying to add the hours correctly within the loop.

Thanks very much for any help!

Body:
You need a new object each time. Currently you are modifying the same object over and over and pushing the same reference to each index of the array

Try:

for (var i= 1; i < 4; i++) {
    var newDate = new Date(hour_date);
    hour += 6;
    newDate.setHours(hour_date.getHours() + hour);
    output.push(newDate);
}

var hour_date = new Date(), output = [],  hour = 0;
for (var i = 1; i < 10; i++) {
  var newDate = new Date(hour_date);
  hour += 6;
  newDate.setHours(hour_date.getHours() + hour);
  output.push(newDate);
}

console.log(JSON.stringify(output, null, ' '))


问:
Can't access object literal property using getter in ES6 module
I was looking for a way to self-reference an object to access it's property when I discover the ES5 getter feature (see. MDN).

I'm working with NPM module and can't access the canvas property.

config.js

```<code>import path from "path";
import layout from "./layouts";

const config = {
  canvas: { width: 80, height: 80 },
  layout: {
    get base() {
      console.log(this);
      console.log(this.canvas);
      return layout.base.bottom(this.canvas);
    },
    get annotation() {
      return layout.annotation.top(this.canvas);
    }
  }
};
export default config;
</code>```

layouts.js

```<code>export default {
  annotation: {
    top: options => ({
      x: options.width / 2,
    })
  },
  base: {
    bottom: options => ({
      x: options.width / 2,
    })
  }
};
</code>```

Error

```<code>{ base: [Getter], annotation: [Getter] }
undefined
TypeError: Cannot read property 'width' of undefined
    at Object.bottom (/data/projects/hanzi-pinyin-font/src/layouts.js:13:10)
    at Object.get base [as base] (/data/projects/hanzi-pinyin-font/src/config.js:17:26)
    at generateSvg (/data/projects/hanzi-pinyin-font/index.js:15:40)
    at /data/projects/hanzi-pinyin-font/index.js:39:5
    at /data/projects/hanzi-pinyin-font/node_modules/jsonfile/index.js:46:5
</code>```

Question

Why isn't this working?

答:
.canvas is not a property of the layout object but of the config one, so you cannot access it using this (which refers to layout, as your log shows). Instead, use

```<code>import path from "path";
import layout from "./layouts";

export default const config = {
  canvas: { width: 80, height: 80 },
  layout: {
    get base() {
      return layout.base.bottom(config.canvas);
    },
    get annotation() {
      return layout.annotation.top(config.canvas);
    }
  }
};
</code>```

Body:
I was looking for a way to self-reference an object to access it's property when I discover the ES5 getter feature (see. MDN).

I'm working with NPM module and can't access the canvas property.

config.js

import path from "path";
import layout from "./layouts";

const config = {
  canvas: { width: 80, height: 80 },
  layout: {
    get base() {
      console.log(this);
      console.log(this.canvas);
      return layout.base.bottom(this.canvas);
    },
    get annotation() {
      return layout.annotation.top(this.canvas);
    }
  }
};
export default config;

layouts.js

export default {
  annotation: {
    top: options => ({
      x: options.width / 2,
    })
  },
  base: {
    bottom: options => ({
      x: options.width / 2,
    })
  }
};

Error

{ base: [Getter], annotation: [Getter] }
undefined
TypeError: Cannot read property 'width' of undefined
    at Object.bottom (/data/projects/hanzi-pinyin-font/src/layouts.js:13:10)
    at Object.get base [as base] (/data/projects/hanzi-pinyin-font/src/config.js:17:26)
    at generateSvg (/data/projects/hanzi-pinyin-font/index.js:15:40)
    at /data/projects/hanzi-pinyin-font/index.js:39:5
    at /data/projects/hanzi-pinyin-font/node_modules/jsonfile/index.js:46:5

Question

Why isn't this working?

Body:
.canvas is not a property of the layout object but of the config one, so you cannot access it using this (which refers to layout, as your log shows). Instead, use

import path from "path";
import layout from "./layouts";

export default const config = {
  canvas: { width: 80, height: 80 },
  layout: {
    get base() {
      return layout.base.bottom(config.canvas);
    },
    get annotation() {
      return layout.annotation.top(config.canvas);
    }
  }
};


问:
Get the file size from a WebP file header
https://developers.google.com/speed/webp/docs/riff_container

I’ve got a WebP file (about 22 kilobytes), and the hexadecimal of the first 12 bytes is 524946461c57000057454250.

The first and last 4 bytes make sense (ASCII "RIFF" and "WEBP"), but I don’t know what 1c570000 signifies. The doc says it is the file size, but that would be a huge file if it were hexadecimal 1c570000 bytes.

How do I calculate the file size (22 kilobytes) from the file header (reporting 1c570000)?

答:
As specified in the document (https://developers.google.com/speed/webp/docs/riff_container), the file size bytes are stored in Little Endian.

That is, the bytes are stored in the order of least significance to most significance (the least significant byte is at the first location, and the most significant byte is stored at the last location).

00 00 57 1c is 22,300, so "about 22 kilobytes" is correct.


问:
Why isn't my unordered lists not being positioned beside the centered image?
I'm trying to put my two lists beside the image that is centered in the middle one on each side but the two lists have to be centered and not all the way right or left.

Thanks in advance.
*Please fullscreen the html snippet.

div.main p {
  color: white;
  font-size: 20px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
}

div.main h1 {
  color: white;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  text-decoration: underline;
  text-align: center;
  font-size: 36px;
}

div.material {
  float: left;
}

div.material h2 {
  color: white;
  font-size: 20px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  text-decoration: underline;
}

div.list li {
  color: white;
  font-size: 16px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: left;
  list-style-type: none;
}

div.materialy {
  float: right;
}

div.materialy h2 {
  color: white;
  font-size: 20px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  text-decoration: underline;
}

div.listy li {
  color: white;
  font-size: 16px;
  font-family: Arial, Helvetica, sans-serif;
  list-style-type: none;
  text-align: right;
}

div.method p {
  color: white;
  font-size: 20px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
  text-decoration: underline;
  font-weight: bold;
}

div.method li {
  color: white;
  font-size: 16px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
  list-style-type: none;
  line-height: 40px;
}

div.skill li {
  font-weight: bold;
  font-style: italic;
  font-size: 18px;
}

div.skill p {
  font-style: italic;
  text-decoration: none;
  font-size: 16px;
  color: #F00;
}

div.image img {
  display: block;
  margin: 0 auto;
}

body {
  background-color: blue;
}

div.nav ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font: Arial, Helvetica, sans-serif black;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 18px;
  border-radius: 5px;
  border-bottom: solid black;
  border-top: solid black;
  border-left: solid black;
  border-right: solid black;
  background: #09F;
  /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(#09F, #9FF);
  /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(#09F, #9FF);
  /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(#09F, #9FF);
  /* For Firefox 3.6 to 15 */
  background: linear-gradient(#09F, #9FF);
  /* Standard syntax (must be last) */
}

div.nav li {
  float: left;
}

div.nav li a {
  display: block;
  color: black;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

div.nav li a:hover {
  background-color: #0FC;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<link href="style4.css" type="text/css" rel="stylesheet" />

<head>
  <title>Tips</title>
</head>
<div class="nav">
  <ul>
    <li>Home
    </li>
    <li>Tips
    </li>
    <li>Learn
    </li>
    <li>Contact
    </li>
  </ul>
</div>

<body>
  <div class="main">
    <h1>Welcome to the tips page!</h1>
    <p>
      <br>Artists typically use great techniques to make their art more professional looking and it also helps them improve their skills at drawing.
      <br>They use different types of mediums, tools, and art supplies to enhance the looks of their artwork.</p>
  </div>
  <div class="material">
    <h2>Materials for a beginner or newbie:</h2>
  </div>
  <div class="image">
    </br>
    </br>
    </br>
    <div class="list">
      <ul>
        <li>HB #2 Pencil</li>
        <li>Clean white vinyl eraser</li>
        <li>White printer paper</li>
        <li>Good lighting or desk lamp</li>
      </ul>
    </div>
    <img src="person-drawing.jpg" height="296" width="395"></div>
  <div class="materialy">
    <h2>Materials for the advanced:</h2>
    <div class="listy">
      <ul>
        <li>Staedtler Design/Drafting Pencil Set</li>
        <li>Clean white vinyl eraser</li>
        <li>Gum eraser</li>
        <li>Kneaded eraser</li>
        <li>White printer paper</li>
        <li>Good lighting or desk lamp</li>
        <li>Blending sticks</li>
        <li>0.5/0.7 mechanical pencils</li>
        <li>0.5/0.7 mechanical pencil lead</li>
        <li>Fine tip liner marker</li>
        <li>Adjustable drafting table</li>
      </ul>
    </div>
  </div>
  </br>
  <div class="method">
    <p>Here are some good methods and techniques to practice drawing skills:</p>
    <ul>
      <div class="skill">
        <li>Drawing is a skill</li>
        <p>*Drawing isn't some magical activity that people are born with! It can be taught and learnt from also, anyone can be skilled at drawing!</p>
      </div>
      <li>Drawing or sketching lightly</li>
      <li>Observe your artwork while drawing regularly</li>
      <li>Look for basic shapes</li>
      <li>Take your time</li>
      <li>Use guidelines/structure to form the foundation of the drawing</li>
      <li>Use resources if needed</li>
      <li>Be consistent</li>
      <li>Relax and have fun</li>
      <li>Keep practicing constantly</li>
    </ul>
  </div>
</body>

</html></code>```

答:
First of all, you have to put all DIV tags inside BODY. Then you have to clean up a little your DIVs. In order not to rewrite the whole HTML code, I would suggest you to use a table for the lists:</p>

```<code><!DOCTYPE html>
<html>
<link href="style4.css" type="text/css" rel="stylesheet" />

<head>
  <title>Tips</title>
</head>

<body>

    <div class="nav">
      <ul>
        <li><a href="home.html">Home</a>
        </li>
        <li><a href="">Tips</a>
        </li>
        <li><a href="index.html">Learn</a>
        </li>
        <li><a href="contacts.html">Contact</a>
        </li>
      </ul>
    </div>

  <div class="main">
    <h1>Welcome to the tips page!</h1>
    <p>
      <br>Artists typically use great techniques to make their art more professional looking and it also helps them improve their skills at drawing.
      <br>They use different types of mediums, tools, and art supplies to enhance the looks of their artwork.</p>
  </div>

  <table border="0" cellspacing="0" cellpadding="0" width="100%">
  <tr>
  <td align="center" width="33%">
    <div class="material">
        <h2>Materials for a beginner or newbie:</h2>
    </div>
    <div class="list">
        <ul>
        <li>HB #2 Pencil</li>
        <li>Clean white vinyl eraser</li>
        <li>White printer paper</li>
        <li>Good lighting or desk lamp</li>
        </ul>
    </div>
  </td>
   <td align="center" width="33%">
    <div class="image">
        </br>
        </br>
        </br>
        <img src="person-drawing.jpg" height="296" width="395">
    </div>
  </td>
   <td align="center" width="33%">
      <div class="materialy">
        <h2>Materials for the advanced:</h2>
        <div class="listy">
          <ul>
            <li>Staedtler Design/Drafting Pencil Set</li>
            <li>Clean white vinyl eraser</li>
            <li>Gum eraser</li>
            <li>Kneaded eraser</li>
            <li>White printer paper</li>
            <li>Good lighting or desk lamp</li>
            <li>Blending sticks</li>
            <li>0.5/0.7 mechanical pencils</li>
            <li>0.5/0.7 mechanical pencil lead</li>
            <li>Fine tip liner marker</li>
            <li>Adjustable drafting table</li>
          </ul>
        </div>
      </div>
  </td>
  </tr>
  </table>

  </br>
  <div class="method">
    <p>Here are some good methods and techniques to practice drawing skills:</p>
    <ul>
      <div class="skill">
        <li>Drawing is a skill</li>
        <p>*Drawing isn't some magical activity that people are born with! It can be taught and learnt from also, anyone can be skilled at drawing!</p>
      </div>
      <li>Drawing or sketching lightly</li>
      <li>Observe your artwork while drawing regularly</li>
      <li>Look for basic shapes</li>
      <li>Take your time</li>
      <li>Use guidelines/structure to form the foundation of the drawing</li>
      <li>Use resources if needed</li>
      <li>Be consistent</li>
      <li>Relax and have fun</li>
      <li>Keep practicing constantly</li>
    </ul>
  </div>
</body>

</html>
</code>```

Body:
I'm trying to put my two lists beside the image that is centered in the middle one on each side but the two lists have to be centered and not all the way right or left.

Thanks in advance.
*Please fullscreen the html snippet.

div.main p {
  color: white;
  font-size: 20px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
}

div.main h1 {
  color: white;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  text-decoration: underline;
  text-align: center;
  font-size: 36px;
}

div.material {
  float: left;
}

div.material h2 {
  color: white;
  font-size: 20px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  text-decoration: underline;
}

div.list li {
  color: white;
  font-size: 16px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: left;
  list-style-type: none;
}

div.materialy {
  float: right;
}

div.materialy h2 {
  color: white;
  font-size: 20px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  text-decoration: underline;
}

div.listy li {
  color: white;
  font-size: 16px;
  font-family: Arial, Helvetica, sans-serif;
  list-style-type: none;
  text-align: right;
}

div.method p {
  color: white;
  font-size: 20px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
  text-decoration: underline;
  font-weight: bold;
}

div.method li {
  color: white;
  font-size: 16px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
  list-style-type: none;
  line-height: 40px;
}

div.skill li {
  font-weight: bold;
  font-style: italic;
  font-size: 18px;
}

div.skill p {
  font-style: italic;
  text-decoration: none;
  font-size: 16px;
  color: #F00;
}

div.image img {
  display: block;
  margin: 0 auto;
}

body {
  background-color: blue;
}

div.nav ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font: Arial, Helvetica, sans-serif black;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 18px;
  border-radius: 5px;
  border-bottom: solid black;
  border-top: solid black;
  border-left: solid black;
  border-right: solid black;
  background: #09F;
  /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(#09F, #9FF);
  /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(#09F, #9FF);
  /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(#09F, #9FF);
  /* For Firefox 3.6 to 15 */
  background: linear-gradient(#09F, #9FF);
  /* Standard syntax (must be last) */
}

div.nav li {
  float: left;
}

div.nav li a {
  display: block;
  color: black;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

div.nav li a:hover {
  background-color: #0FC;
}

<!DOCTYPE html>

<link href="style4.css" type="text/css" rel="stylesheet" />

  <title>Tips</title>

Home

Tips

Learn

Contact

Welcome to the tips page!

Artists typically use great techniques to make their art more professional looking and it also helps them improve their skills at drawing.

They use different types of mediums, tools, and art supplies to enhance the looks of their artwork.

Materials for a beginner or newbie:

HB #2 Pencil

Clean white vinyl eraser

White printer paper

Good lighting or desk lamp

Materials for the advanced:

Staedtler Design/Drafting Pencil Set

Clean white vinyl eraser

Gum eraser

Kneaded eraser

White printer paper

Good lighting or desk lamp

Blending sticks

0.5/0.7 mechanical pencils

0.5/0.7 mechanical pencil lead

Fine tip liner marker

Adjustable drafting table

Here are some good methods and techniques to practice drawing skills:

Drawing is a skill

*Drawing isn't some magical activity that people are born with! It can be taught and learnt from also, anyone can be skilled at drawing!

Drawing or sketching lightly

Observe your artwork while drawing regularly

Look for basic shapes

Take your time

Use guidelines/structure to form the foundation of the drawing

Use resources if needed

Be consistent

Relax and have fun

Keep practicing constantly

Body:
First of all, you have to put all DIV tags inside BODY. Then you have to clean up a little your DIVs. In order not to rewrite the whole HTML code, I would suggest you to use a table for the lists:

<!DOCTYPE html>
<html>
<link href="style4.css" type="text/css" rel="stylesheet" />

<head>
  <title>Tips</title>
</head>

<body>

    <div class="nav">
      <ul>
        <li><a href="home.html">Home</a>
        </li>
        <li><a href="">Tips</a>
        </li>
        <li><a href="index.html">Learn</a>
        </li>
        <li><a href="contacts.html">Contact</a>
        </li>
      </ul>
    </div>

  <div class="main">
    <h1>Welcome to the tips page!</h1>
    <p>
      <br>Artists typically use great techniques to make their art more professional looking and it also helps them improve their skills at drawing.
      <br>They use different types of mediums, tools, and art supplies to enhance the looks of their artwork.</p>
  </div>

  <table border="0" cellspacing="0" cellpadding="0" width="100%">
  <tr>
  <td align="center" width="33%">
    <div class="material">
        <h2>Materials for a beginner or newbie:</h2>
    </div>
    <div class="list">
        <ul>
        <li>HB #2 Pencil</li>
        <li>Clean white vinyl eraser</li>
        <li>White printer paper</li>
        <li>Good lighting or desk lamp</li>
        </ul>
    </div>
  </td>
   <td align="center" width="33%">
    <div class="image">
        </br>
        </br>
        </br>
        <img src="person-drawing.jpg" height="296" width="395">
    </div>
  </td>
   <td align="center" width="33%">
      <div class="materialy">
        <h2>Materials for the advanced:</h2>
        <div class="listy">
          <ul>
            <li>Staedtler Design/Drafting Pencil Set</li>
            <li>Clean white vinyl eraser</li>
            <li>Gum eraser</li>
            <li>Kneaded eraser</li>
            <li>White printer paper</li>
            <li>Good lighting or desk lamp</li>
            <li>Blending sticks</li>
            <li>0.5/0.7 mechanical pencils</li>
            <li>0.5/0.7 mechanical pencil lead</li>
            <li>Fine tip liner marker</li>
            <li>Adjustable drafting table</li>
          </ul>
        </div>
      </div>
  </td>
  </tr>
  </table>

  </br>
  <div class="method">
    <p>Here are some good methods and techniques to practice drawing skills:</p>
    <ul>
      <div class="skill">
        <li>Drawing is a skill</li>
        <p>*Drawing isn't some magical activity that people are born with! It can be taught and learnt from also, anyone can be skilled at drawing!</p>
      </div>
      <li>Drawing or sketching lightly</li>
      <li>Observe your artwork while drawing regularly</li>
      <li>Look for basic shapes</li>
      <li>Take your time</li>
      <li>Use guidelines/structure to form the foundation of the drawing</li>
      <li>Use resources if needed</li>
      <li>Be consistent</li>
      <li>Relax and have fun</li>
      <li>Keep practicing constantly</li>
    </ul>
  </div>
</body>

</html>


问:
Structuring Django application
I am currently working on designing a web application to be used by researchers to conduct reviews. In this application there are two groups of users - participants and administrators.

Only administrators can start a review and can assign any user or administrator to participate in the review as an admin or a screener. The general workflow for each review will be:

Search medical databases and import thousands of references.

Screen references based on title (number of reviewers/admins Screening can be 1 or multiple). Each reviewer will screen all references. Mark each reference as included or excluded.

Screen included references based on abstract. Same as above applies.

Source full-text as PDF and store for included references.

Screen included references based on full text. Same as above applies.

Create custom forms.

Extract data from included references.

Export data

Throughout the progress of the review machine learning on all of the references will be done. We will also require comprehensive logging throughout the review.

My question is this, how can I best split these sections into django apps and how should I structure the required databases.

Provisionally, I've thought about having these databases:

Users. Stores info on screeners and reviewers and which projects a tenner and admin in.

Project. Stores basic info on each project including data extraction form. One to many relationship with references table.

References. Stores info about each reference including inclusion status and data extraction.

I don't know how to deal with the logging. How can I do this?

Is this a sensible split and if so how should I accordingly split the steps into apps.

答:
The best thing about Django is apps that you create with manage.py startapp <myapp> . Apps gives good control of modularising the code. You are on the right track in modularising the code.

Regarding your tables users, projects and references sounds reasonable from your explanation.

If I were you, I would structure apps into something like this.

```<code>apps/
    userprofile/ (users table )
    project/ (projects and references tables)
    activity/ (activity and notifications tables)
</code>```

Regarding logging
Each activity like user edits , project edits or deletes can be captured via a post_ or pre_ signals https://docs.djangoproject.com/en/1.10/topics/signals/. User them to create an activity and based on the activity you can publish the single activity to multiple users as notifications ie., a single activity will trigger each  notification to multiple users who are participants in the event.

In each app

I prefer to use following structure inside each app :

```<code>userprofile/
    __init__
    views.py
    tests.py
    signals.py # write the post_save pre_save post_delete pre_delete logics here
    managers.py  # take full leverage of managers, and custom querysets
    forms.py
    models.py
    urls.py
    admin.py
    tasks.py # for celery or tasks which will be used by queuing systems
    apps.py
</code>```

Regarding version the data

Try the one which suites your requirement from here  https://djangopackages.org/grids/g/model-audit/

Title: Structuring Django application

Body:
The best thing about Django is apps that you create with manage.py startapp <myapp> . Apps gives good control of modularising the code. You are on the right track in modularising the code.

Regarding your tables users, projects and references sounds reasonable from your explanation.

If I were you, I would structure apps into something like this.

apps/
    userprofile/ (users table )
    project/ (projects and references tables)
    activity/ (activity and notifications tables)

Regarding logging
Each activity like user edits , project edits or deletes can be captured via a post_ or pre_ signals https://docs.djangoproject.com/en/1.10/topics/signals/. User them to create an activity and based on the activity you can publish the single activity to multiple users as notifications ie., a single activity will trigger each  notification to multiple users who are participants in the event.

In each app

I prefer to use following structure inside each app :

userprofile/
    __init__
    views.py
    tests.py
    signals.py # write the post_save pre_save post_delete pre_delete logics here
    managers.py  # take full leverage of managers, and custom querysets
    forms.py
    models.py
    urls.py
    admin.py
    tasks.py # for celery or tasks which will be used by queuing systems
    apps.py

Regarding version the data

Try the one which suites your requirement from here  https://djangopackages.org/grids/g/model-audit/


答:
You can use the second argument of map, the index:

```<code>{someArray.map((object, i) => {
                return (<span key={i}> {object} </span>); })}
</code>```

As long as someArray remains the same during the lifetime of the component, this is fine; if not, it will cause more re-rendering than necessary when you move, insert or remove items, because all the props of the child change (but in this case you will not notice it at all).

Title: How to map through an array in React without ids?

Body:
You can use the second argument of map, the index:

{someArray.map((object, i) => {
                return (<span key={i}> {object} </span>); })}

As long as someArray remains the same during the lifetime of the component, this is fine; if not, it will cause more re-rendering than necessary when you move, insert or remove items, because all the props of the child change (but in this case you will not notice it at all).

ContentLicense: CC BY-SA 4.0


问:
Setting up OpenFrameworks with Android Studio
I'm in the process of setting up my system to deploy OpenFrameworks apps on Android devices.

I've followed the instructions here to the letter: http://openframeworks.cc/setup/android-studio/

However, whenever I open one of the OF - Android example projects, I keep getting the following error:

I haven't turned up anything yet as far as what the issue may be (and this is my first foray to Android anything). Anyone have an idea?

答:
It could be because there are some spaces in your directory path in "Development Tools" and "3rd Party Tools". I've had weird issues in the past with openFrameworks and Android studio like the one you're having. </p>

<p>Try to put openFrameworks in a path structure without spaces. Maybe clone a fresh version to test. </p>

Body:
It could be because there are some spaces in your directory path in "Development Tools" and "3rd Party Tools". I've had weird issues in the past with openFrameworks and Android studio like the one you're having.

Try to put openFrameworks in a path structure without spaces. Maybe clone a fresh version to test.


问:
Mappers fail for pig to insert data into MongoDB
I am trying to import a file from HDFS to MongoDB using MongoInsertStorage with PIG. The files are large, around 5GB. The script runs fine when I run it in local mode with

```<code> pig -x local example.pig
</code>```

However if I run it in the mapreduce mode, Most of the mappers fail with the following error:

```<code> Error: com.mongodb.ConnectionString.getReadConcern()Lcom/mongodb/ReadConcern;
 Container killed by the ApplicationMaster.
 Container killed on request.
 Exit code is 143 Container exited with a non-zero exit code 143
</code>```

Can someone help me solve this issue?? I also increased the memory allocated to YARN containers but that hasnt helped.

Some mappers are also timing out after 300 seconds.

Pig Script is as follows

```<code>REGISTER mongo-java-driver-3.2.2.jar
REGISTER mongo-hadoop-core-1.4.0.jar
REGISTER mongo-hadoop-pig-1.4.0.jar
REGISTER mongodb-driver-3.2.2.jar

DEFINE MongoInsertStorage com.mongodb.hadoop.pig.MongoInsertStorage();

SET mapreduce.reduce.speculative true
BIG_DATA = LOAD 'hdfs://example.com:8020/user/someuser/sample.csv' using PigStorage(',') As (a:chararray,b:chararray,c:chararray);

STORE BIG_DATA INTO 'mongodb://insert.some.ip.here:27017/test.samplecollection' USING MongoInsertStorage('', '')
</code>```

答:
Found a solution.

For the error

```<code>Error: com.mongodb.ConnectionString.getReadConcern()Lcom/mongodb/ReadConcern;
 Container killed by the ApplicationMaster.
 Container killed on request.
 Exit code is 143 Container exited with a non-zero exit code 143
</code>```

I changed the JAR versions - hadoopcore and hadooppig from 1.4.0 to 2.0.2 and for Mongo Java driver from 3.2.2 to 3.4.2. This eliminated the ReadConcern Error on the mappers!
For the timeout, I added this after registering the jars:

```<code>SET mapreduce.task.timeout 1800000
</code>```

I had been using SET mapred.task.timeout which didnt work

Hope this helps anyone who has a similar issue!

Body:
I am trying to import a file from HDFS to MongoDB using MongoInsertStorage with PIG. The files are large, around 5GB. The script runs fine when I run it in local mode with

 pig -x local example.pig

However if I run it in the mapreduce mode, Most of the mappers fail with the following error:

 Error: com.mongodb.ConnectionString.getReadConcern()Lcom/mongodb/ReadConcern;
 Container killed by the ApplicationMaster.
 Container killed on request.
 Exit code is 143 Container exited with a non-zero exit code 143

Can someone help me solve this issue?? I also increased the memory allocated to YARN containers but that hasnt helped.

Some mappers are also timing out after 300 seconds.

Pig Script is as follows

REGISTER mongo-java-driver-3.2.2.jar
REGISTER mongo-hadoop-core-1.4.0.jar
REGISTER mongo-hadoop-pig-1.4.0.jar
REGISTER mongodb-driver-3.2.2.jar

DEFINE MongoInsertStorage com.mongodb.hadoop.pig.MongoInsertStorage();

SET mapreduce.reduce.speculative true
BIG_DATA = LOAD 'hdfs://example.com:8020/user/someuser/sample.csv' using PigStorage(',') As (a:chararray,b:chararray,c:chararray);

STORE BIG_DATA INTO 'mongodb://insert.some.ip.here:27017/test.samplecollection' USING MongoInsertStorage('', '')

Body:
Found a solution.

For the error

Error: com.mongodb.ConnectionString.getReadConcern()Lcom/mongodb/ReadConcern;
 Container killed by the ApplicationMaster.
 Container killed on request.
 Exit code is 143 Container exited with a non-zero exit code 143

I changed the JAR versions - hadoopcore and hadooppig from 1.4.0 to 2.0.2 and for Mongo Java driver from 3.2.2 to 3.4.2. This eliminated the ReadConcern Error on the mappers!
For the timeout, I added this after registering the jars:

SET mapreduce.task.timeout 1800000

I had been using SET mapred.task.timeout which didnt work

Hope this helps anyone who has a similar issue!


问:
Modify object in container without pointer: vector vs set
I have access to a factory which produces objects in the following way:

```<code>A a = factory.build();
</code>```

I want to store objects of type A in a container, access them, modify their inner state and the next I access the object via the container I'd like to access the same as object as before (with the modified state).
My first thought was to store pointers to A in a container. However, as given above, the factory does not give me a pointer to an object but the object itself.

Class A:

```<code>class A
{
  private:
    int id;

  public:
    A(int id)
    {
      this->id = id;
    }

    int getId() const
    {
      return id;
    }

    void setId(int id)
    {
      this->id = id;
    }
};
</code>```

I figured out that the following works using vector:

```<code>A obj1(1);

std::vector<A> vec;
vec.push_back(obj1);

A & obj = vec[0];
obj.setId(4);

for(std::vector<A>::iterator itr = vec.begin();itr!=vec.end();itr++)
{
    std::cout << (*itr).getId() << endl;
}
</code>```

This prints the modified id: 4.

Is something similar possible using std::set? I tried the following:

```<code>struct AComp
{
  bool operator()(const A lhs, const A rhs) const
  {
    return (lhs.getId() < rhs.getId());
  }
};
</code>```

and

```<code>A obj2(1);

std::set<A, AComp> mySet;
mySet.insert(obj2);

int id = 1;
auto result = std::find_if(mySet.begin(), mySet.end(), [id](A a) {return a.getId() == id;});

A tmp = *result;
tmp.setId(4);
std::cout << tmp.getId() << endl;

for(std::set<A>::iterator itr = mySet.begin(); itr!=mySet.end();itr++)
{
    std::cout << (*itr).getId() << endl;
}
</code>```

Of course this does not change the state of the object in the set. But here I can't say

```<code>A & tmp = *result;
</code>```

This gives me:

```<code>binding ‘const hallo2::A’ to reference of type ‘hallo2::A&’ discards qualifiers
</code>```

How would I achieve this with a std::set?

答:
The error is telling you that *result is a const A& which means you're not allowed to modify the object through this reference.

That's because you aren't allowed to modify objects in a set. If you really want to, then you have to remove and re-insert the object.

Body:
I have access to a factory which produces objects in the following way:

A a = factory.build();

I want to store objects of type A in a container, access them, modify their inner state and the next I access the object via the container I'd like to access the same as object as before (with the modified state).
My first thought was to store pointers to A in a container. However, as given above, the factory does not give me a pointer to an object but the object itself.

Class A:

class A
{
  private:
    int id;

  public:
    A(int id)
    {
      this->id = id;
    }

    int getId() const
    {
      return id;
    }

    void setId(int id)
    {
      this->id = id;
    }
};

I figured out that the following works using vector:

A obj1(1);

std::vector vec;
vec.push_back(obj1);

A & obj = vec[0];
obj.setId(4);

for(std::vector::iterator itr = vec.begin();itr!=vec.end();itr++)
{
    std::cout << (*itr).getId() << endl;
}

This prints the modified id: 4.

Is something similar possible using std::set? I tried the following:

struct AComp
{
  bool operator()(const A lhs, const A rhs) const
  {
    return (lhs.getId() < rhs.getId());
  }
};

and

A obj2(1);

std::set mySet;
mySet.insert(obj2);

int id = 1;
auto result = std::find_if(mySet.begin(), mySet.end(), [id](A a) {return a.getId() == id;});

A tmp = *result;
tmp.setId(4);
std::cout << tmp.getId() << endl;

for(std::set::iterator itr = mySet.begin(); itr!=mySet.end();itr++)
{
    std::cout << (*itr).getId() << endl;
}

Of course this does not change the state of the object in the set. But here I can't say

A & tmp = *result;

This gives me:

binding ‘const hallo2::A’ to reference of type ‘hallo2::A&’ discards qualifiers

How would I achieve this with a std::set?


问:
Android Programming: Alphabetically Order ListView
As the title says, how can I do this?
I've looked but can't find the answer.
It's really annoying me now.
This is for my file browser, I've tried using Collections.sort() on the array that gets added to the ListView but that didn't do anything!

Help :'( :'( :'(

答: You may want to check this existing question: Sorting Android ListView</p>

ContentLicense: CC BY-SA 2.5


问:
How do I add a gap between series in MsChart?
I have created a chart with following code:

```<code>ChartAmalkerd.Titles[0].Text = "xxxx";
        ChartAmalkerd.Series.Add("x");
        ChartAmalkerd.Series["x"].ChartType = SeriesChartType.Column;
        ChartAmalkerd.Series["x"]["PointWidth"] = (0.5).ToString();
        ChartAmalkerd.Series["x"].Points.AddY(10);
        ChartAmalkerd.Series["x"].IsValueShownAsLabel = true;
        ChartAmalkerd.Series.Add("y");
        ChartAmalkerd.Series["y"].ChartType = SeriesChartType.Column;
        ChartAmalkerd.Series["y"].Points.AddY(20);
        ChartAmalkerd.Series["y"]["PointWidth"] = (0.5).ToString();
        ChartAmalkerd.Series["y"].IsValueShownAsLabel = true;
        ChartAmalkerd.Series.Add("y");
        ChartAmalkerd.Series["z"].ChartType = SeriesChartType.Column;
        ChartAmalkerd.Series["z"].Points.AddY(20);
        ChartAmalkerd.Series["z"]["PointWidth"] = (0.5).ToString();
        ChartAmalkerd.Series["z"].IsValueShownAsLabel = true;
</code>```

but the columns are together and there is no any gap between columns.
How do I add a gap between columns?

答:
```<code>chart1.Series["y"].BorderWidth = 2;
chart1.Series["y"].BorderColor = Color.Transparent;
</code>```

works nicely.

Body:
I have created a chart with following code:

ChartAmalkerd.Titles[0].Text = "xxxx";
        ChartAmalkerd.Series.Add("x");
        ChartAmalkerd.Series["x"].ChartType = SeriesChartType.Column;
        ChartAmalkerd.Series["x"]["PointWidth"] = (0.5).ToString();
        ChartAmalkerd.Series["x"].Points.AddY(10);
        ChartAmalkerd.Series["x"].IsValueShownAsLabel = true;
        ChartAmalkerd.Series.Add("y");
        ChartAmalkerd.Series["y"].ChartType = SeriesChartType.Column;
        ChartAmalkerd.Series["y"].Points.AddY(20);
        ChartAmalkerd.Series["y"]["PointWidth"] = (0.5).ToString();
        ChartAmalkerd.Series["y"].IsValueShownAsLabel = true;
        ChartAmalkerd.Series.Add("y");
        ChartAmalkerd.Series["z"].ChartType = SeriesChartType.Column;
        ChartAmalkerd.Series["z"].Points.AddY(20);
        ChartAmalkerd.Series["z"]["PointWidth"] = (0.5).ToString();
        ChartAmalkerd.Series["z"].IsValueShownAsLabel = true;

but the columns are together and there is no any gap between columns.
How do I add a gap between columns?

Body:
chart1.Series["y"].BorderWidth = 2;
chart1.Series["y"].BorderColor = Color.Transparent;

works nicely.


问:
Debugging Task.WhenAny and Push Notifications
I have the following snippet to handle Azure Notification Hub push notifications:

```<code>var alert = "{\"aps\":{\"alert\":\"" + message + "\"}}";

var task = AzurePushNotifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, username);

if (await Task.WhenAny(task, Task.Delay(500)) == task)
{
     success = true;
}
</code>```

Occasionally, this will fail - I'm trying to figure out why ?

What's the best way to get some diagnostic information when running things with Task.WhenAny?

I'd like to know if either an exception was thrown, or if the timeout has been hit.

答:
You basically have three possibilities:

Task.WhenAny(task, Task.Delay(500)) == task is false. It means that the task timed out

Task.WhenAny(task, Task.Delay(500)) == task is true. Then either:

If t1.Status == TaskStatus.RanToCompletion, then the task ran successfully

Otherwise, it's either cancelled or faulted. Check task.IsFaulted and task.Exception to find more information

If it takes > 500ms, I want it to fail, but I want to know that's why it failed

In that case, the only thing you can know is that the notification timed out. There is no exception to log since the task hasn't completed yet. If you want to check the status when it eventually completes, you can chain a continuation:

```<code>task.ContinueWith(t =>
{
    // Log t.Exception
}, TaskContinuationOptions.OnlyOnFaulted);
</code>```

Body:
I have the following snippet to handle Azure Notification Hub push notifications:

var alert = "{\"aps\":{\"alert\":\"" + message + "\"}}";

var task = AzurePushNotifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, username);

if (await Task.WhenAny(task, Task.Delay(500)) == task)
{
     success = true;
}

Occasionally, this will fail - I'm trying to figure out why ?

What's the best way to get some diagnostic information when running things with Task.WhenAny?

I'd like to know if either an exception was thrown, or if the timeout has been hit.

Body:
You basically have three possibilities:

Task.WhenAny(task, Task.Delay(500)) == task is false. It means that the task timed out

Task.WhenAny(task, Task.Delay(500)) == task is true. Then either:

If t1.Status == TaskStatus.RanToCompletion, then the task ran successfully

Otherwise, it's either cancelled or faulted. Check task.IsFaulted and task.Exception to find more information

If it takes > 500ms, I want it to fail, but I want to know that's why it failed

In that case, the only thing you can know is that the notification timed out. There is no exception to log since the task hasn't completed yet. If you want to check the status when it eventually completes, you can chain a continuation:

task.ContinueWith(t =>
{
    // Log t.Exception
}, TaskContinuationOptions.OnlyOnFaulted);


问:
How to achieve unique manyToMany in doctrine
In doctrine I have a manyToMany association

```<code>Document:
manyToMany:
        tags:
          targetEntity: Tag
          inversedBy: tags
          joinTable:
              name: documents_tags
Tag:
manyToMany:
        documents:
          targetEntity: Document
          mappedBy: tags
</code>```

and that creates a new table documents_tags with a primary key on document_id+tag_id and normal keys on each of them. But I would like to have a unique key constraint over the two columns tag_id and document_id. how can I achieve that?

答: ok I can answer it myself, it revealed to me when I edited my question: The primary key already is unique of course, so its working already.</p>

Body:
In doctrine I have a manyToMany association

Document:
manyToMany:
        tags:
          targetEntity: Tag
          inversedBy: tags
          joinTable:
              name: documents_tags
Tag:
manyToMany:
        documents:
          targetEntity: Document
          mappedBy: tags

and that creates a new table documents_tags with a primary key on document_id+tag_id and normal keys on each of them. But I would like to have a unique key constraint over the two columns tag_id and document_id. how can I achieve that?