Loki's blog

  • Home
  • maloki.net
  • Ubiquity 0.5; Updated Ping.fm command

    • 10 Jul 2009
    • 0 Responses
    •  views
    • Programming Technology projects
    • Edit
    • Delete
    • Tags
    • Autopost
    Ubiquity 0.5 is out! If you currently have and older version of Ubiquity installed for Firefox, it won't automatically update since it would break a lot of other commands in the wild. If that's ok with you, you can download Ubiquity 0.5 at Planet Ubiquity. Of course, mine broke, too, and I just updated it! Whoo! I updated my Ping.fm Ubiquity command to use the new parser. Others should also be able to localize the command if they want to do so*. The old version of the command is still up just in case some issues pop up in this version of the command. There are still some tweaks (and maybe some other features) I want to put in but this is it for now. Time for me to get some sleep. It'll be a busy day at work later! -- *Well, not now, but probably in the future as:
    "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...
    • Tweet
  • Don't Repeat Yourself using LINQ & Delegates

    • 29 May 2009
    • 0 Responses
    •  views
    • C# DRY LINQ Programming Technology
    • Edit
    • Delete
    • Tags
    • Autopost

    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.

    Enter LINQ and delegates!

    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:

    • LINQ
    • Lambda Expressions
    • Tweet
  • Windows 7 Secrets

    • 14 Jan 2009
    • 1 Response
    •  views
    • Microsoft OS Technology
    • Edit
    • Delete
    • Tags
    • Autopost
    Yesterday, I posted my first impressions on the Windows 7 Beta. Today, I've bumped into a great informative post by Tim Sneath with his 30 favorite secrets in Windows 7. Much thanks to Tim! Back From Retirement I was happy to find among them a way to bring back the old Quick Launch Toolbar! (#13)
    • 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.
    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:
    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...
    • Tweet
  • First Impressions on Windows 7 Beta

    • 12 Jan 2009
    • 1 Response
    •  views
    • Microsoft OS Technology geek
    • Edit
    • Delete
    • Tags
    • Autopost
    Public Beta Release Last January 9, 2009, Microsoft released the Windows 7 Beta to the public. I don't think Microsoft expected much demand since the servers were facing technical difficulties. The put down the site to ensure a better download experience. The link to the ISO was shared by some helpful users and still worked. However, potential testers (including me) couldn't get a product key that would get past the 30-day limit. Fortunately, Microsoft more than made up for their overloaded servers by extending the key distribution until January 24. If you're interested, you can download the ISO, get a key and test Windows 7 yourself until it stops working on August 1, 2009. (By this time, maybe there will be another beta version / new key distribution...) To Test or Not I tried to resist beta testing Windows 7 but in the end, Windows 7 beta won. I finished downloading the Windows 7 x64 ISO (about 3.3 GB) & just got my product key yesterday morning (Sunday) and started testing shortly after. After a day of use, here's what I noticed, plus my comments/suggestions. I've tried to link to as much screenshots that I've taken to show what I mean.

    Read the rest of this post »

    • Tweet
  • Inverse Square Root

    • 5 Jan 2009
    • 0 Responses
    •  views
    • Programming Share Technical Technology gaming geek
    • Edit
    • Delete
    • Tags
    • Autopost

    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:

    • Newton’s method (also known as the Newton-Raphson method)
    • The ‘magic number’: 0x5f3759d5, an optimized first guess

    For a better explanation, I suggest reading Kalid Azad’s article and the paper by Charles McEniry.

    Wait a minute, so why is this useful?

    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.

    What did I learn?

    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. 

    • Tweet
  • Google Chrome is here and it's really fast!

    • 3 Sep 2008
    • 0 Responses
    •  views
    • Technology google web
    • Edit
    • Delete
    • Tags
    • Autopost
    Get it now! It's cleaner, faster, and it's fun too! Aside from the features listed in the features page, here are my first impressions: The Good:
    • You can import bookmarks, passwords, etc. from your current browser
    • It's noticably faster
    • Cleaner = More page real estate! (It may take some time for me to get used to this...)
    • Text in the address bar is more readable (it's bigger!)
    • Firefox shortcuts work! (Alt+D/Ctrl+L, Ctrl+J, Ctrl+H, etc..)
    • Autocomplete isn't intrusive and it really works
    • Draggable tabs (moving them like FF...and OUTSIDE to put them in their own window!)
    • Speaking of tabs, you can also drag your Firefox tab to Google Chrome! 
    • There's Incognito mode (or "porn mode" if you're the type)
    • The new tab page is unexpectedly useful
    • Did I mention it's really fast? Wooo~! JavaScript!
    • When right-clicking on a link, "Open link in new tab" is the first option instead of "new window." It also loads NEXT to your current tab, not at the end like in Firefox
    • If one page causes a crash, the other tabs are unaffected. Finally!
    • Downloads window is now a Downloads tab. Less intrusive = better
    • When searching for terms, results outside the visible area is shown in the scroll bar! Neato!
    The Bad:
    • No spell check Whoops! I think it's just wordpress...Or maybe it's new? Ooh! they updated it!
    • No real-time search in the History tab
    • No user profiles
    • No "master password" to protect all your saved passwords
    • Plugins/Extensions are (currently) missing. (If you're extension-depended, stick to your current browser...for now at least)
    • The feed button is nowhere to be seen (tell me if you find it)
    What do you think? Right now, I can't help but still use Firefox along with Google Chrome...
    Either way, Google Chrome is worth a try! It's not mind blowing but the experience is just more pleasant.
    UPDATE: Some things you might not know... Regarding the spell check thing, I think it was an update they released on their part. Here's some info on their Google Chrome Terms of Service:
    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?
    • Tweet
  • Google Chrome

    • 2 Sep 2008
    • 0 Responses
    •  views
    • Technology web
    • Edit
    • Delete
    • Tags
    • Autopost
    Oooh...Google Chrome: Google's new browser. (Comics & Blog) This will be interesting indeed. Hooray for open source~! More code to mess around with. :D On another note: I think I'm going overboard with my code... C#
    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>());
    Whee~! Single line of code. Aw hell, it's only test code. *Used Ubiquity for Sytax-highlighting...let's see how it turns out.

    Posted by email from goofydelinquent's posterous

    • Tweet
  • Ubiquity: Connecting the Web, Empowering Users

    • 1 Sep 2008
    • 10 Responses
    •  views
    • Technology mozilla open source projects ubiquity web
    • Edit
    • Delete
    • Tags
    • Autopost
    Ubiquity: Why should I care? Last week, I learned about this nifty Firefox tool called Ubiquity. What is it?
    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!
    You might also want to check out:
    • Ubiquity in Depth by Aza Raskin
    • Ubiquity User Tutorial
    • Ubiquity Author Tutorial
    • Tweet
  • "i" was and is a mistake

    • 29 Jul 2008
    • 0 Responses
    •  views
    • Apple Technology open source
    • Edit
    • Delete
    • Tags
    • Autopost
    Open a new tab or window and do a search on "reasons to avoid" and what do you see? Go on, do it. What do you see? At the time of writing, I got 5 reasons to avoid iPhone 3G:
    • iPhone completely blocks free software. Developers must pay a tax to Apple, who becomes the sole authority over what can and can't be on everyone's phones.
    • iPhone endorses and supports Digital Restrictions Management (DRM) technology.
    • iPhone exposes your whereabouts and provides ways for others to track you without your knowledge.
    • iPhone won't play patent- and DRM-free formats like Ogg Vorbis and Theora.
    • iPhone is not the only option. There are better alternatives on the horizon that respect your freedom, don't spy on you, play free media formats, and let you use free software -- like the FreeRunner.
    Coming from the Free Software Foundation, it pretty much sounds like an ad for the NeoFreerunner from OpenMoko (and yeah, I do want one or something similar, like one that supports the Google Android - despite this little issue). Sure, you can "jailbreak" an iPhone but do we have to keep I've never owned an iPhone but Lifehacker does and knows more about it that I do. I admit at one point I did want an Apple laptop but that's just it. I wanted the laptop just for the sake of owning one but not really using one. It looks cool but using it is a different story. Last night, one topic raised during our family dinner was regarding buying an Apple laptop. I said that I would not get an Apple one for two main reasons:
    1. After using the Microsoft's OS's for over 10 years, I don't find Mac's OS user-friendly. It looks cool but function should take priority over form.
    2. It's overpriced. Want proof? Here's a comparison of the Dell Inspiron 1720 and a MacBook Pro 17-inch:
    Media_httpblogmalokin_ciavo
    Let me quote one redditor, GlueBoy:
    While it's true that there are advantages to an apple computer in software and hardware and tech support and whatnot, it's insufficient to justify a nearly $2k price difference. What it comes down to is paying for style over substance, and anyone who says differently is lying or stupid.
    Ok, what I do own is an 4th generation 20 GB iPod. I'm quite satisfied with it, despite the fact that I had to get it fixed last year when I got this error (cute icon though), and a year before that. But that's just it! I've become used to it and had been drowned by the hype that I didn't bother with complications Apple didn't mention.
    • 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:
    Media_httpblogmalokin_acafj
    (images from: reddit: The problem with Apple, Apple iMac vs Dell XPS 410)
    • Tweet
  • The corrupt, absent or not writable

    • 4 Jul 2008
    • 5 Responses
    •  views
    • Microsoft Problems Technology Vista
    • Edit
    • Delete
    • Tags
    • Autopost
    This morning, my office PC was suddenly showing the dreaded Blue Screen of Death. After 2-3 hours of tinkering, we got it back up and what I can say is that Vista is weird (We're using Windows Vista Business (64-bit) with SP1 installed). The BSOD So what was my problem? It went something like this:
    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 alternate
    Can'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
    1. Boot the Windows Vista CD
    2. Selected the option to Repair an existing installation (it's found in the second window when it finally loads)
    3. Wait for it....and then done!
    4. Restart and Vista should load!
    Yay! It now boots Windows Vista! It was able to detect that I had problems booting up Windows Vista and fixed the problem itself. It's as easy as cake...if my problem ended there! (The cake is a lie!) When logging into the network, my user name and password was not being accepted! The network administrator account can't log in either using my PC. WTH, right? Now this is where Vista gets weird... Jack Out To Jack In: Logging Into a Network that Doesn't Exist Yes, you read that right. Well, it exists but the computer wasn't physically connected. Did you get that? There were no network cables that connected me to the network but I was able to log in. This was the only way both my account & the administrator accounts can connect to the "network." It defies all logic that would lead to a proper solution but hey, it works. I had to somehow log in to the computer I'm not really complaining. It's just weird. think it uses previously log-ins to check the information if the log-in information is valid. At this moment, everything seems to work fine. I can work on my local files and am connected to both the local network and the internet. The only problem is that whenever I have to authenticate/verify an action (Thanks to Vista, this is very common) I have to unplug my network cable and authenticate using the right user name & password. It's downright annoying to work under that condition so something had to be done. Welcome back! So how was I finally able to connect to the network and log in properly? It's quite easy. Get the computer out of the domain and then get back in. After that, I was able to log into the network.
    1. Go to Computer > Properties > Advanced System Settings
    2. Click the Computer Name tab
    3. Then somewhere near the bottom, click the Change button
    4. In the "Member of" portion at the bottom, select the Workgroup radio button and type in a Workgroup name ("WORKGROUP" by default)
    5. You'll be asked to restart so just do that
    6. Repeat the same steps 1-3
    7. Instead of selecting the Workgroup radio button, select Domain and type in the network domain.
    8. Restart the computer.
    After this, I could log on normally WHILE connected to the network! (Well, sometime later, something went wrong in the local network so. Woohoo x.x Glad everything's back to normal again. At least it seems so.)
    • Tweet
  • « Previous 1 2 Next »
  • About

    25-year old Filipino software developer and gamer who loves food, especially cookies. Mmmm, Cookies!

    28050 Views
  • Archive

    • 2011 (1)
      • May (1)
    • 2010 (1)
      • September (1)
    • 2009 (8)
      • July (1)
      • May (1)
      • April (2)
      • January (4)
    • 2008 (17)
      • December (1)
      • November (3)
      • September (3)
      • July (6)
      • June (1)
      • April (1)
      • January (2)
    • 2007 (24)
      • November (2)
      • October (2)
      • September (3)
      • August (4)
      • July (6)
      • June (2)
      • May (2)
      • March (2)
      • February (1)
    • 2006 (10)
      • November (3)
      • March (1)
      • February (2)
      • January (4)
    • 2005 (5)
      • December (1)
      • November (2)
      • March (1)
      • January (1)
    • 2004 (3)
      • November (2)
      • October (1)

    Get Updates

    Subscribe via RSS
    TwitterFacebookFacebook
  • Other blogs

    • Photography
    • Singularity
    • Hungry
    • Tumblog

    maloki.net

    • Home
    • Projects
    • Contact