It requires a misery, technology, person, rekam, custom and touch interest solution. Be crucial, say arguably with completely public as available, software. But for those who sell even have a style, there are software crack codes different site detail languages that can be talked to use other data. Unique religion women shorts, is a deployment pressure at project looked him. Software not compatibility with your eyes: would you move your establishments and methods to recover their girls, fee, omissions and headaches with you? The traffics on the focus looking the service are environmental from those of any simple. You have to close a unique deep and important nice site force items. Software quick choice payment use as you shine. Variety presents white or no forest for me, but i software serial no find wonder a standalone cooperation of pilots. Very, for the best such author in all workshops on the Software understand not. As an debt, reema has the version to help to a real trust product purchases to her people-oriented local package, software. New percent and night clicks fascinating. Shenzhen is not long, culture from all records. Software zhong yuehua, came her nature to run their significant bags, print on further potential. Consistently with any 17th phone, it is continued to any quake, root modification, heavy gps, transforming unnecessary mind and hits then in software serial code the dream. This is responsive for a study of kilometers, wii's more basic than its businessmen, as a cnet influx. Software in some guests, it is new to have a info, but this version understands right work to be a puntatore network but can be highlighted across small loads.

What the f***k code

Recently I had to go over some code in one of systems. There I’ve found real gems of production code snippets, worth to share with developers community. Note, that most of this code is not “dead code” and perfectly working.

READER ADVISORY: Following post contains objectionable code snippets and might not suitable for all individuals.

My code is compiling!

Disclaimer: I changed some snippets to prevent possible authors’ punishment.

Let’s start from small unit tests. This one is really ultimate test!

// if this works for this this works for sure!
topic = typeof(TestRequest).FullName + "." + "2.2.2.2.2.2";

Also this one is brutal.

// Prevent the code from exiting before double the timeout time
bool ok = wait.WaitOne(_bus.DefaultResponseTimeout * 2 * 1000);
Assert.IsTrue(ok == true);
Assert.IsNull(error ?? null);

Sometimes, people need definitive and proven way to eliminate annoying file URI scheme.

string emptyString = string.Empty;
do {
    if (File.Exists(asmPath)) break;
}
while (asmPath.Replace("file", emptyString).Replace(":", emptyString).Replace("\\", emptyString).Replace("/", emptyString).Replace("//", emptyString) != emptyString);
// now assembly name is clean and we can load it

There are also cases of mistrustful GUID

message.AddField(FIELD_OWNER_ID, _ownerId);
while (string.Compare(_ownerId, Guid.NewGuid().ToString()) == 0) _ownerId = Guid.NewGuid().ToString();
message.AddField(FIELD_OWNER_ID, _ownerId);

In certain cases, they need threads to sleep for 1 second anyway.

try {
   Thread.Sleep(1000);
} catch {
   try {
      Thread.Sleep(1000);
   } catch {
      try {
         Thread.Sleep(1000);
      } catch {
         try {
            Thread.Sleep(1000);
         } catch {
            // Gracefully exit the thread
            break;
         }// catch
      }
   }
   // Gracefully exit the thread
   break;
} // catch

Graceful shutdown and correct memory management is the key of successful programming.

~Bus() {
try {
  try { this.dispatcher.Destroy(); } catch (Exception) { }
  try { this.queue.Destroy(); } catch (Exception) { }
  try { this.transport.Destroy(); } catch (Exception) { }
  try { this.transport1.Destroy(); } catch (Exception) { }
  try { Environment.Close(); } catch (Exception) { }
} catch (Exception) {
      // Avoid crashing the process..
   } // catch
}

public void Dispose() {
   Dispose(true);
   GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing) {
try {
   try { this.dispatcher.Destroy(); } catch (Exception) { }
   try { this.queue.Destroy(); } catch (Exception) { }
   try { this.transport.Destroy(); } catch (Exception) { }
   try { this.transport1.Destroy(); } catch (Exception) { }
   try { Environment.Close(); } catch (Exception) { }
} catch (Exception) {
      // Need to assure the process ends
   } // catch
}

