{ Code: Impossible } | this = HowI.Roll();

Archive for April 2008

Apr/08

20

Red Pepper Omelette

This recipe serves 2 people and is an excellent Sunday morning breakfast treat.

Ingredients:

  • 2 Red Peppers
  • 1/2 Yellow Pepper (Roughly Chopped)
  • 1/2 Orange Pepper (Roughly Chopped)
  • 1 Ham Steak (1/4″)
  • 2 Eggs
  • 1/4 Onion (Roughly Chopped)
  • 6 Asparagus Stalks (cut into small bite-sized pieces)
  • 2 tablespoons Olive Oil
  • 1/2 cup sliced Asiago cheese
  • 1 teaspoon salt
  • 1 teaspoon pepper

Begin by cooking the ham steak over low-medium heat. You will want to brown it on both sides (5-6 minutes on each side). Sauté the asparagus, onion, yellow and orange peppers in heated olive oil along with the salt and pepper for 5-7 minutes. The asparagus should still be crisp.

Remove the tops and centers of the red peppers taking care not to pierce or damage the sides of them. These will serve as your bowls for the dish.

At this point it is safe to start the eggs. I scrambled mine with a little butter and salt but you may want to use a sunny-side-up presentation which will work well too. Check the ham and after it has browned on both sides remove it from the heat and begin cubing it.

When the eggs are just about done it will be time to start plating. You will start by layering the ingredients in the following order (bottom to top) in each red pepper: Vegetables, Ham, Asiago cheese and finally the eggs. Garnish with a sprig of thyme and you are all set. Enjoy!

No tags

Apr/08

8

Enumerate windows users' groups

The code below will enumerate which groups a domain / local user belongs to.

[sourcecode language="csharp"]

private static string GetUserGroups(string strUser)
{
string groups = “”;
DirectoryEntry de = null;
try
{

string entryName = String.Format(“WinNT://{0},user”,
strUser.Replace(“\\”, “/”));

de = new DirectoryEntry(entryName);

object oGroups = de.Invoke(“Groups”);
foreach (object o in (IEnumerable)oGroups)
{
DirectoryEntry group =
new DirectoryEntry(oGroups);
groups += group.Name + “,”;
}
}
catch (Exception)
{
throw;
}
return groups;
}

[/sourcecode]

·

Just in case you ever want to convert a binary representation of a Windows Security Identifier (SID) to it’s friendlier string version:

Imagine we have a binary sid that is:

0x010500000000000515000000F2EBB9149329116C5E3528360E040000

That doesn’t look too inviting does it? Lets break it out into segments for easier reading.

0 [0x01] 
1 [05] 
2 [000000000005] 
3 [15000000] 
4 [F2EBB914] 
5 [9329116C] 
6 [5E352836] 
7 [0E040000]

Segments 0 through 2 are used by Windows to validate the SID. 0 is the version number of the SID; currently, all Windows operating systems use “1″ as the version. 1 tells us that there are 7 segments in this SID (number of dashes minus 2). Segment 2 states that this sid has a top level authority of 5 which equals SECURITY_NT_AUTHORITY. (for a better description of what each security authority does please see this KB article)

Segments 3 through 6 are little-endian 32-bit integers that describe the issuer of the SID. 7 is a 32-bit little-endian integer called the “Relative ID”. This value is the id of the user on the machine that issued the SID. It is important to remember that these values are stored as little-endians because this will factor in when we translate them into the final SID.

the first part of the sid is the easiest to translate. In our example sid above the first 3 segments become “S-1-5″ because every sid is prefixed with “S” and we drop segment 3 as it is only used in validation. The next part is where we translate the machine id and user id and this can be confusing when done for the first time. Since the values are stored in little-endian format we have to reverse the order of the bits so:

  • 15000000 becomes 00000015 which translates to (hex to dec) 21
  • F2EBB914 becomes 14b9eb2f which translates (hex to dec) to 347728882
  • 9329116C becomes 6c112993 which translates (hex to dec) to 1813064083
  • 5E352836 becomes 3628355E which translates (hex to dec) to 908604766

Now we have our machine identifier and our SID is now

S-1-5-21-347728882-1813064083-908604766

All we have to do now is translate the user id which follows the same process as the machine id so:

  • 0E040000 becomes 0000040e which translates (hex to dec) to 1038

So we are all done and our final sid is:

S-1-5-21-347728882-1813064083-908604766-1038

Apr/08

6

Care about your code

Jeff Perrin posted a great one-liner today:

Write code as if you care what others think about what you’ve written.

I couldn’t agree with this sentiment more. I do this at work all the time. I worry about what my peers will think when they look at the code I’m writing. And you know what? It really helps me to take extra steps to ensure that the code I write is code that I wouldn’t worry about handing off to a fellow co-worker.

I think all developers should take Jeff’s advice and embrace self conscious development.

Apr/08

6

Our roommates

Just testing out this new gallery system, posting some pictures of our two roommates: Manny (the large all black cat-in-the-box) and Shiva (the White, Grey and Black lazy girl on the pillow).

No tags

Older posts >>

Theme Design by devolux.nh2.me