Tuesday, September 21, 2010
Apple intuitiveness: Upgrading OS X results in downgraded components
To top if off, after upgrading I went to check for updates, there were 776MB of updates (and these are the people who make fun of Windows updates?), and sure enough, Safari 5 was on the list.
So, to recap: I had Safari 5, I upgraded OS X, it got downgraded to Safari 4, then I had to get a 776MB update to get back to where I was before the upgrade. Intuitive or not, I'll let you be the judge xD.
Update. after another 10 minutes, more updates came up, this time an additional 200MB, requiring, of course, that I reboot again.
Friday, March 05, 2010
MissingManifestResourceException was unhandled
There are many articles related to this one but they all point to a different solution than the problem I had, so I figured someone else might run into this
you can get this exception if you declare a class before the code of one of your forms
This will generate the error:
public class SomeTestClass {...}
...
public partial class ConfigurationForm : Form ...
The fix is simple, either move your class after the Form class, or (better yet) move it out to it's own file
Monday, November 02, 2009
Software ever changing truths
Programmers are frequently questioning what is the best way to do x or y, in many cases people will grab the first result from a web search (sounds familiar?), take that as the absolute truth, apply it to whatever problem they are solving and move on with life, though other times the ramifications of such learning experience will carry over much further, maybe the person will write a blog post about it or teach his/her co-workers, thus distributing the knowledge.
Keep in mind that is not always about finding out the best way of doing things, some other times we find out that something is not possible, and this last one might be worst, more so on young developers, learning that something is not possible is very dangerous, have you seen an elephant tied to the tiny stake? it has learned that as soon as it reaches the end of its rope, it can't go any further.
Many of these truths come from respected authorities in the world of software, maybe from the software vendor itself or the official community around it, making matters even more complicated because they are the source and you trust them. The key here is not that you can't trust anyone, it's only that you should not lock that into your brain as the absolute truth, software is always evolving, it's always changing truths.
There are few things that you should take as the absolute truth though ;), among them:
- There's usually no best way of doing things, there's only a better way(s) of doing it.
- Software development is not black or white, in fact I think most of it is gray area.
- There are no hard rules in software development, it'd be too easy if that was the case.
- There is no such thing as an impossible thing, only incapable beings.
- Software is always evolving, what is truth today may not be the truth tomorrow.
Friday, October 30, 2009
Information disclosure: It's everywhere
You might have seen stickers like this in the back window of some minivan and maybe you thought it was funny/cute/stupid, but did you ever think of it as information disclosure? What's the big deal about showing all of your family's names? glad you ask :), let me briefly describe something that happens in Mexico and South America: Virtual kidnapping extortion, criminals will call your phone, tell you that hey have kidnapped your kid (they have the names you graciously provided) and ask you to immediately pay the ransom, when in reality they don't have your kid, but use the emotional momentum to take advantage of you. This is only one example of how they conduct these activities, there are many other ways, and I'm not trying to make you scared of that, but to make a point on information disclosure. It can be found in the most innocent places and if you think this can't happen to you, then you're already very vulnerable.You've also probably seen this:
I couldn't even tell you how many blogs have been hacked because of that (hint: too many), WordPress makes it too easy to break those sites when new vulnerabilities appear (as they do every other week).
I have seen systems where they use some employee id as their login credentials, that id is visible when the computer is locked, and it turns out you can call the help desk, provide them with that id, the person's name, and they will happily reset the password for you.
Unfortunately there are no rules that I can give you or that I have ever seen anywhere to prevent the issue of information disclosure, I'm just trying to raise the awareness on the potential issue that represents having information that bad people can use for malign purposes both in your systems and your own life. The only thing I can tell you is that information disclosure is really everywhere, in your comments, in your configuration files, disclosing the components that your app users, that version, that user id, etc. even in that innocent sticker.
Security does get in the way of usability and usability gets in the way of security, just give it a second thought and be careful out there.
There is no such thing as a secure system, all you can do is raise the bar a little bit more and yes, security by obscurity may be your friend some times.
Wednesday, October 21, 2009
Duct tape programming: Elegant code doesn't pay the bills