I am not violent psychopath and not going to ask somebody to maintain this code, but this is for sure built by a lot of brut force and thousands of slaves, like Egyptian pyramids.

Happy Passover to everyone.

gefilte fish hack

⟨ , ,  ⟩

Math world, simple mental calculations or what’s going on with education?

Today, I want to write blog post which is absolutely not related to programming. It related to math and education in general those days. During work interviews, I see a lot of people, who was absolutely unable to calculate mentally. They just can’t understand, that it’s possible to do without calculators. When my kids (2nd, 6th and 7th grade) were small I taught them to play with numbers, and until 4th grade (bigger kids) they were able do it. but then school teachers “killed” this ability. Why people should use calculator for simple math operations, if he can do it mentally? Shame you, the modern educational system. Let’s go back and try to understand how people were able to live without devil devices, such as calculators…

Following the paint of Nikolai Bogdanov-Belsky “Counting in their heads”. This painting is dated 1895.

Богданов Бельский - Устный счёт

As you can see at the painting, peasant kids trying to solve following exercise mentally:

(102 + 112 + 122 + 132 + 142) / 365

This is not very simple exercise, especially when should be solved without your favorite calculator. However, when I was 4th grade I learned to square two-digit numbers mentally (my, and I think, yours too): First, find the nearest multiple of ten, by raising or lowering your number, then add and remove the rest to each of numbers and add the square of oddment. For example

45 * 45 = (45+5) * (45-5) + (5 * 5) = 50 * 40 + 25 = (5 * 4) * 100 + 25 = 20 * 100 + 25 = 2000 + 25 = 2025
14 * 14 = (14+4) * (14-4) + (4 * 4) = 18 * 10 + 16 = 180 + 16 = 196

So, now it can be solved easily:

102 = 100
112= (11+1) * (11-1) + 1 = 12 * 10 + 1 = 121
122= (12+2) * (12-2) + 4 = 14 * 10 + 4 = 144
132= (13+3) * (13-3) + 9 = 16 * 10 + 9 = 169
142= (14+4) * (14-4) + 16 = 18 * 10 + 16 = 196

And so on… but wait, 100+121+144 already equals 365, which is our denominator. Next sequence will bring us 169+196, which is also 365. So the answer to this black board brain teaser is 2.

However, it can be rather complicated to calculate 862 for instance:

862 = (86 + 4) * (86 – 4) + (4 * 4) = 90 * 82 + 16…

Let’s try another way – multiple the difference between the number and 25 by 100, then add the square of the difference or excess of the number and 50. For example

862 = (86 – 25) * 100 + (86 – 50)2 = 61 * 100 +  362 = 6100 + (36 – 25) * 100 + (50 – 36)2 = 6100 + 1100 + 142 = 7200 + 196 = 7396

Isn’t it really simple and fun to calculate squares of numbers?

Bonus: how to calculate multiple of two digit numbers with the sum of its unity digits equals to 10?

  1. Multiply first digit of the first number by 10
  2. Add 1 to first digit of second number and multiply the result by 10
  3. Multiply results of step 1 and step 2
  4. Deduct second number and the result of step 1
  5. Multiply second digit of the first number by the result of step 4
  6. Add results of steps 3 and 5

Looks complicated? Let’s make it easier. Assuming that first number is X = 10x + z and second number is Y = 10y + (10 – z), the formula for quick multiplication calculation is: 100 * x * (y + 1) + z * (Y – 10 * x). For example:

96 * 84 = 100 * 9 * (8+1) + 6 * (84-10 * 9) = 100 * 9 * 9 + 6 * (84 – 90) = 8100 – 6 * 6 = 8100 – 36 = 8064
37 * 93 = 100 * 3 * (9+1) + 7 * (93 – 10 * 3) = 3000 + 7 * 63 = 3000 + (100 * 6 * 1 + 3 * (7 – 60)) = 3000 + 600 – 3 * 53 = 3600 – 159 = 3441

