"Community commands (those hosted on individual servers, locally, or on the herd), however, cannot be localized at this time." (via: Labs/Ubiquity/Ubiquity 0.5 Making Commands Localizable - 09.07.10)Maybe soon...
"Community commands (those hosted on individual servers, locally, or on the herd), however, cannot be localized at this time." (via: Labs/Ubiquity/Ubiquity 0.5 Making Commands Localizable - 09.07.10)Maybe soon...
In one of my projects, I had to look for certain objects using certain qualifiers: ID, Name, ID & Name, etc… Without optional parameters (Hello C# 4.0!), I ended up with copying & pasting whole blocks of code: initializing, filtering, returning the result, error handling, etc. I wondered if there was an easier solution to that and then it hit me! LINQ & delegates!
Let’s start with a simple class:
public class Employee
{
public string FirstName { get; protected set; }
public string LastName { get; protected set; }
public int Id { get; protected set; }
//...and other methods...
}Then, we have a List of Employees:
List<Employee> Employees = new List<Employee>() { new Employee("Juan", "dela Cruz", 1), new Employee("John", "Doe", 2), //and so on... };
Now let’s try making some convenience methods for retrieving a collection of filtered Employees.
public IEnumerable<Employee> GetByLastName(string last) { IEnumerable<Employee> result = Employees.Where(emp => emp.LastName == last); return result; } public IEnumerable<Employee> GetById(int id) { IEnumerable<Employee> result = Employees.Where(emp => emp.Id == id); return result; }
Quick & easy, yes? Now what if instead of a List, our collection of Employees isn’t that stable. We’d need to put each of them in try-catch blocks and add error handling. This can quickly become high-maintenance code.
We then basically need one method that will contain all the error handling, initialization and whatnot. We just pass a delegate will filter the collection:
public IEnumerable<Employee> GetEmployee(Func<Employee, bool> query) { try { //initialization IEnumerable<Employee> result = Employees.Where(query); return result; } //handling other exceptions... catch (Exception ex) { //Error handling return null; } }
Did you notice: Func<Employee, bool>? All we need is to pass an expression that uses the Employee as input and returns a boolean (true if it passes the condition or false if not).
What does this mean? Well, we can now replace the convenience methods we wrote earlier with this:
public IEnumerable<Employee> GetByFirstName(string first) { Func<Employee, bool> query = emp => emp.FirstName == first; return GetEmployee(query); } public IEnumerable<Employee> GetById(int id) { Func<Employee, bool> query = emp => emp.Id == id; return GetEmployee(query); }
We’re back to code that’s easy to maintain with all the initializations, error handling and other code blocks that you need.
You could even do away with the convenience methods and use lambda expressions all the way!
GetEmployee(emp => true); //get everything GetEmployee(emp => emp.LastName.Contains("Locs")); GetEmployee(emp => emp.FirstName == "Richard" && emp.LastName == "Locsin");
Have fun!
Related resources:
I just love the Quick Launch toolbar since it provides easy access the usual programs and folders I use without much clutter on the taskbar. No Shaking Required In my previous post, I also mentioned that the Aero Shake seemed impractical for non-touch/pen input. I guess Microsoft's answer to that is the shortcut: [Win+Home]. (#3) Hide and Go Peek When on keyboard intensive tasks such as writing and coding, I hate to move my right hand and reach for the mouse. Good thing there's [Win+Space] that reveals the Destkop like Aero Peek (#17), and [Win+1], [Win+2], ...[Win+5] for quick access to the first 5 items on the taskbar (#11), and [Win+T] to shift focus to the taskbar (#21). (Note: [Win+T] works on Vista, too) Still More? These are just my favorite "secrets" from what Tim Sneath posted. I can't help but wonder what Microsoft is intentionally hiding from us, especialy after reading this from the Windows 7 Beta 1 review on TechRadar UK:
- Right-click the taskbar, choose Toolbars / New Toolbar
- In the folder selection dialog, enter the following string and hit OK: %userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch
- Turn off the “lock the taskbar” setting, and right-click on the divider. Make sure that “Show text” and “Show title” are disabled and the view is set to “small icons”.
- Use the dividers to rearrange the toolbar ordering to choice, and then lock the taskbar again.
The beta is feature complete; although there are "a couple of things that we're holding back", according to general manager Mike Ybarra. ... "all of the code is in the build, just the discoverability is not." ...Very Interesting...
I just bumped into a clever little code snippet used to find the inverse square root:
float InvSqrt(float x) { float xhalf = 0.5f * x; int i = *(int*)&x; // store floating-point bits in integer i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method x = *(float*)&i; // convert new bits into float x = x*(1.5f - xhalf*x*x); // One round of Newton's method return x; }
[ taken with comments from Kalid Azad @ BetterExpalined.com: Understanding Quake’s Fast Inverse Square Root. ]
Ok, it does not get the exact value but you get a good enough estimate, FAST!
There are two important things to note here:
For a better explanation, I suggest reading Kalid Azad’s article and the paper by Charles McEniry.
In graphics programming, this can be used to normalize vectors quickly. If you noticed the title on the first link, it’s used in the Quake 3 engine. So does that mean the legendary John Carmack wrote this code? If you’re interested, you can read the Origin of Quake3’s Fast InvSqrt() at Beyond3D.
I usually forget one thing: there are times when speed trumps accuracy. A close quick estimate would be better and there are a number of optimations that can be made. Much thanks goes to Doc Mana who first introduced me to the Newton-Raphson method & how to apply it on code.
12. Software updates 12.1 The Software which you use may automatically download and install updates from time to time from Google. These updates are designed to improve, enhance and further develop the Services and may take the form of bug fixes, enhanced functions, new software modules and completely new versions. You agree to receive such updates (and permit Google to deliver these to you) as part of your use of the Services.Also, here are some things you might want to know:
17. Advertisements 17.1 Some of the Services are supported by advertising revenue and may display advertisements and promotions. These advertisements may be targeted to the content of information stored on the Services, queries made through the Services or other information. 17.2 The manner, mode and extent of advertising by Google on the Services are subject to change without specific notice to you. 17.3 In consideration for Google granting you access to and use of the Services, you agree that Google may place such advertising on the Services.Well, for me it's fine (as long as they're unobtrusive). Do you agree?
info["Errors"] = context.AllErrors == null ?
"" : string.Join( "<br/><br/>",
(from error in context.AllErrors
select String.Format( "{0}<br/>{1}",
error.Source, error.Message))
.ToArray<string>());Ubiquity is an experimental Firefox extension that gives you a powerful new way to interact with the Web. You're used to telling Firefox where you want to go by typing Web addresses into the URL bar. With Ubiquity installed, you'll be able to tell Firefox what you want it to do by typing commands into a new Ubiquity input box.
(Source: Ubiquity 0.1 User Tutorial)
It's experimental and it's only on version 0.1 but hey, it's a prototype that just WORKS! Okay, so what can it do? Here's a video by Aza Raskin to show you more about it: (Watch it. I promise that you won't regret it.)(Source:Ubiquity for Firefox from Aza Raskin on Vimeo.) Neat stuff. I, myself, am so excited that I can't help but try messing with Ubiquity. The result: A Ubiquity command for Ping.fm. Ping.fm: Updating social networks in a snap With a lot of social sites around (like Facebook, Twitter, Tumblr, Plurk, Livejournal, Yahoo! 360, Delicious, etc.), I can't help but be a member of a number of them. What usually happens is that some of my friends on one network is not a member of another. To update everything would be a pain and so there's Ping.fm!
Ping.fm was created for the sole purpose of making it as easy as possible to share your posts with the world. Now you don't have to fumble around the web in order to post anymore, you can just post once, and be done with it.
(Source: Ping.fm/About)
If you want a Ping.fm account, the current beta code is: "legendofping". [Checking the different social sites is a different story. I suggest using Socialthing! I currently have one free invite for SocialThing so if you want in, just ask me. ] Ubiquity + Ping.fm So here I am now, with my Ubiquity command written for Ping.fm. I'm pretty proud if it and have used it a lot recently. It's so much easier to share things on the web. Highlight, type some text and you're good to go! If you want to get Ubiquity on Firefox, you can download it from here. To install and use my Ubiquity command for Ping.fm, just follow the instructions I wrote in there. NOTE: After clicking on the Subscribe button, you'll reach a scary warning page that says "Ubiquity Command from Untrusted Source." Just click on "I know what I'm doing. Subscribe to it!" to install the command. Don't worry, I promise you that nothing in there is harmful to your computer and does not violate your privacy. This command only allows you to post to different social sites using Ping.fm and that's it. The source code is available for you to check if you don't trust me. At the moment, you're always being warned when installing a command as mentioned here. If you have any problems/comments/suggestions, email me or comment below. Have fun with Ubiquity! If you develop some commands yourself, don't be shy and share it! UPDATE1: Ubiquity has been updated and breaks your current subscriptions. For your current subscriptions to work again, you may need to unsubscribe & resubscribe to them. UPDATE2: Ping.fm is now in OPEN beta! No more beta codes needed!The registry cannot load the (hive) file: SystemRoot/System32/config/SOFTWARE or its log or alternate. It is corrupt, absent, or not writeable. Beginning dump of physical memory. Physical memory dump complete. Contact your system administrator or technical support group for further assistance.or this
Stop: c0000218 {Registry File Failure} The registry cannot load the hive (file): \SystemRoot\System32\Config\SOFTWARE or its log or alternateCan't remember exactly but basically it was about the hive file and that my registry was most probably dead. The Solution?!? My first instinct told me to restart in safe mode but that just proved to be worthless. So what did we do that worked
- I have to use iTunes to import songs into my iPod and to listen to them while it's connected to my computer. Thankfully, there are quite a number of hacks out there so that I don't have to use this memory hog. Aside from that, there are Linux apps (with much resistance from Apple) that can read the iPod's weird file storage system that brings me to point #2.
- I cannot export the songs I have on my iPod, even if I got the files from that computer in the first place. Let's say I have my music library in my iPod & hard drive. For some reason, my hard drive got corrupted so my whole music library is lost. I cannot intuitively transfer the songs in my iPod back to my computer. I need to download more hacks to be able to that. I try copy the contents of my iPod as is, but it's not human readable.
If we give more "value" to such terms, we might end up in a grim world for consumers. Finally, just to end on a lighter side: