How can I capture the stdout from a process that is ALREADY running

True solution for OSX Write the following function to your ~/.bashrc or ~/.zshrc. capture() { sudo dtrace -p “$1” -qn ‘ syscall::write*:entry /pid == $target && arg0 == 1/ { printf(“%s”, copyinstr(arg1, arg2)); } ‘ } Usage: example@localhost:~$ perl -e ‘STDOUT->autoflush; while (1) { print “Hello\n”; sleep 1; }’ >/dev/null & [1] 97755 example@localhost:~$ capture … Read more

Capture incoming traffic in tcpdump

In Bash shell try this: tcpdump -i eth0 tcp and dst host $MyIpAddress and not src net $MyNetworkAddress/$myNetworkBytes or this equivalent formulation: tcpdump -i eth0 ip proto \\tcp and dst host $MyIpAddress and not src net $MyNetworkAddress/$myNetworkBytes On my system this resolves to something like: tcpdump -i eth0 tcp and dst host 10.0.0.35 and not … Read more

How can I capture which direction is being panned using UIPanGestureRecognizer?

On UIPanGestureRecognizer you can use -velocityInView: to get the velocity of the fingers at the time that gesture was recognised. If you wanted to do one thing on a pan right and one thing on a pan left, for example, you could do something like: – (void)handleGesture:(UIPanGestureRecognizer *)gestureRecognizer { CGPoint velocity = [gestureRecognizer velocityInView:yourView]; if(velocity.x … Read more

Capturing image from webcam in java?

This JavaCV implementation works fine. Code: import org.bytedeco.javacv.*; import org.bytedeco.opencv.opencv_core.IplImage; import java.io.File; import static org.bytedeco.opencv.global.opencv_core.cvFlip; import static org.bytedeco.opencv.helper.opencv_imgcodecs.cvSaveImage; public class Test implements Runnable { final int INTERVAL = 100;///you may use interval CanvasFrame canvas = new CanvasFrame(“Web Cam”); public Test() { canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); } public void run() { new File(“images”).mkdir(); FrameGrabber grabber = new OpenCVFrameGrabber(0); // … Read more

Regex group capture in R with multiple capture-groups

str_match(), from the stringr package, will do this. It returns a character matrix with one column for each group in the match (and one for the whole match): > s = c(“(sometext :: 0.1231313213)”, “(moretext :: 0.111222)”) > str_match(s, “\\((.*?) :: (0\\.[0-9]+)\\)”) [,1] [,2] [,3] [1,] “(sometext :: 0.1231313213)” “sometext” “0.1231313213” [2,] “(moretext :: 0.111222)” … Read more