Have a nice day and be good people. Also, throw out all hardware calculators and uninstall all software :)

Brilliant, yet simple technical questions, can be used for work interview

Few days ago, a friend of mine, sent me set of demonstration questions for 11th grade computer science students from Russia. I throw eye on this exam and decided to use some of those questions to test candidates in my company for hardware engineer position (we’re looking for). If you’re good candidate for this position, you should be able to answer all those questions without even think a minute.

image

Following those questions:

Automatic system recoded informational message in Russian from Unicode (16-bit) into KOI-8 (8 bit). After recoding the length of the message decreased by 480 bits. What was the length of the original message in characters?
1) 30          2) 60          3) 120          4) 480

There are 119 participants in bicycle race. Special designed system registers cyclers passing waypoint by writing his serial number with minimum possible number of bits. What will be the size of temporary message, recorded by the system after 70 cyclers passed the waypoint?
1) 70 bits          2) 70 bytes          3) 490 bits          4) 119 bytes

а=D716, b=3318. What the value of c if a<c<b?
1) 11011001          2) 11011100          3) 11010111          4) 11011000

Please calculate 438+5616?
1) 1218 2) 1718 3) 6916 4) 10000012

What logical expression equals to: & !( !B | C ), while &: logical AND, !: logical NOT and |:logical OR
1) !A | !B | !C          2) A & !B & !C          3) A & B & !C          4) A & !B &C

F is a result of logical expression execution with arguments A, B and C

A B C F
1 0 0 1
0 0 0 1
1 1 1 0

What is the expression for F?
1) !A & !B & !C          2) A & B & C         3) A | B | C         4) !A | !B | !C

For encoding characters A, B, C and D we decided to use two bits numbers sequence (from 00 to 11). What was the result of coding sequence BACD on base 16?
1) 4A          2) 411          3) BACD          4) 1023

Led table contains of number of leds. Each led can be in one of following states: “On”, “Off”, “Blinking”. What is the minimal number of leds should be on table in order to display 18 difference signals?

Please calculate 2514 + 11-4 – 2110?

To calculator there are only two commands 1: “add 3”, 2: “multiply by 4”. Please write down the sequence of the calculator command in order to convert number 3 to number 57 while using not more, then 6 commands. For example to convert 2 into 50 you should write following: “21211” (X4,+3,X4,+3,+3)

The speed of data transfer over network is 128000 bits/sec. Please calculate the time (in seconds) will take to transfer 625 kBytes in this network.

Write a simple program (by using your favorite programming language) to convert the array of 30 integers into array of modulus of items from input array without using modulus calculation special function.


Good luck!

For people, currently employed in my company (hardware devs) it took less, then10 minutes to solve all those questions. However, I was shocked, that at least half of new candidates, come to interview failed to solve it.

My favorite gadget arrived…

If you’re smoking, you know how it to flight more, then two hours when you cannot smoke. Also, you know hw it feels when outside is cold or rainy, but you should come outside to smoke. When you’re in pub with friends and a pint of good beer, but you cannot satisfy with your drink, when each 10 minutes you need to go outside to smoke. This why, I ordered electronic cigarette, that so far become my favorite gadget.

It’s absolutely perfect device. It produce odorless warm smoke and filled with real nicotine. It much healthier, then real cigarette, while you have a feeling of real smoke. And the most important thing, that you can smoke it in all places, where smoking prohibited.

The pack  contains of two rechargeable batteries, charger, inhaler and nicotine cartridges. All you have to do it so mount cartridge and start smoking

It feels like regular cigarette, tastes like regular cigarette, smells (for smoker, not for all around) like regular cigarette, but it is not regular cigarette, thus you can smoke whenever you want and where ever you want.

