26May/17

My Favorite X-Plane 10 / 11 Controls – Rudder, Joystick & Throttle Setup

I do not take credit for this controller layout. I really like it and would like to have a copy easily available so I hosted it here, also I would like to share with you all my favorite controllers. These have been designed by Catstrator, all credit goes to him (if you see this, I hope its okay that I am using this). Full credit goes to you good sir!

Xplane Controls (credit goes to catstrator) – click on picture to enlarge

Joystick & Throttle: Saitek Pro Flight X-55 Rhino H.O.T.A.S. (Hands on Throttle and Stick) System for PC

Rudder: Saitek Pro Flight Rudder USB Pedals (these are different than the picture, however they both support Yaw & Left & Right Toe Break)

Setup Video for X-Plane 11 (there is also one for X-Plane 10 on his channel): https://www.youtube.com/watch?v=hFn-zztS5ho

 

26May/17

Repeat Command Until Success – recursive method – rrsync, repeat, repeatrecurse

Here I show you how to repeat a command until it finishes successfully. This should only be done with programs that support resume and also have legit exit codes (or else they might run on for forever – read on). I show how I constructed such a function, by first showing how to create a function that repeats rsync only. Then we build a function that can repeat anything.

Sometimes you will run a command and it will fail. However you can repeat that same command to resume it where it left off. A good example is “rsync”. rsync can be made to resume from where it left off – I use the partial option (-P gives progress bar and partial option at the same time). This can be done with any command that supports resume and has good exit codes (meaning success is 0, and fails are none 0).

Two criteria for this to work

  1. supports resume in a good way (cp supports resume, but its not good – see below, rsync supports good resume)
  2. has good exit codes (0 is success, none-zero for none-success)

Note that “cp” is not a good example of a command that can resume where it left off (even if you use -u), because it will skip the files that where partially copied. So if you have 10 big files, and the “cp” got cut off mid 5th file, when you repeat the command, it will just continue with the 6th file. The 5th file will be incomplete.

We will use a recursive method to do this repeating resume operation.

RRSYNC – Repeating Rsync

First I will show how to do this with rsync. We basically run rsync, then if its exit code is zero we exit out, if its exit code is none zero we repeat the function.

Check the comments for how to run it. Basically you would first copy paste that function into a shell and then run this  rrsync 1 -avhP <src> <dest> . Also if you had the above code in a script file. Such as rrsync.sh. You would need to source the script first to get that function to be available in the shell source rrsync.sh  or the shorthand way . rrsync.sh

Note I decided to keep track of a variable (so that I can show which run number this is), and the only way to do that within a recursive function is with global variables, or a variable that you pass on to the next level. Since I didnt want to use global variables, I just passed it on to the next level, the caveat is that we have to specify the start value of this variable when we begin (hence the 1 before the arguments)

REPEAT function

The next code allows me to repeat any function. I didnt want the user to worry about having to provide 1 all the time, so I created a starting function called “repeat”, which calls the code that does everything “repeatrecurse”.

So copy&  paste the above two functions into a shell to source them (or source them thru a script with the source  bash builtin), so that you can use repeat. Then to utilize the repeat function do this:

Rsync will then repeat until success.

You can test the code by creating two small functions one which always returns success (exit code 0, so it will only run once), and one that will always return none-success (none-zero exit code, so it will run forever until someone presses Control-C or kills it)

You can test them like so

Here we show how it runs once when we have a successful end

Here we show how it repeats

The end

 

21Oct/16

FreeBSD – Show info about running process – SIGINFO

When you are running a command hit Control-T anytime, its very useful when a command looks stuck.

It causes the kernel to spit out a line similar to the following:
load: 0.69 cmd: awk 56538 [piperd] 0.96r 0.00u 0.00s 0% 2380k

Shows load 1m load-average (“load: 0.69”), the ucomm (utility basename) of the running process (“awk”), the process ID (PID) of the running process (56538), the wait channel or wchan status (“piperd” for pipe read), the real number of seconds the command has been running thus far (“0.96r”), the user seconds (“0.00u”), system seconds (“0.00s”), CPU utilization (0%) and rss or resident set memory size (“2380k”)

That line comes from the kernel and not a sub-process, userland process, nor forked process

When you get more than just the “load: …” line out of a Ctrl-T, for example… “sleep: about 99 second(s) left out of the original 100”

The extra information comes from the running process itself responding to a SIGINFO that was generated by the kernel and sent to said running process (following the initial strike of Ctrl-T and printing of “load: …” line)

Ctrl-T does not and cannot interfere with a running program

27Sep/16

Enable Mouse Scrolling with Screen (tested in Putty)

