Archive for the ‘Uncategorized’ Category

Ghost linux exploit on Ubuntu 12.04 and 12.10

If you have a version of Ubuntu that old, you usually cannot even run the ‘fix’ all the blogs are talking about. Everyone advices;

apt-get clean; apt-get update; apt-get upgrade

but that will probably give you a lot of file not found. When you update to the old distro repository for Ubuntu there is a good chance, especially on 12.10 that it will tell you libc is fine and updated already; no newer versions while the ghost test script tells you it’s vulnerable.

What to do then is

do-release-upgrade

and follow the steps. Things to notice;

– if your connection cuts out you have to SSH back in via the extra ssh session on 1022 and run screen -r to continue
– when you get the question that the boot drive is no longer found (happens in a read config / udev situation), just pick the drives the boot up raid device is built from, all of them, to place grub on

After this the test script will report you are ok and you can sleep again.

Bulk extract MP3 from MKV

Because I always spend too much time on finding this script and some computers I have I cannot really update ffmpeg anymore, here is a conversion method using an old mplayer & lame I thought I would share;

  1. #!/usr/bin/perl
  2.  
  3. @x = `find .|grep mkv\$`;
  4. print `mkdir encdir`;
  5. foreach(@x) {
  6. chomp;
  7. $f = $_;
  8. /.*\/(.*).mkv/;
  9. print "$1\n";
  10. $wav = "encdir/$1.wav";
  11. $mp3 = "encdir/$1.mp3";
  12. next if -f $mp3;
  13. $mplayer = "mplayer -vc dummy -vo null -ao pcm:file=\"$wav\",fast \"$f\"";
  14. print `$mplayer`;
  15. $lame = "lame -h -b128 \"$wav\" \"$mp3\"";
  16. print `$lame`;
  17. print `rm "$wav"`;
  18. }

UITableView not showing data / refreshing while data is there

Was in Xamarin, but the same issue applies to ObjC/XCode. 

It was a late night on the 25th and when I got up quite early the 26th to some inspiration for coding I added a UITableView like I did so many times before. I added the source and thought all was fine. But it didn’t work. It didn’t show anything.

First I decided to view.SetNeedsDisplay() and that actually then did show the table, but without any data. Just a BackgroundColor rectangle. At least now it had BackgroundColor and not white (the color of Superview.BackgroundColor).

After a lot of swearing I found that;

  1. this.ReloadRows (new NSIndexPath[]{ NSIndexPath.FromItemSection (0, 0) }, UITableViewRowAnimation.None);

would actually load and show all data.

But the table wouldn’t scroll and you could not select any rows; this, in my tired mind, made an alarm go off. I did this so many times before and it always worked, this time it didn’t and all stackoverflow answers where based on mistakes I had not made for a long time, so it must be another mistake.

It took me 1 hour to figure out what was going on as I did not know that tableviews who do not receive inputs do not get refreshed which is related to the UIViews which receive no inputs not getting they LayoutSubviews() called.

Long story short; the UITableView was in a UIView which was not big enough and ClipToBounds was false, so it did show up but nothing else. My overlapping tools and debugging tools did not detect this, so I lost any hour.

In my library I have all Apple view classes inherited by my own for tooling, debugging and convenience methods, so it was not hard to fix this once and for all by overriding Frame{get;set;} and, for DEBUG add the following which warns me and makes sure I actually checked everything (ShowStack is an Extension which allows me to see the linenumber + file name the issue happens to be appear in);

  1. public override System.Drawing.RectangleF Frame {
  2.             get {
  3.                 return base.Frame;
  4.             }
  5.             set {
  6.                 base.Frame = value;
  7.  
  8.                 if (Superview == null)
  9.                     return;
  10.  
  11.                 if (value.X < 0
  12.                     ||
  13.                     value.X > Superview.Frame.Width
  14.                     ||
  15.                     value.X + value.Width > Superview.Frame.Width
  16.                     ||
  17.                     value.Y < 0
  18.                     ||
  19.                     value.Y > Superview.Frame.Height
  20.                     ||
  21.                     value.Y + value.Height > Superview.Frame.Height) {
  22.  
  23.                      this.ShowStack   (“Warning: Frame is out of bounds of the superview frame:+ this.ToString() + “ trying to fit in+ Superview.ToString(),1);
  24.                 }
  25.             }        
  26.   }

Edit: The data loading issue is not related to this, but I don’t know yet what it is related to. I just call ReloadRows for now as I have no time to debug it.

Xamarin / make a little debugging tool for MKMapView / maps when you don’t want to spend actual time moving around

When you are making an app with GPS routes and you want to create test data (for unit tests or just testing without moving around), you can use the following code;

In ViewDidLoad or whatever used to initialise the view, put:

  1. var tapRecogniser = new UITapGestureRecognizer(this, new MonoTouch.ObjCRuntime.Selector(“MapTapSelector:));
  2.  
  3.             map.AddGestureRecognizer (tapRecogniser);

And somewhere in the same class;

  1. [Export(“MapTapSelector:)]
  2.         protected void OnMapTapped(UIGestureRecognizer sender)
  3.         {
  4.             CLLocationCoordinate2D tappedLocationCoord =  map.ConvertPoint(sender.LocationInView(map), map);
  5.                
  6.             locations.Add (tappedLocationCoord);
  7.  
  8.             HandleDidUpdateUserLocation (this,
  9.                 new CLLocationsUpdatedEventArgs(
  10.                     new CLLocation []{
  11.                         new CLLocation(tappedLocationCoord.Latitude, tappedLocationCoord.Longitude)
  12.                     }
  13.                 )
  14.             );
  15.  
  16.         }

In my case

  1. List<CLLocationCoordinate2D> locations

which contains all the already clicked locations so we can draw a nice path from all taps which is the same as  say a run or a walk or a drive. Add some small debugging fields for speed and altitude and you can test most real life situations.