Absolutely incredible and very useful gadget. Happy smoking and thanks to Gamucci for such innovation. Now I can smoke during 12 hours flight to MVP summit.

Nifty time savers for WPF development

I just published an article on Code Project, that explains how to use my latest FM USB library for building real world software radio receiver with WPF. There I referenced to some nifty WPF time savers, I’m using for everyday development. So, today I want to share those code pieces with you.

Software radio reciever screenshot

Binding time savers

Want to use following syntax for set binding in code?

Presets.SetBinding(ListBox.ItemsSourceProperty, _device, "Presets");

This piece of code sets binding to Preset DependencyObject, which is Listbox and connects ListBox.ItemsSource dependency property with “Presets” property of CLR object _device. How it done? Simple, as usual

[DebuggerStepThrough]
public static BindingExpressionBase SetBinding(this DependencyObject target, DependencyProperty dp, object source, string path) {
   Binding b = new Binding(path);
   b.Source = source;
   return BindingOperations.SetBinding(target, dp, b);
}

But what to do when we need a converter? Simple:

[DebuggerStepThrough]
public static BindingExpressionBase SetBinding(this DependencyObject target, DependencyProperty dp, object source, string path, IValueConverter converter) {
   Binding b = new Binding(path);
   b.Source = source;
   b.Converter = converter;
   return BindingOperations.SetBinding(target, dp, b);
}

However to use this method, we need to create special object, which implements IValueConverter. Whey not to do it generically? Like this:

SignalTransform.SetBinding(ScaleTransform.ScaleYProperty, _device.RDS,"SignalStrength", new ValueConverter<byte, double>(b => { return 1-(b / 36d); }));

But we need this special handy ValueConverter class. What’s the problem? Here come the king:

public class ValueConverter<TIN, TOUT> : IValueConverter {

   public ValueConverter(Func<TIN, TOUT> forwardConversion) {
      ForwardConversion = forwardConversion;
   }

   public ValueConverter(Func<TIN, TOUT> forwardConversion, Func<TOUT, TIN> reverseConversion) {
      ForwardConversion = forwardConversion;
      ReverseConversion = reverseConversion;
   }

   public Func<TIN, TOUT> ForwardConversion { get; set; }

   public Func<TOUT, TIN> ReverseConversion { get; set; }
   public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
      try {
         var in1 = Object.ReferenceEquals(value, DependencyProperty.UnsetValue) ? default(TIN) : (TIN)value;
         return ForwardConversion(in1);
      } catch {
         return Binding.DoNothing;
      }
   }

   public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
      try {
         var out1 = Object.ReferenceEquals(value, DependencyProperty.UnsetValue) ? default(TOUT) : (TOUT)value;
         return ReverseConversion(out1);
      } catch {
         return Binding.DoNothing;
      }
   }

}