Finally decided to jump into the Duct Tape programmer conversation that's been around the internets for the last weeks; talk about flame wars! a large portion of the blogging/twitter community took this post as an attack on TDD, Agile development practices and overall quality software development; which makes perfect sense if you think about it, that's what they sell, that's what they blog and tweet about all the time, so, Joel's post hit some sensitive nerves there. All of those patterns and practices fanboys are trying to convince the world that the duct tape programmers are those who don't care about quality and that they are just writing software that is not maintainable, extensible and all those things that we expect from good software. Those are the same people that quickly dismiss content that is "purely technical", you'll see them talking and talking all the time about good patterns and practices, but not so much about implementations of anything down to the actual code level. I say, theory is good, but without the practice, it's useless.
A brute-force solution that works is better than an elegant solution that doesn't work. Code Complete 2
Now, when you corner purists showing them good results from duct tape programming, they argue that it takes very talented people to pull that off, sure, nobody said it was easy, it takes talent, it takes reading and understanding all those "purely technical content" entries, experimenting, playing, hacking, on the end, software development IS a people problem. I think methodologies are for people who don't have the talent, but that's a whole different topic.
There are no hard rules in programming, it would be too easy if that was the case.
disclaimer: I took the "elegant code doesn't pay the bills" phrase from someone in Twitter, sorry, can't find it now.
Saturday, October 03, 2009
Mac intuitiveness: syncing notes and hard limits

I usually keep around 10 notes on my iPhone, so, of course it's always going to be more than 5 freaking percent, why should it care that I change even 100% of all my notes, just keep a history if that's the concern, the other issue is that if you plug your iPhone in to sync it and walk away, you'll come back one hour later only to find out that it hasn't finished because it is stuck on this stupid dialog. Really bad usability there, hasn't improved even with the countless iTunes updates.
Always remember the least surprise principle.
Friday, September 25, 2009
Apple intuitiveness: The lost OK button

Maybe it's just me, but it took me a long time (and I mean, months) to realize that it wasn't referring to an OK button, just that it was OK to disconnect your device; so much for being intuitive.
But then again, I'm not the only one who thinks that iTunes sucks
Wednesday, September 23, 2009
Ping doesn't cut it for connectivity testing
Friday, July 17, 2009
How to: Save GIF files in MS Outlook

For some reason MS Outlook doesn't give you an
I actually lied on the title, there are ways to save the .GIF files in Outlook, but I'm not going there, there is a much easier way, forward the message to a web-based email account such as Yahoo or Gmail (haven't tried Hotmail, but it probably works there too)
You'll be able to save the files from there as you would expect, with a right click, save file as...
Tuesday, July 14, 2009
Programming is like Chess

