Magazines, Books and Articles

Showing posts with label Software development. Show all posts
Showing posts with label Software development. Show all posts

Wednesday, March 18, 2015

A C# library for CouchDB

I was recently working on a .NET project that uses CouchDB v 1.6.1 as its database. As part of this project, I created this library to abstract away the HTTP requests to a CouchDB. It is a work in progress, but the methods available should be sufficient for CRUD operations on a CouchDB database.

The code's written in C# in VS 2013 Community Edition.

You can download the source at https://github.com/nestas-santanu/CouchDBLibrary/releases and use it in your projects that use CouchDB. No strings attached.

Thursday, January 22, 2015

Error using cURL to POST or PUT data formatted in JSON in Windows

If you use cURL in a cmd.exe shell on Windows, an attempt to POST or PUT data formatted in JSON results in an error. An example:

This is the data:
{"Continent":"AS","ContinentName":"Asia","CountryName":"India","Capital":"New Delhi","Iso_Alpha2":"IN","Iso_Numeric":"356","Iso_Alpha3":"IND","FipsCode":"IN"}
curl -i -X PUT -d "{"Continent":"AS","ContinentName":"Asia","CountryName":"India","Capital":"New Delhi","Iso_Alpha2":"IN","Iso_Numeric":"356","Iso_Alpha3":"IND","FipsCode":"IN"}"  -H "Content-type:application/json; charset=UTF-8" http://192.168.1.6:5984/geodb-country-test/IN

HTTP/1.1 400 Bad Request
Server: CouchDB/1.6.1 (Erlang OTP/R16B02)
Date: Thu, 22 Jan 2015 06:28:26 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 48
Cache-Control: must-revalidate

{"error":"bad_request","reason":"invalid_json"}
This is because the cmd.exe shell on Windows has issues parsing the quotes in the data.

One work around is to escape all quotes in the JSON. The following works:
curl -i -X PUT -d "{\"Continent\":\"AS\",\"ContinentName\":\"Asia\",\"CountryName\":\"India\",\"Capital\":\"New Delhi\",\"Iso_Alpha2\":\"IN\",\"Iso_Numeric\":\"356\",\"Iso_Alpha3\":\"IND\",\"FipsCode\":\"IN\"}"  -H "Content-type:application/json; charset=UTF-8" http://192.168.1.6:5984/geodb-country-test/IN

HTTP/1.1 201 Created
Server: CouchDB/1.6.1 (Erlang OTP/R16B02)
Location: http://192.168.1.6:5984/geodb-country-test/IN
ETag: "1-d4c8b330d781b982184e0e6829f434cd"
Date: Thu, 22 Jan 2015 06:31:26 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 65
Cache-Control: must-revalidate

{"ok":true,"id":"IN","rev":"1-d4c8b330d781b982184e0e6829f434cd"}
Escaping all the quotes in the data would be a huge pain; here's an online tool that will do all the donkey's work.

Another work around is to write the data to a file and use it in the following manner:
curl -i -X PUT -d @"C:/Shared Folder/country.json"  -H "Content-type:application/json; charset=UTF-8" http://192.168.1.6:5984/geodb-country-test/countries

HTTP/1.1 201 Created
Server: CouchDB/1.6.1 (Erlang OTP/R16B02)
Location: http://192.168.1.6:5984/geodb-country-test/countries
ETag: "1-568f829b1bcc952ba27ca7a084428390"
Date: Thu, 22 Jan 2015 07:42:12 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 72
Cache-Control: must-revalidate

{"ok":true,"id":"countries","rev":"1-568f829b1bcc952ba27ca7a084428390"}
cURL
Windows Installer

Wednesday, April 2, 2014

Creating complex business solutions

In spite of the fact that I haven't posted on this blog for 2-2.5 years, there has been an average of 100 page views a month. I assume from this that the content has been helpful to some. Inspiration enough to start again.
Technology has made giant strides in these few years making it possible to create very complex business solutions. Two areas get highlighted:
a. how do we maintain large volumes of structured and unstructured data, query and analyse it
b. how do we build and deploy applications in terms of performance, scalability and mobility.
It is a time when developers are under extreme pressure to learn and understand a lot of new technologies (in addition to the traditional ones) in a very short time - and deliver. .NET developers, IMHO, are at a greater disadvantage, because solutions are more in the Java/ Open Source space and require more effort on their part.
In subsequent posts we will discuss the topics below. This will address some of the areas related to 'a' above.
1. NoSQL databases: the need, different types, performance comparisons, applications
2. Search: the need, different approaches, performance comparisons, applications

Saturday, October 8, 2011

IE's legacy browsers - will they ever go away?