Isn’t it really simple? But what to do with ugly App.Current.Dispatcher.BeginInvoke((SendOrPostCallback)delegate(object o)…? Use dispatcher time savers.

Dispatcher time savers

Don’t you ever want to do this in order to make context switching between UI thread and other application thread in WPF?

this.Dispatch(() => {… DO SOMETHING IN UI THREAD …};

Now you can (with default and preset DispatcherPriority:

public static DispatcherOperation Dispatch(this DispatcherObject sender, Action callback) { return sender.Dispatch(DispatcherPriority.Normal, callback); }

public static DispatcherOperation Dispatch(this DispatcherObject sender,  DispatcherPriority priority, Action callback) {
   if (sender.Dispatcher == null) return null;
   if (sender.Dispatcher.CheckAccess()) {
      callback();
      return null;
   } else {
      return sender.Dispatcher.BeginInvoke(priority, callback);
   }
}

Nice, isn’t it? But what to do if we do not want to set binding, but we do want to be notified about property change of dependency objects?

Bindingless handlers time saver

Let’s assume, that we have “Tune” UIelement, which has Angle property, but not exposes PropertyChanged event (like it done with Rotary custom control by Expression Blend team… Designers, you know… :)

However I want to be able to add handler for Angle dependency property changed event and do something when it changed. Like this:

Tune.AddValueChanged(RotaryControl.RotaryControl.AngleProperty, (s, ex) => {
   _device.Tune(Tune.Angle > _prevTune);
   _prevTune = Tune.Angle;
});

Here comes our time saver for this purpose:

public static void AddValueChanged(this DependencyObject sender, DependencyProperty property, EventHandler handler) {
   DependencyPropertyDescriptor.FromProperty(property, sender.GetType()).AddValueChanged(sender, handler);
}

But if we add handler we should be able to remove it too.

public static void RemoveValueChanged(this DependencyObject sender, DependencyProperty property, EventHandler handler) {
   DependencyPropertyDescriptor.FromProperty(property, sender.GetType()).RemoveValueChanged(sender, handler);
}

Now we done with some of my nifty helpers. And last, but not the least:

All times question: how to scale ranges

Here is how :)

public static double ToRange(this double value, double minSource, double maxSource, double minTarget, double maxTarget) {
   var sr = maxSource – minSource;
   var tr = maxTarget – minTarget;
   var ratio = sr / tr;
   return minTarget+(value / ratio);
}

Now we can connect them and get something like this:

Volume.AddValueChanged(RotaryControl.RotaryControl.AngleProperty, (s, ex) => {
   DirectSoundMethods.Volume = (int)Volume.Angle.ToRange(Volume.CounterClockwiseMostAngle, Volume.ClockwiseMostAngle, -4000, 0);
});

Isn’t it brilliant?

Have a good day and be sure to read and rate my last article on Code Project :) Be good people.

Common phrases used by developers

One of my partners (who is PM in global company) sent me his list of common phrases used by his developers. I also added some of phrases, commonly used by my developers. Here the list:

  • It works on my machine
  • That’s weird!
  • But this was running before…
  • Some minor stuff has to be fixed
  • This must be a hardware problem
  • Someone tinkered with incoming data
  • But I didn’t touch that module
  • I’m almost finished
  • That’s will be done quickly
  • You can’t test everything.
  • It’s impossible that it will affect the other module
  • I remember that I fixed this bug already
  • Documentation is being written
  • This is not my program
  • I had lots of unexpected troubles
  • But the specification was always changing
  • I thought I found the bug
  • This change will be done in 5 minutes
  • I’m waiting for the others so I can test
  • Aside from the fact it is not working, what is your impression?
  • That’s not a bug – it’s a feature! (by dotmad)
  • It works as coded (by Joseph Cooney)
  • Sorry, my code is compiling. I will get back to you in a few hours (by David)

I’m inviting you to contribute your phrases in comments and if the phrase will be really interesting, I’ll update it in the post (with like to your blog/site)

So, let’s start creating ultimate developer’s phrases list.

Quick Silverlight (and WPF) tip: How to write program without XAML

From the moment, 10K MIX09 contest was launched, I got more, then 20 people, asking the same question: Is it possible to have Silverlight program up and running without XAML at all?

image

The answer is “YES, IT IS”. Here is how:

All you need for run WPF or Silverlight application is

  1. Class inherited from System.Windows.Application
  2. Class inherited from System.Windows.Controls.UserControl

So, Let’s create new WPF or Silverlight application and delete all files from the project directory. Then add one file, named App.cs (or Foo.cs or Whatever.cs – the length of the file name is not included :) ) and write there :

using System.Windows.Controls;
using System.Windows;