anyway, let me elaborate on my analogy
The bad programmer
Arguably the average programmer, makes a move without thinking about the side effects, his capacity of analyzing problems is not all that great, there are so many side effects (breaking code, introducing bugs, security, etc) but this guy is not even aware of most of them, he basically relies on the debugger and if it runs on his machine then is good to go; when stuff inevitably breaks he just goes back and makes another move that seems to fix the problem, if you give this guy a large project it is likely that he'll make a stupid move that will just cause Checkmate on the project
The good
Analyzes different paths and choses the one he thinks is best, this player can play a good game, every once in a while his analysis is not that through and makes some mistakes but he can learn from that, this guy usually delivers good quality software with few bugs that he can go back and fix quickly enough to be acceptable
The best
This guy can make a whole bunch of moves all in his head, he's informed about all the latest techniques to defeat the opponent but he doesn't just rush and use them in a game, he tries them first on his own little projects and ends up using the ones that he proves to be useful, the ones that are shorter, quicker and give him the best return, he knows the techniques to use with the small projects and the ones to be used with large projects, and he knows they are very different, this guy knows what the opponent is thinking, he knows what the opponent will respond to every one of his moves so he usually chooses the best move... he knows the side effects; the "works on my machine" is not on this guy's vocabulary.
As you can see the the main two differences in my analogy are the capacity of analysis (selecting the move) and the awareness of the side effects (what happens when you make that move).
The opponent is your software project, the move is writing the code, the side effects are everything else that is affected by that.
When was the last time that you introduced a new bug fixing that other bug or writing some new functionality? or when *they* found bugs of your code right after it went to production? or when it worked on your machine but not on the server?
Every time you make a move, stop and think about the side effects, there are always side effects, if you can't think of them, there are tools that can help you think better, such as Unit Testing, the more you practice it, the better you'll get at it, I promise
Tuesday, June 30, 2009
Firefox taking a long time to start after upgrading to 3.5
After updating it and running it for the first time, I got this little window
It took me a while to even realize that that little guy was somewhere on my screen, I thought Firefox was just taking a long time to start after the update, then I clicked on the taskbar icon and that's when I saw the little window, I tried to re-size it but it didn't allow me to, all I could do was close the little (attempt of) window, then Firefox ran normal
thought I would blog about it in case this happens to more people
symptom: Firefox takes a long time to start after updating to 3.5
solution: click on the taskbar firefox icon and find the little window on your screen, close it, then Firefox will run normal
Wednesday, June 24, 2009
Are we done with XML yet? hello JINI
One area where I find particularly painful to use XML is on configuration files and my proposal to fix this problem is to formalize a new format, which I call JINI for now. JINI is a subset of JSON similar in simplicity to the good old .ini files and it's used specifically for configuration purposes to replace all those app.config xml configuration files
Benefits
- Simple
- No brackets
- Simple
- Shorter
- Easier to read
- Simpler
- Everything that can be expressed in XML, can be expressed in JINI, but simpler
Too bad "jini" is kinda already taken (2 million results on Google and 714K on Bing say so)
I thought someone would have come up with this idea already, but a quick search gave me nothing, so I thought I would get the ball rolling
what do you think?
Monday, June 22, 2009
How to: Convert DIB to Bitmap
During the weekend a friend asked for some help on code to convert a DIB to a Bitmap in .NET, he had found some code in internet and it almost did everything he needed but the image was getting cut off along the sides, we figured the issue had something to do with getting the pointer to the bitmap, so we digged more and found some more code that then we had to make a couple fixes and changes to get it working. Since I was not able to find a full working solution to the problem I decided to write this post, I saw many people asking the same question in multiple forums so hopefully this will help
First, you’ll need to add System.Drawing.dll to the references of your project, then you’ll need to add the following uses clauses
//Name spaces needed
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
the next step is to declare the BITMAPINFOHEADER structure, this can be declared outside your class:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct BITMAPINFOHEADER
{
public uint biSize;
public int biWidth;
public int biHeight;
public ushort biPlanes;
public ushort biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public uint biClrImportant;
public void Init()
{
biSize = (uint)Marshal.SizeOf(this);
}
}
Then you need to import a function from GdiPlus.dll
//GDI External method needed Place it within your class
[DllImport("GdiPlus.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
private static extern int GdipCreateBitmapFromGdiDib(IntPtr pBIH,
IntPtr pPix, out IntPtr pBitmap);
Now we can get to the actual code to conver the DIB to Bitmap, note the use of a helper function GetPixelInfo, this was the culprit of our issues, and the one we had a hard time finding then getting to work, the function BitmapFromDIB that you’ll find all over the web doesn’t have this code and so it doesn’t work in many cases, in fact the function that you'll find all over the place has a parameter pPix but it doesn't specify how to get this value. This code needs to be declared inside your class
//THIS METHOD SAVES THE CONTENTS OF THE DIB POINTER INTO A BITMAP OBJECT
private static Bitmap BitmapFromDIB(IntPtr pDIB)
{
//get pointer to bitmap header info
IntPtr pPix = GetPixelInfo(pDIB);
//Call external GDI method
MethodInfo mi = typeof(Bitmap).GetMethod("FromGDIplus", BindingFlags.Static | BindingFlags.NonPublic);
if (mi == null)
return null;
// Initialize memory pointer where Bitmap will be saved
IntPtr pBmp = IntPtr.Zero;
//Call external methosd that saves bitmap into pointer
int status = GdipCreateBitmapFromGdiDib(pDIB, pPix, out pBmp);
//If success return bitmap, if failed return null
if ((status == 0) && (pBmp != IntPtr.Zero))
return (Bitmap)mi.Invoke(null, new object[] { pBmp });
else
return null;
}
//THIS METHOD GETS THE POINTER TO THE BITMAP HEADER INFO
private static IntPtr GetPixelInfo(IntPtr bmpPtr)
{
BITMAPINFOHEADER bmi = (BITMAPINFOHEADER)Marshal.PtrToStructure(bmpPtr, typeof(BITMAPINFOHEADER));
if (bmi.biSizeImage == 0)
bmi.biSizeImage = (uint)(((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight);
int p = (int)bmi.biClrUsed;
if ((p == 0) && (bmi.biBitCount <= 8))
p = 1 << bmi.biBitCount;
p = (p * 4) + (int)bmi.biSize + (int)bmpPtr;
return (IntPtr)p;
}
finally, as a plus, what my friend actually needed was to convert from DIB to TIFF, so he wrote a function to do that, this function reuses the BitmapFromDIB function and allows you to set the image resolution
private void SavehDibToTiff(int hDIB, string fileName, int xRes, int yRes)
{
//Identify the memory pointer to the DIB Handler (hDIB)
IntPtr dibPtr = new IntPtr(hDIB);
//Save the contents of DIB pointer into bitmap object
Bitmap myBitmap = BitmapFromDIB(dibPtr);
//Set resolution if needed
if (xRes >0 && yRes>0)
myBitmap.SetResolution(xRes, yRes);
//Create an instance of the windows TIFF encoder
ImageCodecInfo ici = GetEncoderInfo("image/tiff");
//Define encoder parameters
EncoderParameters eps = new EncoderParameters(1); // only one parameter in this case (compression)
//Create an Encoder Value for TIFF compression Group 4
long ev = (long)EncoderValue.CompressionCCITT4;
eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, ev);
//Save file
myBitmap.Save(fileName, ici, eps);
}
//Helper to get Encoder from Windows for file type.
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
for (int j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
and that is it, hoping this will help someone out there
Saturday, June 13, 2009
What are those colors on IE tabs?
I thought this was one of the best features in Internet Explorer 8, but not everyone gets the meaning of the colors on the tabs. The colors represent that the tabs are related, meaning that you followed a link from one page, IE opened another tab and assigned the same color as the previous tab, so that way the tabs that are derived from other tabs are now all grouped and it’s very easy to see this, very useful when you have multiple tabs open for different purposes. I just had to blog this because someone actually asked me what those colors were for, so I figured there’s more people who may have the same question.
Sunday, May 31, 2009
Silverlight how to: Add a user control to another user control
I'm starting to experiment with SilverLight and there's plenty of material out there, but some of the small details are really hard to find. The first application I'm working on requires a couple user controls, one embedded in the other and I spent a couple hours finding how to insert the user control into another control, then to the page, I thought it would be as easy as drag and drop but that didn't work, tried a few other things with no luck, turns out you have to add the namespace to the xaml, similar to the way you declare your controls in ASP.NET
The top xml of a user control (or the Page.xaml which is really just a user control) looks like this:
<UserControl x:Class="MyNameSpace.SomeUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="300">
right after the last line with xmlns, you can type "xmlns:[prefix]=" (where [prefix] is the prefix you want to use in the xml to add your control, and make sure to add the = at the end); intellisense will do the rest, the first line of the drop down will contain the default namespace of your assembly, select that and you're good to go, it will look something like this:
<UserControl x:Class="MyNameSpace.SomeUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prefix="clr-namespace:MyUserControl"
Width="200" Height="300">
You can now start adding your control by typing <prefix: wherever you want to add your control and again intellisense will do the rest for you, you will be able to select any of the user controls that you have created previously under that namespace.
One last thing, if you will be referencing that user control from the code behind, you will need to name your control:
<prefix:MyUserControl Name="myControl" ></prefix:MyUserControl>
Doing so will give you strongly typed access to the instance of the control in your code behind, public members included
myControl.SomePublicMethod(someParameters);
Thursday, April 16, 2009
my solution to Eric Lippert's quiz
The problem:
Write me a function that takes a non-null IEnumerable
(1) If the sequence is empty then the resulting string is "{}".
(2) If the sequence is a single item "ABC" then the resulting string is "{ABC}".
(3) If the sequence is the two item sequence "ABC", "DEF" then the resulting string is "{ABC and DEF}".
(4) If the sequence has more than two items, say, "ABC", "DEF", "G", "H" then the resulting string is "{ABC, DEF, G and H}". (Note: no Oxford comma!)
My solution:
static string JoinStrings(IEnumerable<string> strings) {
int len = strings.Count();
return "{"+(
(len > 1) ?
strings.Take(len - 1)
.Aggregate((string head, string tail) => head+", "+tail)+
" and " +strings.Last()
: (len == 1) ?
strings.First()
: "")+
"}";
}
Thursday, April 02, 2009
public ASP.NET MVC { get; private set; }
The first question that was raised was "can I submit patches?" and the answer is no, however nothing stops you from going and creating your own copy (forking) and start modifying it and redistributing it like this guy has already done.
You can get the source code here.
Did you know? Interface members are allowed to be private
public interface ITest {
void Test();
}
public class Test : ITest {
void ITest.Test() {
Console.WriteLine("test");
}
public void Test2() {
Console.WriteLine("test2");
}
}
class Program {
static void Main(string[] args) {
ITest t = new Test();
t.Test();
Test t2 = new Test();
//t2.Test(); //<<=== doesn't compile
If you don't believe it you can try it of course.
But why is this useful or how do you use this?
The technique allows you to ensure that the method is only visible to those who are using a variable of the interface type. All this does is to force the use of the member through an instance of the interface, meaning, for this example, if you want to get access to the .Test method, you can only do so through a variable of type ITest.
The only trick to make this work is to precede the member declaration with the Interface type as in:
void ITest.Test();
Not the most useful of tricks, but something to have on the bag of tricks, or maybe something to make you win a bet ;)
Friday, March 27, 2009
Do you want to view only the webpage content that was delivered securely? The simple guide
1 - What the heck does it mean.1 - What the heck does it mean?
2 - What they should do to see the full page.
3 - How can they get rid of the stupid message.
They inverted the question from the previous dialog:
"This page contains both secure and nonsecure items.So that more people will just click the default, and by doing so IE will not display the unsecure items on the page.
Do you want to display the nonsecure items?"
2 - I just want to see the entire page, what should I do?
Click NO
3 - How can I get rid of the stupid dialog once and for all?.
The short answer would be: Tools>internet options>security>custom level>display mixed content: Enable.
The long answer is on this other post: How to: Prevent the security dialog about unsecure items in IE
hope this helps! If I didn't answer what you were looking for, please let me know in the comments.
Friday, March 20, 2009
How to: Prevent the security dialog about unsecure items in IE
In my previous post about the new dialog in IE8 about mixed content, someone asked "How can I prevent this message from reappearing?", I thought it would be a good-to-have post and started writing this, but someone else already answered it (thanks Anonymous), in any case, here's what you need to do if you don't want to see that dialog:
tools>internet options>security>custom level>display mixed content: enable
Note that if the site you are visiting is NOT on the internet zone, you would have to make the changes to the appropiate zone:
here's how you tell which "zone" you are on, on the bottom right hand corner of the browser you should see something like this:
If you double click that, you can make changes to the other zones (Local Intranet, Trusted sites, restricted sites)
Just click the zone you want, and it will bring up the first dialog (from this post) where you can make the change.
This applies to IE8, IE7, IE6 (I don't know about older versions)