“W3C publishes documents that define Web technologies. These documents follow a process designed to promote consensus, fairness, public accountability, and quality. At the end of this process, W3C publishes Recommendations, which are considered Web standards.” from Standards FAQ.
The recommendations are not binding, but as the W3C says: “W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web.”
And would make us developer’s creating web applications more productive.
Microsoft, in spite of its large representation in the W3C Working Groups, has been a laggard at proactively adopting these recommendations in its browsers. It has thus gifted us a bunch of what it now calls its ‘legacy browsers’ - IE6, IE7 and IE8, which, whether we like it or not, has still to be supported if our web applications/sites are to reach a greater audience.
A case in point is the CSS Color Module Level 3, one of the modules of CSS3, which was endorsed as a W3C Recommendation on 7 June 2011. The first W3C Working Draft was published on 22 June 1999, it became a W3C Candidate Recommendation on 14 May 2003, back to a W3C Working Draft on 21 July 2008, and a W3C Proposed Recommendation on 28 October 2010.
Tantek Çelik [Microsoft’s representative till 2003] and Brad Pettit [Microsoft’s representative] have been associated with this recommendation right from the first working draft to its endorsement as a recommendation.
In this period, IE went from IE6.0 to IE9.0, Firefox to version 5.0 and Chrome to 12.0. The table below indicates how Firefox and Chrome were early adopters of CSS3, whereas Microsoft waited until IE9.
Table 1
How does Microsoft’s apathy affect us in development? Several ways:
1. IE is the most used web browser.
Figure 1: Web browser usage by country in September 2011 [Source: http://en.wikipedia.org/wiki/Usage_share_of_web_browsers]
2. StatCounter estimates the usage share of web browser for September 2011 as below.
Figure 2 [Source of data: StatCounter]
3. The usage share of various versions of IE for September 2011 is shown below (source: StatCounter)
Figure 3 [Source of data: StatCounter]
Figure 3 means that the usage share of Microsoft’s legacy browsers is 32.72%. This is a large population and cannot be ignored.
So why do we have a such a large population using IE’s legacy browsers? 2 reasons in my opinion.
One: Microsoft bundles IE with its OS. So IE is kind of available out of the box. The fact remains that the majority of Internet users are not techies or geeks like you or me. The browser is just another tool to get their work done. And if it is available out of the box, they’ll use it. They don't care if the IE version they are using is W3C compliant or otherwise, as long as it can get their work done.
IE also has a tight integration with the OS. So while you will be able to install Firefox 7 on Window XP or Window 7, IE9 will work only on Window 7+ (though its legacy browsers can run of this OS). The high usage of IE8 is because it was released for Windows XP, Windows Server 2003, Windows Vista, and is the default browser for Windows 7 and Windows 2008 R2.
Window XP and Window 7 more or less share the honours as per StatCounter’s data of September 2011. This delays adoption of IE9 as the primary browser.
Figure 4 [Source of data: StatCounter]
Two: Figures 1, 2 and 3 indicate internet usage. My experience is that the usage of IE’s legacy browser is even greater in intranets in corporate, business and government - this follows from the fact that the browser is bundled with the OS. These have a large user base and the cost and time of upgrading the OS or the browser is huge.
So, IE’s legacy browsers aren’t going away soon. And we will continue to fret for a while longer about the pain these give us. And because we create applications for the masses, we need to write code to support both these and the modern browsers. Something like this ‘best practice CSS’, even though it will never validate.
.50PercentOpaque
{
    opacity: 0.5;     //W3C CSS Color Module Level 3 compliant browsers
    filter: alpha(opacity=50); //IE legacy browsers
}

Friday, April 29, 2011

Bugs!!

From Three Questions About Each Bug You Find
"..Do you sometimes fix a bug, and then find another bug related to the first or to the way you fixed it? When I fix a bug, I ask myself three questions to make sure I've thought carefully about its significance. You can use these questions to improve productivity and quality every time you think you've found and fixed a bug..."
Figure 1
Figure 1 is "The First 'Computer Bug' Moth found trapped between points at Relay # 70, Panel F, of the Mark II Aiken Relay Calculator while it was being tested at Harvard University, 9 September 1947. The operators affixed the moth to the computer log, with the entry: "First actual case of bug being found". They put out the word that they had "debugged" the machine, thus introducing the term "debugging a computer program". In 1988, the log, with the moth still taped by the entry, was in the Naval Surface Warfare Center Computer Museum at Dahlgren, Virginia, which erroneously dated it 9 September 1945. The Smithsonian Institute's National Museum of American History and other sources have the correct date of 9 September 1947 (Object ID: 1994.0191.01). The Harvard Mark II computer was not complete until the summer of 1947..." The First "Computer Bug"

Friday, October 8, 2010

The privilege and responsibility of software development


From Grady Booch:
".. It is a privilege because -- in spite of some inevitable dark days -- we collectively are given the opportunity to create things that matter: to individuals, to teams, to organizations, to countries, to our civilization. We have the honor of delivering the stuff of pure intellectual effort that can heal, serve, entertain, connect, and liberate, freeing the human spirit to pursue those activities that are purely and uniquely human. At the same time, we have a deep responsibility. Because individuals and organizations depend on the artifacts we create, we have an obligation to deliver systems of quality in a manner that applies scarce human and computing resources intentionally and wisely. This is why we hurt when our projects fail, not only because each failure represents our inability to deliver real value, but also because life is too short to spend precious time on constructing bad software that no one wants, needs, or will ever use. As professionals, we also have a moral responsibility: Do we choose to labor on a system that we know will fail or that may steal from a person their time, their liberty, or their life? These are questions that do not have a technical answer, but rather are ones that must be consciously weighed by our individual belief system as we deploy technology to the world. .." The privilege and responsibility of software development


And from the Software Engineering Code of Ethics and Professional Practice:
".. Computers have a central and growing role in commerce, industry, government, medicine, education, entertainment and society at large. Software engineers are those who contribute by direct participation or by teaching, to the analysis, specification, design, development, certification, maintenance and testing of software systems. Because of their roles in developing software systems, software engineers have significant opportunities to do good or cause harm, to enable others to do good or cause harm, or to influence others to do good or cause harm. To ensure, as much as possible, that their efforts will be used for good, software engineers must commit themselves to making software engineering a beneficial and respected profession. .."