Screen the app that can split screens like so, is not too intuitive when it comes to scrolling thru your bash shell. Notice where the cursor is in the diagram below, its in the top right window, sitting at an empty prompt right after an ls -1 was run. Lets say I wanted to scroll up. I cant use the mouse wheel (yet), however I can use Control-A [ and then use the arrow keys to scroll up and down (pressing q when im done)

By default mouse wheel support is not enabled.

To enable mouse wheel support in screen you will need to add the following lines to your screen configuration file ~/.screenrc. I would also recommend to make sure you have the latest version of screen installed (I am using 4.04).

I just put the following two lines in my .screenrc in my $HOME dir (thats all thats in my .screenrc)

I tested and this and it works with Putty. This should also work in Max OSX and also with Cygwin.

Sidenote: I might actually be misleading you and it might not work so well when you have screen doing window splits. However it works well when the windows are not split. Thats for you to test and find out.

Some other recommendations, that I have seen, are to launch screen like so:

Sidenote: If you are already in a screen session when you make these changes, you will not see them be activated, first you need to detach, and then reattach to your screen session. Detach screen like so: Control-A followed by little d  (a.k.a. Control-A+d, or simply ^A d). Then create the file ~/.screenrc (if doesnt exist, and if it does, just add those lines). Finally reattach to your screen detach with screen -x (which will reattach to your last session). If you have several detached screen sessions then you can use screen -ls to see all of your screen session listings. You can connect to different screen sessions by their ID screen -x ID (example: screen -x 9532). Where ID, you get from screen -ls.

Sidenote: try the scroll wheel in a new screen session. If your having troubles not getting mouse wheel support after editing the file, maybe kill all of your screen sessions and try it.

The end.

20Sep/16

Show and Print Tabs in Linux and Freebsd

To print tab characters (and other control characters) you cant just press Tab because tab is a special auto complete char in bash.

Control-V then Tab or Control-V then Control-I (also known as ^I) – Tab character – so to print a Tab character you can use both of these combos

Example:

echo “Here comes a tabControl-V then Tabwhatever”

Will show: as echo “Here comes a tab      whatever”

Hitting enter you will see

Here comes a tab     whatever

Sidenote: In this article I actually used spaces to represent a tab (whatever, whocares)

Sidenote: if you select the tab character from the shell (by dragging a box around the echo or around the output) and paste it within a putty again it will actually put spaces into clipboard, but using bash history with up and down arrows you will actually have the tabs preserved. So with clipboard the tabs turn to spaces, but in bash history its actually shown as Tabs.

So to the outside viewer a tab or a few spaces look similar, so how do you distinguish them? One way is to add some characters and see how tab jumps things around more than a few character spaces (where as space always just keeps the same distance)

The best way, in my opinion, is to pipe the output of whatever text into cat -tevu (the t specially will convert all Tabs into ^I)

echo “Here comes a tabControl-V then Tabwhatever” | cat -tevu  (the bold are special keys to press)

Here comes a tab^Iwhatever

The ^I means tab, a single tab char. If I saw ^I^I that means there were two tabs (Control-V then Tab, followed by Control-V then Tab again, will get us two tabs on the shell)

sidenote: there are other control characters, not just tab, for example ^X (control-V control-x) is the delete character it will show up as ^X but it will act as a delete in the output. cat -v shows those.

09Sep/16

FreeBSD missing tee and tee append – make tee bash functions

The version of FreeBSD 8.0 that I am using is missing tee & tee -a (tee append)

You know tee as in write on screen & file:

date | tee thedate.txt

Which will run command date and show its output on the screen (stdout) and also write that same output to thedate.txt. tee and tea read in via STDIN supplied by the Pipe. Recall that Pipes connect the STDOUT of the left side (date) to the STDIN on the right side (tee). Pipes operate on the send STDOUT, not STDERR, so you might be missing some precious error output (error messages, debug messages, and help messages are sometimes output as STDERR with nix systems). To get STDERR into the TEE you have to do this little trick.

date 2>&1 | tee thedate.txt

Which says STDERR (2) output should also go to the address (&) of STDOUT (1).

The tee you are familiar can be run as tee filename or tee -a filename, where -a appends to an existing file where as regular tee (Without -a) writes to a new file (and if file exists it truncates,deletes, old contents)

Here are the two as two seperate bash functions. tee for regular tee. And tea for append tee.

 

Enjoy

Use like:

date | tee thedate.txt

Which will show the date on the screen and save it to file. Repeating command will update the date string inside the file.

date | tea thedate.txt

Which will show the date on the screen and save it to file. Repeating command will append the new date string inside the file.

06Sep/16

Sed replace new line with any text

Source: http://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed

Replace with space:

Use this solution with GNU sed:

Here is cross-platform compatible syntax which works with BSD sed (FreeBSD 8 confirmed):

Replace with double dash:

Use this solution with GNU sed:

Here is cross-platform compatible syntax which works with BSD sed (FreeBSD 8 confirmed):

 

10Aug/16

Nohup Alternative

Learned it from here http://stackoverflow.com/questions/6168781/how-to-include-nohup-inside-a-bash-script They use it to make current script daemoned but you can also make scripts that you run from within a script daemoned

Instead of doing

or

which is 

NOTE: > whatever 2>&1  is the same as &> whatever  in bash4 and ahead

Interesting alteranative

You can use redirects and disown instead of nohup

or:

or if you want output:

You run process with /dev/null for input and output which unties it from output and input (you can give it some output if you want by modifying > or 2> or &>, just make sure to untie the input of stdin by doing </dev/null). Then we run it into background with &. Then we disown it (untie it from shell, so if shell turns off the process still runs).

The End

10Aug/16

Best way to protect against Ransomware – Backups and Snapshots

You’ve been hearing about Ransomware attacks (they are  attacks that target your files and encrypt them and make you pay money to hidden organizations to get your files back – at first they targeted regular consumers like you and me and now they are targeting more and more businesses.)

How can you protect yourself against Ransomware Attacks? UPDATE:

SIDENOTE: protect is the wrong word, as you might still get attacked. However using the techniques below you will be able to recover from a hack without paying the ransom & without much effort. The line should instead say:

How to recover from a ransom ware attack?

  • Backups
    • Have a local backup
    • Offsite back
    • Not enough can be said about having backups. They are not just good for Ransomware attacks. They are good for all sorts of data and intellectual property protection.
  • Snapshots
    • Filesystems like ZFS and BTRFS support Readonly snapshots. They take backups of your files point-in-time and nothing can touch them. Ransomware cannot penetrate the filesystems readonly barrier. Ransomware attacks operate on common protocols like Cifs/Samba. If your ZFS and BTRFS snapshots are not exposed or are readonly the attack vectors cant change your files.
    • Store your important data on file servers or systems that support snapshots. Setup Hourly or Daily snapshots. Snapshots are great because if there are not alot of changes they dont take up much space

So now if you get attacked all you have to do is just look for your original un-encrypted file in your snapshots or in your backups.

UPDATE: Its been brought to my attention that using above techniques do not protect you from the actual hack happening. That is true. The above solutions are only a cure to if you got already hacked. Either way its good to have backups and good to have snapshots. The above are not like a vaccine that will prevent the issue indefinitely. However I would like to mention, in a perfect world we would have both the cure and vaccine. Ransomware is constantly evolving, so your network security and computer security would have to stay ahead of that all of the time. Most of the common Ransomware hacks are fought by common security tools and common network security appliances, so keep those up to date, and make sure to have those in place & your chance of being compromised decrease.

05Aug/16

Guide to Fixing Audio Out of Sync in VLC

Watching a video and your audio and video are out of sync. Try reloading video. If that doesn’t work try the audio delay option (which will delay the audio by 50 millisecond increments = 50ms increments). By default the audio delay option is set to 0 (or off)

You can have negative audio delay, or positive audio delay.

Pressing j will give you more negative audio delay. So you can go from 0 to -50ms to -100ms to -150ms etc. This brings the audio back.

Pressing k will give you positive audio delay. So you can go from 0 to +50ms to +100m etc. This moves the audio forward.

Imagine that the video and audio are on two different stills. You cant control the video still with this option, you only control the audio still. The video still is controller by when you play the video (rewind, fastforward, play and pause)

How to tell if you need to go negative or positive:

Look at the video and listen. Watch the way people say things or wait for an audible action (like a light switch being turned on, or somebody dropping something).

First we find out if the audio is behind or ahead of the video. Then before changing try to count off in your head the delay time. Remember that you change the delay in 50ms increments. 1000ms is 1 second. 1second delay is very noticeable. Even 100ms is noticeable. Im working with a video right not is 600ms off sync (the video comes first, so I have to put in -600ms audio delay to line it up)

If you notice that the video happens first then a few split moments later the audio follows. Then you can fix it by brining the audio back (back = negative), so press the j button.

If you notice that the audio happens first then the video follows, you can fix that by brining the audio forward (forward = positive), so press the k key.

Tip: when trying to find the delay and adjust it its good to know a few good hot keys (not just the j and k). First find a good point in the video (i.e. light switch is turned on, and there is clear audio and video; the click and light change should be on top of each other; or people speaking and you hear their voices and their mouths moving). You can pause on that moment with Spacebar. You can rewind a few seconds with Shift + Left Arrow. You can rewind even more by holding Shift and pressing the Left Arrow a few times. You can fast forward in a similar manner with ShiftRight Arrow.

Sidenote: the human ears are pretty good at fixing most delay and out of syncs, so we just need to get in the ball part within 100ms. So if the audio is actually 633ms behind the video. You can get away with -600ms and -650ms and -700ms. -650 will obviously be better.

Sidenote: this guide says to use the f and g keys. f is for negative, g is for positive. Might be the old keys: https://wiki.videolan.org/Adjust_Audio_Delay/