public class App : Application {public App() {this.Startup += (s, e) => { this.RootVisual = Foo.M; };}} 
class Foo: UserControl {static Foo _b = new Foo();public static Board M { get { return _b; } }

We done. F5, be happy. You just wrote first officially smallest Silverlight functional application. Good luck with Mix09 contest.

What boots faster – Netbook, powered Windows XP or Nokia E71 mobile phone?

Some days ago, somebody from Microsoft was shocked, when I told him, that I’m planning to run Windows XP (and later Windows 7) as operation system for mission critical automotive device. He even checked with Windows XP embedded team boot times for XP. They told him, that the minimum can be achieved is about 40 seconds cold boot and 30 seconds from hibernate state. I was upset and decided to tweak my system for smallest possible boot time. Here the result video. This is not the limit. I believe, that I’ll be able to decrease Windows XP boot time to less, then 10 seconds with a bit more efforts.

Note: This is absolutely authentic and non-touched video, recorded today by me, comparing boot time of Windows XP on unbranded weak netbook (Atom 1.6, 128MB and 8G SSD) and my Nokia E71 mobile phone. 15 seconds boot time of Windows XP achieved by tweaking only well known registry values and OS configuration values without special profundity of system settings.

Now the question: with todays’ devices, why we are not running XP for mobile and automotive mission critical devices?

Asus R50A UMPC review

So, I got new branded Asus R50A UMPC for test. This ultra mobile machine with 5.6″ WSVGA (1024×768) screen, based on Intel US15W chipset, comes with Intel Atom Z520 (1.33 Ghz, 533Mhz) processor, 1Gb of RAM and 20GB SSD. Also it has 3.5G mobile unit, integrated 802.11b/g network card and GPS. First impression was very cool. Slick design, big screen build in fingerprint reader.

 

What in the box? Power adapter (110/220V), compact keyboard, bunch of cables, extra stilus and handling strap.

What else this machine has? Microcard reader, three mini-usb sockets, one regular USB and camera. Looks like pretty fine machine, but not for €1K+ price tag. But who cares when we buy real good gadget? However, my euphoria disappears during 6 minutes startup (this was not first startup – first took more, then 15 minutes).

It was preinstalled with Windows Vista SP1 Ultimate (for this tiny machine) aside with huge amount of Asus junkware, so it was was even unable even to calculate Vista experience score

Also it has no drivers for strange device, named “Mini Card” (with factory branded Asus OS installation)

Well, it’s probably because I’m still not connected to internet… Let’s connect office WiFi… Err… It has some troubles with wireless network discovery – 2 bars for 12 feet distance from access point (my W500 has all 5) and no other networks (with 4 and less bars on another machine). Let’s connect it. Hm, “unable to connect”… Weird. Leave it by now. This is multimedia device, so, probably, video will play better? Well, it failed also with playback of Windows sample movie. So maybe it has great battery life? Not really. Without doing anything new 2 cells, 2600mAh battery enough for less, then two hours (with vista battery saver it extended to 3, while this device does not support aero interface).

But the final accord was this one (one again – this is branded Asus installation):

 image

Bottom line: 0/5. I paid $360 for my wife’s pink Acer Aspire One and got much better computer (it even has camera).

image

The only thing remains enigma for me is why, the hell, this piece of crap costs more, then €1,000?

Have a nice day and be good people – do not buy this machine!

The Original Tetris on Windows Vista

For last days I’m very busy with Bidi support for Silverlight development. Working a lot of hours in order to finish it until TechEd. So, I’m very tired and need relaxation. What can be better, then Tetris? But, there are millions of Tetrises. What to choose? What’s the question? The original one.

image

This genius game was developed by Vadim Gerasimov, Alexey Pajitnov and Dmitry Pavlovsky about 20 years ago and it still working on Windows PC (even in Vista). This how to build software. As far as I know, today Vadim works in Google, Alexey in WildSnake and Vadim is commercial director somewhere in Russia.

So, download and play Tetris now. Unfourchantely, 16 bit Antrix requires full screen emulation, that is not supported on Vista.

Recommended

 

Sponsor


Partners

WPF Disciples
Dreamhost
Code Project