Wednesday, June 12, 2013

IOS: the correct way to create object-c singleton

There are many wrong ways to create singleton class on the web, there is the right way to create it.

//  MyManager.h
#import

@interface MyManager : NSObject

+ (MyManager*) sharedManager;


@end



//  MyManager.m
#import "MyManager.h"

@implementation MyManager

static  MyManager* sharedInstance = nil;

+ (MyManager*) sharedManager {
    if(sharedInstance==nil) {
        @synchronized(self) {
            if (sharedInstance==nil) {
                sharedInstance = [[MyManager alloc] init];
            }
        }
    }
    return sharedInstance;
}

- (id)init {
    if (self = [super init]) {
        //init some properties here
    }
    return self;
}



@end


Sunday, April 20, 2008

Software Configuration Management Tools

copied from http://www.software-configuration.com/software_configuration_tools.html

Software Configuration Management Tools
configuration managment system Posted by Rob Castellow


So now is the fun part. You get to pick which tools you will be using to make your development process as smooth as possible. I will attempt to give my experiences with a select few tools that I have seen be useful in a software configuration management environment. If you, the reader, know of other tools that you feel should really be mentioned, please feel free to send suggestions to my email address in the contact section.
First, let's address each area that you will need at some point of the software design life cycle...

Version Control Tools
Subversion (http://subversion.tigris.org) - This is quickly becoming the open source industry standard for version control. Subversion provides numerous features and also there is an enormous amount of support for development tools (Eclipse, NetBeans, etc) Subversion was developed by many of the original CVS developers and was designed to address all the things wrong with CVS.

Git (http://git.or.cz/) - A non-traditional SCM tool but efficient and distributed version control system. This project was originally created to manage version controlling LINUX kernels. The main push on Git is to handle large projects more efficiently.

Clearcase (http://www-306.ibm.com/software/awdtools/clearcase/) - Did I say that I was cheap? Yes, I did, but I would like to mention Clearcase anyway. First, understand the cost of Clearcase is more than what appears on your invoice. The real cost to maintain Clearcase is in maintaining a local server, and then if multi-site is needed, just multiply that cost by the number of remote locations. Other than the enormous costs, if I had to pay for a version control tool I would select Clearcase for its overall functionality.
Multi Site replicators
WANDisco (http://www.wandisco.com) - I have not personally used this product, but I know that WANDisco is the leader in providing multi site solutions for Subversion, JIRA, and CVS.
Defect and Enhancement Tracking
JIRA (http://www.atlassian.com/software/jira/) - JIRA is a customizable bug and issue tracker. JIRA provides custom workflows, web service interfaces and much more. I have used JIRA and it is extremely intuitive. JIRA is not free, but it is extremely cheap compared to other tools.

TRAC (http://trac.edgewall.org) - I use TRAC on all my home projects, and it is extremely simple and flexible. TRAC has an interface to Subversion and also has an integrated wiki. TRAC also reads wiki markup in the commit comments of Subversion. TRAC is also open source.

Bugzilla (http://www.bugzilla.org) - Bugzilla is an old standby for many developers. I would suggest though that there are many better tools out there these days. However, if you just want the old classic, Bugzilla is still actively maintained. Bugzilla is open source.

Scarab (http://scarab.tigris.org) - Scarab is an open source tool to track issues. Scarab is a Java based implementation over MySQL. Scarab is highly configurable, and will also import/export data from other defect tracking tools.

Mantis (http://www.mantisbt.org) - Mantis is a popular open source web based issue tracker. Easily installed and configurable.

Requirement Tools
OSRMT (http://sourceforge.net/projects/osrmt) - Open Source Requirements Management Tool manages features, requirements, design, implementation, and testing.

Iterative Build Tools
Cruise Control - CruiseControl was for many years on the forefront of continuous build integration. CruiseControl has been a favorite by many. There are many options to the CruiseControl tool, which can all be configured in its xml configuration file.

Hudson - A newer but powerful continuous integration build tool. I am using this tool on a project now, and enjoy Hudson's many options, nice interface, and good communication options.

Environment Management Tools
SourceForge - (http://sourceforge.net) - The world's largest open source development web site. This environment allows any open source project to host itself for free on the site. SourceForge also enables developers to communicate efficiently, track defects, and provides version control.

Build Tools
Ant (http://ant.apache.org) - Ant is a Java XML based build tool that has many built in libraries to automate builds and deploys. Most development environments have plugins to Ant, and Ant enjoys widespread support.

Maven (http://maven.apache.org) - Maven is another Java XML based build tool with many built in libraries. Maven differs in a few aspects from Ant. First Maven is object oriented. A developer will create a POM file to build code and that file will be inherited on all subprojects. If you are trying to decide whether to use Maven or Ant, I would recommend that if you have a basic J2EE app that does not deviate from good design patterns, then Maven is great. If you really need to create creative design patterns, I would recommend Ant.

Make (http://www.gnu.org/software/make) - You may be designing C++ apps and using Make. If so, I dropped the link, but chances are this is tattooed on your forearm by now.

Other Utilities worth Mentioning
KOSMOS - (http://labs.jboss.com/kosmos) - This product is so useful, if you are using JIRA, Subversion, CruiseControl, or SourceForge. If you are into high level understandings of where the code is at at any given moment, this tool provides a dashboard to several version control and defect tracking tools. This tool is a JBoss portlet, so you will need a JBoss application server to run this app. That's OK though. It's all free!

Saturday, April 19, 2008

maven, defininitly not a relacement for ant

Ant has many problems, but maven is definitely not the replacement for ant.

One key concept for the next generation build tool is that it should be much easier to use. Obviously, maven goes to the wrong direction.


The following is copied from http://fishbowl.pastiche.org/2007/12/20/maven_broken_by_design
for my reference to write presentation to prevent the moving from ant to maven.

Responsiveness

We have a joke around the office, when a new hire is setting up their development environment for the first time. “Now we go to lunch while Maven downloads the Internet.”

Software should be responsive. When you tell it to do something it should do it. Take a pristine Maven installation and tell it to build a Java application — i.e. perform its most obvious, primary function — and Maven will first say “Wait a moment, I have to download three dozen different components before I can even start doing what you asked me to do.”

“Ah”, you say. “That’s how maven works. It’s a modular system, you’re just using it to build a Java app.”

To which I reply: “Then don’t give me a spoon and tell me to use it to cut steak.”

The fact that all these components are downloaded separately and in serial mean the overhead of not including them is far greater than if they’d put them all (even plus a bunch more you might not need) in the core installation. Worse, though, this happens not when you’re installing maven, but when you’re trying to use it to do something else.

This process doesn’t stop at installation. Far too often you’ll run maven and it will gleefully traipse off through various repositories doing its own internal housecleaning before actually performing the build. It’s like walking up to a shop assistant and asking him to help you find a book, only to watch him dust shelves for fifteen minutes first.

Reliability

Consider two pieces of software. One uses maven (and 1–n artifact repositories) to manage its dependencies, the other keeps all its dependencies in source-control. How many potential points of failure are involved in checking out and building each product?

Repeatability

Builds must be repeatable. If you check out a particular version of your code and build it with particular versions of your tools, you should get a product that is binary-identical each time. (Modulo things like compiled-in build dates, obviously)

Maven seems to try as hard as it can to prevent this. Files go missing from public Maven repositories and suddenly a whole swathe of historical versions of open source projects can’t be built without hacking. ibiblio reorganises its directory layout and chaos ensues. Imagine what happens in ten years time when maven has been superceded by some new tool, public maven repository maintenance is an afterthought, and you desperately need to patch some legacy Java app?

For well-resourced projects, the solution is to maintain your own repository and ensure all your dependencies will be available from it, for all time, but even that won’t help you if you suddenly need the compile-time dependencies of a project you previously only used as a binary.

(A number of responses to this blog post have assumed that all my problems could be solved by a locally maintained repository, and/or a repository proxy. We have both. They help to some extent, but they in no way solve the problem completely. All they are is a band-aid over the fundamental issue, and once again, additional potential points of failure.)

Most open-source projects just assume their dependencies will continue to exist in “the cloud” for eternity.

Plugins are the worst culprit. Since the core of maven exists solely to download an Internet’s-worth of plugins to do the heavy lifting, and maven has a nasty habit of upgrading those plugins without any user-prompting whatsoever, builds can be crippled by some well-meaning committer “fixing” some piece of functionality. I’m told this has been fixed recently (or will be fixed soon) but versions should not be a moving target. v. 2.0.1 of your build tool should be v. 2.0.1 of your build tool. Forever.

Case Study: Dependency Management

One of the big strengths of Maven 2 is supposed to be the way it manages dependencies, including transitive dependencies. So if jar A requires jar B which requires jar C, Maven will sort all this out for you.

Tracking down dependencies and sorting out their transitive relationships is a tricky task, but it’s a tricky task you only ever have to do when you modify your dependencies. Maven, on the other hand, wants to do this job every time you build, which adds a huge responsiveness overhead, as the “pom” definition files of each dependency must be retrieved and analysed alongside their jars.

Dependencies may live in a number of different repositories, and these repositories are out of the control of the user, especially in the case of maven-built open-source projects that almost universally rely on the public ibiblio, apache and Codehaus repositories. This impacts both reliability, as all these repositories must be available, and repeatability, as changes to the repositories may have catastrophic effects on the build.

Reliability problems also creep in because maven, forced to do dependency resolution in each build, must hide a lot of what it’s doing from view lest it overwhelm the user even more. Conflicting transitive dependencies are resolved implicity, and you have to make a concerted effort (with clumsy tools) to manually find out what was going on.

Paradoxically, by trying to make dependency management easy, maven makes it incredibly hard. It becomes dangerously easy for a project to accumulate dependency cruft —— at best unnecessary, at worst conflicting —— and excruciatingly painful to remove them.

Conclusion

Maven 2 performs a difficult task, and there are a lot of moving parts — plugins, proxies, repositories — between typing mvn install on the command-line and getting a working system. But there has to be something fundamentally wrong with any tool that, whenever I use it, seems to have at least a 50% chance of completely fucking up my day

Sunday, March 30, 2008

mvn + tomcat for hot deployment

Also, one very powerful feature of Maven that I am messing around with right now is filtering and profile "mashups". Lets say, I want LRD (local rapid development ;-) on my workstation using Tomcat. Usually I would use the Jetty plugin because it is the ultimate for Maven LRD, but the majority of the time and to match what is in production, developers use Tomcat at a minimum. Here is a quick tip for creating a shared distributable app using the aforementioned.

In a existing Maven app, create the following structure:

src
|-main
|-filters
|-tomcat.properties
|-resources
|-context.xml

In your pom.xml we have something like
:


tomcat

false






src/main/filters/tomcat.properties





${basedir}/src/main/resources

true
../${build.finalName}/META-INF

context.xml





in tomcat.properties

context.docBase=${basedir}/target/${project.build.finalName}
context.path=/${project.build.finalName}

and in context.xml



Once you have all of this in place (along with a good cargo config found in this post) you will be on your way to a enjoyable, easy development setup.

So now, all you have to do to hot deploy your maven app to a running instance of Tomcat is type the following: mvn install -Ptomcat
This will compile and deploy your changes quickly. You can also set your IDE to copy jsp/xhtml files over using a keyboard shortcut mapping (easy to do with Idea) so for UI changes you don't have to hot deploy every time.
This example just scratches the surface of what mixing profiles with filtering can do. You could have a filtering/profile mechanism for every possible scenario.

Thursday, March 27, 2008

open source e-commerce software

--------------
osCommerce Online Merchant is an Open Source online shop e-commerce solution that is available for free under the GNU General Public License. (PHP)
--------------------------------
Apache: http://ofbiz.apache.org/feature-list.html

-----------------------------
http://www.magentocommerce.com/features
--------
php sites:

osCommerce , ZenCart, phpShop, myMarket

Saturday, March 22, 2008

how to get sequence from mysql in cluster env

If you have a cluster of application servers running and you would like to get a unique id across the cluster, the best way is to get the id from Database. Oracle has the sequence function, but MySQL does not have the function.

Here are several ways to work around the issue in MySQL.

Retrieving AUTO_INCREMENT column values using Statement.getGeneratedKeys()
   Statement stmt = null;
ResultSet rs = null;

try {

//
// Create a Statement instance that we can use for
// 'normal' result sets assuming you have a
// Connection 'conn' to a MySQL database already
// available

stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_UPDATABLE);

//
// Issue the DDL queries for the table for this example
//

stmt.executeUpdate("DROP TABLE IF EXISTS autoIncTutorial");
stmt.executeUpdate(
"CREATE TABLE autoIncTutorial ("
+ "priKey INT NOT NULL AUTO_INCREMENT, "
+ "dataField VARCHAR(64), PRIMARY KEY (priKey))");

//
// Insert one row that will generate an AUTO INCREMENT
// key in the 'priKey' field
//

stmt.executeUpdate(
"INSERT INTO autoIncTutorial (dataField) "
+ "values ('Can I Get the Auto Increment Field?')",
Statement.RETURN_GENERATED_KEYS);

//
// Example of using Statement.getGeneratedKeys()
// to retrieve the value of an auto-increment
// value
//

int autoIncKeyFromApi = -1;

rs = stmt.getGeneratedKeys();

if (rs.next()) {
autoIncKeyFromApi = rs.getInt(1);
} else {

// throw an exception from here
}

rs.close();

rs = null;

System.out.println("Key returned from getGeneratedKeys():"
+ autoIncKeyFromApi);
} finally {

if (rs != null) {
try {
rs.close();
} catch (SQLException ex) {
// ignore
}
}

if (stmt != null) {
try {
stmt.close();
} catch (SQLException ex) {
// ignore
}
}

Retrieving AUTO_INCREMENT column values using
SELECT LAST_INSERT_ID()

Statement stmt = null;
ResultSet rs = null;

try {

//
// Create a Statement instance that we can use for
// 'normal' result sets.

stmt = conn.createStatement();

//
// Issue the DDL queries for the table for this example
//

stmt.executeUpdate("DROP TABLE IF EXISTS autoIncTutorial");
stmt.executeUpdate(
"CREATE TABLE autoIncTutorial ("
+ "priKey INT NOT NULL AUTO_INCREMENT, "
+ "dataField VARCHAR(64), PRIMARY KEY (priKey))");

//
// Insert one row that will generate an AUTO INCREMENT
// key in the 'priKey' field
//

stmt.executeUpdate(
"INSERT INTO autoIncTutorial (dataField) "
+ "values ('Can I Get the Auto Increment Field?')");

//
// Use the MySQL LAST_INSERT_ID()
// function to do the same thing as getGeneratedKeys()
//

int autoIncKeyFromFunc = -1;
rs = stmt.executeQuery("SELECT LAST_INSERT_ID()");

if (rs.next()) {
autoIncKeyFromFunc = rs.getInt(1);
} else {
// throw an exception from here
}

rs.close();

System.out.println("Key returned from " +
"'SELECT LAST_INSERT_ID()': " +
autoIncKeyFromFunc);

} finally {

if (rs != null) {
try {
rs.close();
} catch (SQLException ex) {
// ignore
}
}

if (stmt != null) {
try {
stmt.close();
} catch (SQLException ex) {
// ignore
}
}
}

}
What happes if you need multiple sequences in your app. The you may create sequence talbe several columns.

update sequence set id1=

Thursday, March 20, 2008

opensource social network software

" Pligg is an open source content management system available for download at no cost"

"Drupal.org is the official website of Drupal, an open source content management platform."

"NewsCloud is an open source media platform which you can use to launch your own grassroots media Web site. Or, you can get involved in the development of the NewsCloud platform"

"AROUNDMe is a GNU package. We use the General Public License (GPL) for our software meaning that you can copy our software, redistribute it, explore, change or modify the code."

"Dolphin Smart Community Builder is a universal, free, open source software that allows you to build any kind of online community."

"Even though PHPizabi is distributed unencrypted, it DOES NOT fall under any GPL license (Open Source does not necessarily mean OSD/GPL)."

"Elgg is an open source social networking platform developed for LAMP (Linux, Apache, MySQL, PHP) which encompasses weblogging, file storage, RSS aggregation, personal profiles, FOAF functionality and more."

"The software that powers Mugshot is 100% open source, including the client and the server."

" Web-based social bookmarking system. Allows multiple users to store, share and tag their favourite links online. License: GNU General Public License (GPL) "

"GetBoo just turned to open-source, under the GPL license at the end of April. I don't have any expectations, but I am confident it will add to my experience!"


-------------------

Dolphin

Dolphin, from Boonex, is a popular free community-building application that is being used for a number of dating sites. Many modifications have been developed, however many of them are only available for a fee. There is also a cost associated with removing the company’s links from your site.

PHPizabi

PHPizabi is another social networking script that charges a fee to remove their branding. They are rapidly approaching 100,000 downloads of their software, and have a few impressive-looking demo sites listed on their website.

Elgg

Elgg was developed with the educational industry in mind, but can be customized for any use. Many universities throughout the world have adapted the social software to fit their needs.

Mugshot

Developed by Red Hat, Mugshot allows you to post what you are reading and listening too, and share it with you friends. Mugshot is a little different, as both the client and server code are open source and available for download.

AroundMe

AroundMe is an open source social networking app that supports OpenID. They are based in Sweden. We haven’t seen many sites running on the platform.

---------------------
Top 40 Free Downloadable Open Source Social Networking Software
Vivalogo Resources

This is Vivalogo's list of best free, downloadable, open source social networking software (kinda hard to say all these words :) ).
Unlike some other lists you may find on the net, this one contains only really downloadable and functional software.
Note: listed in no particular order.
spree

spree is an expert search engine where users ask questions to find other participating users, who are knowledgeable in that area and willing to help.
iSocial

iSocial is a free social networking CMS software that allows you to create your own Friendster and Orkut like sites. Use bookmarks, dating and create groups with just one mouse click.
Mahara

Mahara is fully featured electronic portfolio, weblog, resume builder, and social networking system for connecting users and creating online communities.
Yogurt

This is a Social Network module for xoops CMS. You have seen Facebook, Orkut, Myspace , try Yogurt for Xoops!
VMukti

VMukti is a Unified Social Collaborative conferencing engine. Allows access through personalized, mashable web-interface. Core features:- Video conferencing, Audio conferencing, IP Telephony, Desktop sharing, Chat, Whiteboard, Presentation & More.
The PeopleAggregator

The PeopleAggregator is a next-generation social networking system that goes beyond the idea of social networks as mating games, and attempts to use open standards, network inter-connectivity and massive flexibility.
Appleseed

Appleseed is (augmented) social networking software, ie Friendster, only distributed. Sites running Appleseed will interoperate, and form the 'Appleseed Social Network.' Development is focused on privacy and security, as well as ease of configuration.
Mugshot Project

The Mugshot site lets you track what your friends are doing online across a variety of popular web sites ? music, photos, blog posts, and more.
GetBoo

Web 2.0 bookmarking system, both social (with tags) and private (with folders). Import and export your bookmarks from Firefox, IE, Mozilla, Netscape. Admin management section, translations, groups, bookmarklets, Firefox extension, RSS feeds, and more!
Akarru

Akarru is a social bookmarking engine, is used to build social bookmarkings sites, like www.blogmemes.com. Users posts links and promote links to front page using voting system.
Scuttle

Web-based social bookmarking system. Allows multiple users to store, share and tag their favourite links online.
SemanticScuttle

SemanticScuttle is a social bookmarking tool (based on Scuttle) experimenting new features as hierarchical tags, collaborative descriptions or OpenID authentification.
AROUNDMe

Create collaborative social websites (like Ning, Myspace, Yahoo or Google groups). Each group can create a multiple web pages. They get a drop in guestbook, blog, forum and wiki. Each group is fully customizable using xHTML, CSS, Javascript and PHP.
Clonesumating

Clonesumating is the open source version of the code that runs CONSUMATING.COM. It features many state of the art social networking functions including user profiles, user tagging, matching and discovery based on quirky tag combinations, group activities such as weekly photo contests and blog questions, an event calendar, RSS feeds for everything, etc. It is written primarily in mod_perl.
BeWelcome Rox

Get to know the global village and other cultures, share your place. BW Rox is the platform driving www.bewelcome.org and other social networks, aiming to bring people together in real life. Organize your travel or stay abroad, travelblog, meetings, ...
ICEcore

ICEcore open team collaboration software uses social networking to unify team workspaces w/ real-time web conferencing. Collaboration for knowledge networking, program management, communities-of-practice, telework, ...
Memephage

Memephage is an automated web log (blog). It passively gathers and summarizes links from various places. Currently: IRC, social MUDs, e-mail, and web browsers. Uses the POE multitasking and networking framework for Perl.
InteractOLE

A platform for the delivery and support of online learning. It differs from many other elearning platforms in that its aim is to concentrate on the social/interactive aspects of teaching and learning rather than the delivery of content to students.
Elgg

Elgg is an open source social networking platform developed for LAMP (Linux, Apache, MySQL, PHP) which encompasses weblogging, file storage, RSS aggregation, personal profiles, FOAF functionality and more.
CommunityNews

CommunityNews uses social bookmarking and bayesian techinques to provide periodic postings to blogs. Users can vote for or against RSS sources ti increase the chances that the source is used again. Spam filtering (bayesian) is provided by spam bayes.
OpenPNE

OpenPNE is a Social Networking Service Engine written in PHP. It has many features(friend control,friend invitation,diary,blog feeds,message box,etc).
MonkeyChow

Feed Aggregator Reader (branched from FeedOnFeeds) with Social Bookmarks (del.icio.us, Blogger, Newsvine, Technorati, mailto), Article Starring, Feed Tagging, OPML, Article Search, Reblogging and Refeeding, Aging, and Edit feed attributes.
NewsCloud

NewsCloud is an open source media platform for citizen journalism and the social news network hosted at NewsCloud.com.
Feed Me Links

Feed Me Links stores your bookmarks online so you can get to them anywhere. Import your favorites and share your links with friends. Add tags to organize your links. Discover new things.
WorldSpace

WorldSpace is a user-extensible shared virtual environment, aimed at being a next-generation social networking system.
Social Networking POC

A networking site on the lines of Orkut.Right now we plan to build it on Jboss seam and use a Java content management system like apache Jackrabbit as the backend. It would be more of a POC than an actual commercial app.
Zoints

Zoints is intimately aware that online communities are the most important aspect of the internet. Our free software solutions are designed to help solve the three major problems forum owners face: Member acquisition, Member retention and Profitability.
earth-life-simulation

A simulation of the world, there will be a global map representation and players can choose a country or civilization and develop it's social, political and military existence.
PHPizabi

PHPizabi is one of the most powerful social networking platforms on the planet. With literally thousands of websites powered by PHPizabi including everything from simple friends sites to the most complex networking super sites out there.
Ozcode

Ozcode is the source code behind Ozmozr.com, a microformat-aware RSS aggregator, social networking, resource sharing, identity aggregation and presentation site.
TallStreet

TallStreet.com is a new search engine concept where users make investments, with fictional money, in their favourite websites and the rankings are determined entirely by the users.
Jamss

Jamss is a social news site based off of Digg.com. Jamss allows for peer submission and review of web articles and can be adapted to fit a variety of themes. Jamss runs on PHP/MySQL.
Dolphin

Dolphin is open-source and free, although there is a cost associated with removing the company?s links from your site.
Ospo

Ospo is an opensource social portal project. It use standard function (add, remove friends, top10), forums integration, music module (artists directory with albums, songs), shoutcast integration, blog (add, delete, modify, view) and so on.
AstroSPACES

AstroSPACES is the world's first open source social networking solution. Coded from scratch, it is highly efficient and very easy to use.
FlightFeather

FlightFeather's goal is "social networking for everyone". This means that anyone should have a chance to run a popular social networking site -- on minimal hardware, and without wasting bandwidth.
SNOSS

Social Networking Open Source Software, an open source social networking framework, written in PHP, Javascript and MySQL with an AJAX UI.
OpenSocialNetwork

OpenSocialNetwork is a social network of open source. Its main task is to create a social network releasing the source code.
S3B

S3B - Social Semantic Search and Browsing - is a middleware that delivers a set of search and browsing components that can be used in J2EE web applications to deliver user-oriented features based on semantic descriptions and social networking.
Facelift

Facelift is a visualization and analysis software for online social networking services. It displays a given community as a node-link diagram and provides several search / filtering functions as well as cluster analysis features.