Categories
Bookmarked Javascript

Dropzone.js: A great plugin

I recently try Dropzone JavaScript library to ease the upload process. It is really a lightweight and good library. I have a existing PHP form that take multiple images, and transfer/upgrading it to dropzone was as easy as include it’s library.

I have little to mention, but a link to site is what I want to include in this post. http://www.dropzonejs.com a must library if you need multiple image upload by user. I use it for a scientific application, where client need to bulk upload about 1000s of image file for database, and it speed up their process. There is nothing much to add for tutorial as their basic tutorial is good enough to start even for newbie.

Categories
Bookmarked MS SQL Server SQL

SQL Update if Record Exists or Insert

Quite often we need an approach where we need to Insert record if it is not already present. Sometime to manage relationship. There are few different way of doing it, like “If Exists”, or “Insert on Duplicate Key” (mysql) but the best I found is one from MSDN Blog Entry ( http://blogs.msdn.com/b/miah/archive/2008/02/17/sql-if-exists-update-else-insert.aspx)

The approach is to simply try update the record, if record present it got updated, if not then it insert new based on “Row Effected variable”.

Categories
Bookmarked PHP Programming

WhatsAPP moving to new authentication.

Though the new authentication (WUTH-2) is not really new, but few days back they disable the old authentication mechanism. So, just a bookmark to latest version of API: https://github.com/mgp25/WhatsAPI-Official . This is rather refined library and you can feel it when you use it.

Categories
Bookmarked Wordpress

Some Cool WordPress Plugin

Lately, I got lot of wordpress site, that were not just blog or business website. But they are ecommerce, Restaurant Ordering, Video streaming and much more. Been a developer I always remain engage in making some sort of plugin for them. Though following list of plugin assist me a big time in saving time to do some of works I usually have to do to make some really nasty site in wordpress:

The list is of plugin I usually use, but not restricted to. There are couple more of plugin but currently I am unable to recall them. Meanwhile we also create a small plugin used for very limited set of user:

https://github.com/Vikasumit/wpl [Allow only members to see the complete site].

I have few other plugin coming up, but still not ready to launch them in public as they are not yet finish or are mature products. Love the fact that WordPress plugin development is as cool as working on any other project. Just need some good idea to make it possible.

Categories
Bookmarked Database MS SQL Server SQL

Advance SQL: Finding Hierarchical data using Recursive CTE

Often we have a Table that store Hierarchical data, such as any shopping cart will have product category in table that store parent table within same table. We often use such information. The typical structure of table is

ID, Name , ParentID

Where ParentID is ID within same table or for Top level it is either Null or Zero. In such tables we often want to find Child of Child in order we can list them in tree view, i.e.  

L0
  L1
    L2
  L1-1
    L2-1
 ....

Now, to find this type of result you have two option: 1. Write complete logic in your code 2. Make SQL do it for you. For those who prefer this method here is the sample Query I used

 

DECLARE @ParentCompanyID INT = 9;
WITH RecComp
AS
(
    SELECT  crt.CompanyID,
            crt.Name,
            crt.ParentCompanyID,
            1 AS Lvl,
            N'/' + CONVERT(NVARCHAR(4000),crt.CompanyID) + N'/' AS CompanyNode_AsChar
    FROM    @Company crt
    WHERE   crt.ParentCompanyID = @ParentCompanyID
    UNION ALL
    SELECT  cld.CompanyID,
            cld.Name,
            cld.ParentCompanyID,
            prt.Lvl + 1,
            prt.CompanyNode_AsChar + CONVERT(NVARCHAR(4000), cld.CompanyID) + N'/'
    FROM    RecComp prt -- parent
    INNER JOIN @Company cld ON prt.CompanyID = cld.ParentCompanyID
)
SELECT  *,
        CONVERT(HIERARCHYID, CompanyNode_AsChar) AS CompanyNode
FROM    RecComp
ORDER BY CompanyNode;

This query make use of CTE feature of SQL server [I personnally test it on SQL server 2008 R2, 2012 and SQL Azure] and HierarchyID to show the result as desire. More can be read in my thread on StackOverFlow here

 

 

Categories
Bookmarked PHP Programming

PHP Mobile Detection

Just a quick note, to detect the mobile/tablet/desktop this script looks promising : http://code.google.com/p/php-mobile-detect/ I try to detect it my Windows Mango phone, it does detect it as Mobile, though I hate that it doesn’t recognize Windows Mango yet. But looks promising and it is easier to implement it as well.

Categories
Article ASP.NET Bookmarked C#.NET PHP Programming VB.NET/VB

WKHTMLTOPDF: A Free PDF solution

As any other developer we often find it difficult to get a Website to print something accurately, specially when printing labels for mailing as they are outside the default print area for most browser and no client want to adjust or memorize the print setting to adjust them manually. Also it doesn’t make sense to relay on client to do adjustments.

So the only universal solution I found is.. of course PDF files. But how do I create PDF. Well easy enough use some library. I did that I use iTextPDF very good Library that works for my C# project well for couple of years. But then what is the problem now? Well iTextPDF is now have commercial license at ridiculous pricing in fact it is now most expensive to any other paid software. Yet another Open Source project going paid on success. 

Also, there is a problem with library like iTextPDF that they need you to draw each and every element programmatically more often or not. And you find yourself caught in a web of long written code. I remember one of my report’s PDF generation code goes 1000 lines. I hate it. So, the best solution is to Generate PDF from a HTML source. We can handle HTML much better way and rather easily with our skills as web programmer. And even a designer in team can change PDF design giving time for programmer for other work. 

In this regard I look for free alternative of iTEXTPDF, which does have HTML parser to generate PDF from HTML file, and my search for now ends on http://code.google.com/p/wkhtmltopdf/ (wkhtmltopdf ) project. A Simple Executable that I can call from a my code to execute and it does the parsing. 

It is not really a good idea to call it through web page, but we should create a Windows service and use it there, but I have successfully test it to work on web server with quite a load and at least with my limitation to access Windows Service I can live with it running through HTML page, after all my PDF is just 1-2 page and it works fine. Will post code for it some other day. But do try it if you want a good and quick solution to your problem.