tag:blogger.com,1999:blog-388882962024-03-13T18:39:49.285+08:00C# SnippetsA collection of my C# classes, findings and rants.Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.comBlogger64125tag:blogger.com,1999:blog-38888296.post-62580750067196657942016-08-12T22:44:00.004+08:002016-08-14T16:13:48.902+08:00Configure Theano to use Intel MKL on Windows
In order to use convolution layers and FFT in Theano, Theano requires either BLAS or CUDA to be present. On computers without an Nvidia graphics card, BLAS is the only choice.
There are 3 popular BLAS implementations, namely Intel MKL, OpenBLAS and ATLAS. A benchmark shows that ATLAS is the slowest, while MKL and OpenBLAS are on par. I could not get OpenBLAS to work, as I keep getting the errorJeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-54512207563613494202016-08-07T23:36:00.003+08:002016-08-08T22:51:49.620+08:00Compiling aspell-python
While the Unofficial Windows Binaries for Python has aspell-python for Python 3.4, it does not have one for Python 3.5. Thus, we've got to compile it ourselves.
Since Python 3.5 requires Visual Studio 2015, we first have to modify C:\tools\python\tools\Lib\distutils\cygwinccompiler.py to recognize Visual Studio 2015
--- cygwinccompiler.py+++ cygwinccompiler.py@@ -82,7 +82,18 @@ def get_msvcr():Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-27374151261764466442016-01-22T20:30:00.002+08:002016-01-22T20:49:01.028+08:00Compiling Aspell on Windows
Download Aspell
Download and extract GNU Aspell 0.60.6.1 from http://aspell.net/
Download and extract the English dictionary (aspell6-en-2016.01.19-0.tar.bz2)
Install Chocolatey machine package manager
Start PowerShell as Administrator
Enter the following commands:
Set-ExecutionPolicy ByPass
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
Install the Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-18054464402009932442015-03-18T17:10:00.000+08:002015-07-16T15:22:06.494+08:00Creating a constraint to ensure intersection table only joins certain records
I have a database with the following tables
I need to ensure that users only becomes friends with other users of the same department.
Approach 1 – DepartmentId on Friend
On http://stackoverflow.com/a/20443626/263003, diarmuid suggested to add the DepartmentId on the Friend table and use the foreign key constraints of (MyselfId, AppId) and (FriendId, AppId). However, I would have to set the Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-48230344682683966682015-02-28T12:42:00.001+08:002015-02-28T13:30:29.511+08:00React JS in ASP.NET MVC part 2—setting up React<!DOCTYPE html>
Set up the project and libraries for React
Let’s start by creating a new ASP.NET MVC project
Next, we will use NuGet to download the React libraries that we need
Right-click on References and click Manage NuGet Packages
Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com6tag:blogger.com,1999:blog-38888296.post-58041598573079288392015-02-26T23:50:00.001+08:002015-02-28T12:50:34.275+08:00React JS in ASP.NET MVC part 1—why Isomorphic JavaScript?
The conflict of rich web application and search engine optimization
Be it Gmail, Facebook or Github, we have come to expect interactivity without having to wait for a full page reload. Specifically, these web applications are single-page applications (SPA), where new content arising from interactions are sent and retrieved via AJAX.
There are many frameworks to make developing SPA easier. Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com1tag:blogger.com,1999:blog-38888296.post-8330810796153798172015-02-07T20:38:00.001+08:002015-02-07T20:39:15.763+08:00Get an extra 5GB of storage for Copy when you use this link!
My 25 GB of Dropbox space earned from Space Race is expiring in a month! I'll be left with a meagre 2.5 GB only. ::sob::
Luckily, there's a Dropbox competitor, Copy, offering 15 GB of base storage. What's more, if you use the referral link below, both you and I will get an additional 5GB! That's a lot, especially when Dropbox only gives 10% of that per referral.
Get your 20GB NOW
https://Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-31312273239695396462012-08-17T15:47:00.000+08:002012-08-17T16:24:24.709+08:00Upgrading from ASP.NET MVC 3 + Web API RC to ASP.NET MVC 4 to Web API RTM
ASP.NET MVC 4 and Web API are finally released! On to upgrading my projects to the latest version.
I followed the instructions at Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4 to convert ASP.NET MVC 3 to MVC 4. However, I've got lots of errors. It looks like Microsoft added DisplayNameExtensions.DisplayNameFor, thus conflicting with my own DisplayNameFor extension that does the same thingJeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-55407668637157639582012-08-15T12:21:00.000+08:002012-08-15T12:21:16.481+08:00Windows 8 IndexedDB invalid access error
While following the code at Getting Started with IndexedDB, I encountered the invalid access error at this line
var transaction = db.transaction("people", IDBTransaction.READ_WRITE);
It turns out that the IDBTransaction is obsolete. Following the instruction at IndexedDB changed in IE10 PP6, I changed the code to the following. It now works!
var transaction = db.transaction("people", "readwriteJeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com1tag:blogger.com,1999:blog-38888296.post-13385056362723119012012-08-07T15:06:00.000+08:002012-08-15T15:13:32.985+08:00Useful references for Windows 8 Metro style app development
Design Guidelines
Pixel dimensions of margins and paddings
List of controls that is available
Windows 8 ebook
Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-51106975249459322152012-07-11T21:42:00.001+08:002012-07-11T21:42:23.662+08:00Getting FormsAuthentication to work inside iOS WebViewI developed a Facebook mobile web application and wanted users to easily access it by scanning a QR Code. However, while the web application works perfectly in Mobile Safari, it totally fails in the QR Code reader app and gets stuck in the landing page. First suspicion was Facebook’s login process. After extensive debugging, I could not nail the problem, as the code runs in the exact sequence as Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-77040346758058362912012-05-29T12:13:00.001+08:002012-05-29T12:13:10.700+08:00WebsitePanel MySQL errorWhile setting up WebsitePanel, the MySQL setup page always gives the following error. Could not load file or assembly 'MySql.Data, Version=6.3.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies By adding the following to the web.config of C:\WebsitePanel\Server, the problem is resolved. <runtime>   <assemblyBinding xmlns="urn:Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-3099738231337836652012-05-03T23:00:00.001+08:002012-05-03T23:00:24.261+08:00Forcing ValidationSummary to include property errors from IValidatableObjectI implemented IValidatableObject to my class and intended to have the errors shown in @Html.ValidationSummary(true). However, the class with the IValidatableObject  is a property of the model in my view, and that causes the errors to be hidden when I exclude property errors. There is another person on Stackoverflow with exactly the same problem, but no one has answer. http://Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-14803420179329142902012-04-16T22:00:00.001+08:002012-04-16T22:00:27.355+08:00Loading a website inside of PhoneGap in AndroidI am trying a quick and dirty way to turn my mobile website into an Android app. Using PhoneGap, I created a login page that post its values to my mobile site. However, the login did not seem to have any effect, as I am presented with the login page (now loaded from my website) again. The problem lies with the fact that the link is opened in a new browser window, rather than within the web view Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-40271754898761167052012-04-10T17:57:00.001+08:002012-04-10T17:57:48.700+08:00Breadcrumbs partial for Umbraco 5Umbraco 5 is a new CMS build from scratch using ASP.NET MVC 3. It is a departure from previous version which uses Web Forms. However, due to the different architecture, the way to do breadcrumbs changed and I could not find any examples for the new version. So I came out with one =) @inherits RenderViewPage @using Umbraco.Cms.Web; @{     var current = DynamicModel; Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-35294011700543263672011-12-29T14:33:00.001+08:002011-12-29T14:33:55.649+08:00jQuery Mobile swiperight too sensitiveWhile adding functionalities that triggers when the jQuery Mobile swiperight event is fired, I met the same problem as ade_cd, where the swiperight event gets triggered even when I am scrolling a page. On examining the jQuery Mobile 1.0 source code, I realized that the jQuery Mobile team has taken his suggestion and made the previously hardcoded values into parameters. The parameters should be Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com2tag:blogger.com,1999:blog-38888296.post-19345384666439154612011-12-08T13:23:00.001+08:002011-12-08T13:23:09.247+08:00Getting the DayOfWeek in Linq to EntitiesEntity Framework has several pros and cons. The pros of strongly typed objects and shorter code compared to the equivalent SQL kept me from going back to using SqlCommand directly. However, I met another cons of Entity Framework today — that is the lack of support for DateTime.DayOfWeek. I have a table [Booking] with a column [StartDateTime]. Using the following code results in an error. var Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com6tag:blogger.com,1999:blog-38888296.post-82492456248958980312011-11-22T10:20:00.001+08:002011-11-22T10:20:14.912+08:00Enkompass 11.30 unfit for ASP.NET hostingAfter facing various issues with Enkompass, I’m giving up on it and moving to Plesk. I shall document the issues to remind myself not to go back to Enkompass until the issues are resolved. Hopefully, this also serves as a guide to those evaluating whether Enkompass caters to their needs. Enkompass supports only one ASP.NET application. There is no way to configure virtual directories or new Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com2tag:blogger.com,1999:blog-38888296.post-30023671358456239262011-05-10T21:02:00.001+08:002011-05-10T21:02:42.834+08:00Recovering DotNetNuke Host menu after unchecking Include in MenuThe Admin and Host pages in DotNetNuke can be hidden from the menu, just like other pages. However, a bug in DotNetNuke causes the Host page to lose its connection to its subpages. Luckily, it is reversible, as mentioned in http://www.dnncreative.com/Forum/tabid/88/aft/31023/Default.aspx. Just type the following UPDATE {databaseOwner}[{objectQualifier}Tabs] SET PortalID = NULL WHERE TabID = 7 Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com1tag:blogger.com,1999:blog-38888296.post-39798599781510020672011-04-20T12:15:00.001+08:002011-04-20T12:15:59.367+08:00Prevent getting disconnected/blocked from school network when running virtual machineIn Nanyang Technological University’s (NTU) Local Area Network (LAN), whenever one plugs a personal router into a LAN port, the port will be blocked for 10 minutes. If the router is still present after 10 minutes, it gets blocked again. This is probably to ensure that nobody connects a wireless router/access point and turn the non-password secured physical port into a wireless one. However, thisJeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-45777315936818606062011-02-27T14:45:00.001+08:002011-02-27T14:45:20.338+08:00Bing Maps 7 API bug in MouseEventArgs.getX and getYThe new Bing Maps is a lot more lightweight, and the changes in event handling makes more sense. For example, it is now possible to detect viewchangeend event instead of using an assortment of onendpan, timers and getCenter to detect whether the view has changed. However, I ran into the same problem mentioned here http://www.ms-windows.info/Help/map-control-v7-mouse-wheel-double-29660.aspx. The Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-83201434534915126592011-02-08T09:19:00.001+08:002011-02-08T09:19:25.748+08:00Oddities of Facebook events APIUsing the the Graph API of https://graph.facebook.com/[userId]/events, one can retrieve the events that the user is attending. The same applies to page, using https://graph.facebook.com/[pageId]/events. However, what does it mean by the event attended by a page? It is not the same as the events created by the page, as the API returns less results that what you would see in the events tab of the Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-48737526680775295152011-02-07T23:55:00.001+08:002011-02-07T23:55:19.750+08:00Oddities of Facebook event date/timeFacebook is very popular globally, crossing several time zones. Yet to my surprise, it has no concept of time zones. Quote from the Legacy REST API Note that the start_time and end_time are the times that were inputted by the event creator. Facebook Events have no concept of timezone, so, in general, you can should not treat the value returned as occurring at any particular absolute time. Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0tag:blogger.com,1999:blog-38888296.post-83856873532053041662010-10-18T16:27:00.001+08:002010-10-18T16:27:08.865+08:00A comparison of DjVu and JPEG2000 in PDFSome time ago, I stumbled upon DjVu, a document archiving format. I have previously scanned several printed documents into JPEG and compiled them in ZIP archive. The method is sub-optimal,  producing large JPEG files and creating non-viewable files, unless uncompressed. Placing the JPEG files in PDF, while making it viewable, increases the file size further. DjVu presented a much better Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com2tag:blogger.com,1999:blog-38888296.post-41486053317044599222010-09-03T22:41:00.001+08:002010-09-03T22:41:27.476+08:00Downloading Facebook Profile Pictures to Outlook ContactsMicrosoft Office 2010 introduced the Social Connectors. With the Facebook Connector, emails now come with faces, thanks to the connector downloading profile pictures from Facebook. Opening contact items shows faces as well. The next logical step is to use that contact item’s profile picture as the business card picture. However, no matter how I click-and-drag the picture over to the placeholder,Jeow Li Huanhttp://www.blogger.com/profile/11871374011115309096noreply@blogger.com0