Friday, April 29, 2011

Good iPhone SDK tutorials

Hello,

I'm looking for good iPhone SDK tutorials in terms of using Interface Builder to set up views (like using the Navigation Controller or Tab Bar Controller). I can't seem to set one up correctly and add it as a sub view for the main app window to display. I always get a blank screen and I've yet to find something that helps me.

Any help would be great.

From stackoverflow

SQL Bulk Insert error 4863

Hey guys,

I am trying to import some data to SQL Server 2008 by means of Bulk Insert, but I've been getting a ton of conversion errors:

Msg 4864, Level 16, State 1, Line 1 Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 5902, column 2 (Type).

OK so first things first:

a) the data comes from a parser i built in C#. In this file, there are 4 columns, separated by tabs. The columns may or not be null. The collation is UTF-8. Here's an excerpt of it.

D00486  DBLinks PubChem 7847552
D00486  DBLinks LigandBox D00486
**D00487    Name  Pyridostigmine bromide (JP15/USP/INN)** -- WORKS
D00487  Name  Mestinon (TN)
D00487  Chemical 260.016 C9H13N2O2. Br
D00487  Target PATH:hsa00564(43)
D00487  Remark  Therapeutic category: 1239
D00487  Remark  ATC code: N07AA02
D00487  Pathway PATH: map07220 Cholinergic and anticholinergic drugs
D00487  DBLinks CAS 101-26-8
D00487  DBLinks PubChem 7847553
D00487  DBLinks DrugBank DB00545
D00487  DBLinks LigandBox D00487
**D00488    Name  Pyrimethamine (JAN/USP/INN)** -- DOES **NOT** WORK!
D00488  Name  Daraprim (TN)

The second to last row generates an error message like the one i've previously shown you. What really amazes me is that the other line i've placed on bold is quite similar yet does not generate any error whatsoever.

b) This is what i'm using to create the table:

CREATE TABLE [dbo].[KB] ([BEName] [nvarchar](1000) NOT NULL, [Type] [nvarchar](1000) NULL, [Name] [nvarchar](1000) NULL, [Value] [nvarchar](1000) NULL) ON [PRIMARY]

c) This is what i'm currently using to import the data from a file:

DECLARE @SQL nvarchar(4000)
SET @SQL = 'BULK INSERT KB FROM ''C:\KB.xml'' WITH (FirstRow = 1, FORMATFILE = ''C:\out_KB.fmt'')';
EXEC(@SQL)

I had to manually generate the fmt file because for some reason BCP could not connect to my database (still working out the basics on it...) so it may be possible that it's not as it should be. Either way, here are it's contents:

9.0
4
1 SQLCHAR 0 100 "" 1 BEName SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 500 "\t" 2 Type SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 500 "\t" 3 Name SQL_Latin1_General_CP1_CI_AS
4 SQLCHAR 0 500 "\n" 9 Value SQL_Latin1_General_CP1_CI_AS

As i've previously stated, i don't have much experience with BCP; initially, I was simply using

BULK INSERT KB FROM ''C:\KB.xml'' WITH (FirstRow = 1, RowTerminator = ''\n'' , FieldTerminator = ''\t'')

but it wouldn't work anyway. I'd still rather use this instead of the FMT file; I googled and tried a couple of tricks (such as swapping \n with \n\cr or introducing the ASCII code of the \n instead).

Any ideas? I can't say that i have'em, i'm exhausted right now, going to sleep until noon or something :S (it's 4 AM here now).

Cheers mates, thanks and advance Hal

PS: I think the samples are ok, but please be my guest and request what you may need at any time. PS2: Sorry for the wall of text ;)

From stackoverflow
  • Non-XML bulk-insert files are very finicky. I looked at yours and don't see a problem, but it is easy to miss problems.

    XML bulk-insert files are a lot easier to work with. Can you refactor your code to produce XML bulk insert files instead? I have also found that you must also use XML format files when using XML insert files, and BCP won't create that for you -- you have to write your XML format file yourself, but it's pretty easy.

    Hal : Good idea, thank you. I'll have to implement it someday, right now I've managed to import the data through the task's GUI. Thanks again

Is there a free version control server provider for non-public projects?

I'd like to have a version control server (preferably SVN) accessible on the internet without having to host my own (linux) server. Setting up a home server ala DynDNS is not really an option.

Can you have non-public (maybe single-user) projects on one of the OSS project hosting sites? Or are there alternatives?

I had a look at Google Code. But that looked very public to me.

Any help would be greatly appreciated :-)

From stackoverflow
  • Unfuddle - has an option that is free. and not public.

    : I tried this one and it looks like the best offer with its 200 MB for 2 users. Also quiet speedy.
    sirrocco : I also use it and am quite pleased with it :)
  • Give a look to :

    Tuminoid : +1 for XP-dev, its awesome.
    : I'll have to take a closer look at XP-Dev, too. Number-wise it looks like the best offer. Unfuddle has a nice interface and generally seems solid (I tried it first)
    CMS : @ttobiass: You'll be happy with XP-Dev :)
    Dan Esparza : Unfuddle also does Git hosting, no?
    CMS : Yep, you're right, I haven't noticed, answer updated...
    bendewey : +1 I'm going to give OpenSVN a try thanks.
    Robert Koritnik : OpenSVN has **closed its business**. Unfortunately. Nothing that's free lasts. Obviously. Unless you switch hosts on a regular basis.
  • There's also OpenSVN

    Robert Koritnik : Service **CLOSED**.
  • cvsdude has free plan. Very limited though.

  • Assembla has a free (a bit limited) plan and from the FAQ you can make a project private. Supports "Subversion, Git, Mercurial [and Trac]".

    bitbucket.org supports only Mercurial and the free plan allows one private repository.

    SSH Control offers "GIT, HG (Mercurial), SVN (Subversion) over SSH" and is free for small projects.

  • Beanstalk has a free hosting option, although it's limited to 20MB repositories.

    : "Version control with a human face" lol@ that tag line Thanks for the tip. Looks like a nice offer
  • Code spaces has a free option. It's limited, but I have simple needs so I've been happy with them.

    Robert Koritnik : Not free since autumn last year I think. Basic account is rather cheap (2.99$/month) and it offers 1GB space and unlimited number of projects.
  • You might want to check out origo. They offer a subversion repository, a wiki and an issue tracker.

    It is free for both open source and closed source (private) projects.

  • Most hosts with cpanel have a compete control panel for setting up SVN. If you want dead-simple, that's it.

    Setting up your own repository is a rewarding experience. It will also prepare you for all the headaches you're bound to encounter when you have to do your first branch merge. I would recommend you taking the time to familiarize yourself with subversion.

  • Don't forget to check out Bazaar, a cross-platform, distributed revision control system which is easy to learn as a first system, and easy for CVS and Subversion people to use. It can act as a front end for Subversion repositories, and it's also insanely easy to work with in terms of branching and merging when compared to Subversion or CVS.

    It's slightly slower than git, but it's also cross-platform and runs excellently on both Linux and Windows systems, and it has a very active community behind it.

    PhiLho : I agree (having chosen Bazaar finally) but you don't answer the question. An answer would have pointed to Launchpad, for example (what other sites with Bazaar support?). Or the fact that FTP support makes Bazaar work on any site.
  • ProjectLocker also has private free Subversion hosting and free Git hosting, up to 300 MB. You get unlimited repositories (projects), and each comes with a Trac as well.

    Disclaimer: I work for ProjectLocker.

  • http://www.codespaces.com has a 500MB FREE plan with unlimited repositories.

    Robert Koritnik : Not any more. But it does have a 2.99$/Month plan for 1GB and unlimited projects. I'm using it for more than a year and I worked well all the time. When I had to renew I was considering other options but decided to stay with CS since I was really satisfied and it is rather cheap.
  • I like xp-dev, They provide SVN repository. I tryed Assembla but I didn't like when they requested me to upgrade from a free to a paid plan.

    They said in the e-mail that I didn't need to ugrade my plan, but I wouldn't be able to work in the space nor commit to the repository.

    So, if you don't want to expend money, DON'T subscribe to Assembla services. You can read an excerpt from the mail they sent to me here:

    "DO I NEED TO UPGRADE EVERY SPACE? No. On the upgrade page, we ask you to make a decision about all of your spaces. This is not required. You can upgrade an individual space by selecting the space name and navigating to the Admin tab.

    WHAT HAPPENS TO UNSUPPORTED SPACES? After January 9 we will restrict access to private, unsubscribed spaces. This is not an emergency. We are not going to expose your information, and we will not delete your data or cut off your access. On January 9, we will put unpaid private spaces into a read-only mode. You will not be able to work in the space or commit to the repository. You will be able to log in and see your data and download exported repositories or data for the next six months."

How to get a stack for exception.

Hi guys

I have a Winform application (C#) which imports some functions from dll.

Sometimes when running the application i get the following exception:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

I catch it in AppDomain.CurrentDomain.UnhandledException.

But i see no stack. How do i get a stack?

Thanks.

From stackoverflow
  • This exception occurs outside of the scope of your program in the interop plumbing of the CLR, and can only be captured by attaching an external debugger to the process. I suggest using WinDbg (debugging tools for windows).

    -Oisin

Best way to test SQL queries.

So i have run into a problem in that we keep having complex SQL queries go out with errors.

essentially this results in sending mail to the incorrect customers and other 'problems' like that.

What is everyone's experience with creating SQL queries like that, essentially we are creating new cohorts of data every other week.

so here are some of my thoughts and the limitations to them.

Creating test data - whilst this would prove that we have all the correct data it does not enforce the exclusion of anomalies in production. That is data that would be considered wrong today but may have been correct 10 years ago, it wasn't documented and therefore we only know about it after the data is extracted.

Create Venn diagrams and data maps - this seems to be a solid way to test the design of a query, however it doesn't guarantee that the implementation is correct. it gets the developers panning ahead and thinking of what is happening as they write.

Thanks for any input you can give to my problem.

From stackoverflow
  • You might want to check DbUnit, so you may try writing unit tests for your programs with a fixed set of data. That way you should be able to write queries with more or less predictable results.

    The other thing you might want to do is profile your SQL Server execution stack and find out if all the queries are indeed the correct ones, e.g., if you are using just one query which returns both correct and incorrect results, then clearly the query being used is in question, but what about if your application is sending out different queries at different points in the code?

    Any attempt to fix your query then would be futile... the rogue queries might still be the ones firing up the wrong results anyway.

  • You wouldn't write an application with functions 200 lines long. You'd decompose those long functions into smaller functions, each with a single clearly defined responsibilty.

    Why write your SQL like that?

    Decompose your queries, just like you decompose your functions. This makes them shorter, simpler, easier to comprehend, easier to test, easier to refactor. And it allows you to add "shims" between them, and "wrappers" around them, just as you do in procedural code.

    How do you do this? By making each significant thing a query does into a view. Then you compose more complex queries out of these simpler views, just as you compose more complex functions out of more primitive functions.

    And the great thing is, for most compositions of views, you'll get exactly the same performance out of your RDBMS. (For some you won't; so what? Premature optimization is the root of all evil. Code correctly first, then optimize if you need to.)

    Here's an example of using several view to decompose a complicated query.

    In in the example, because each view adds only one transformation, each can be independently tested to find errors, and the tests are simple.

    Here's the base table in the example:

    create table month_value( 
        eid int not null, m int, y int,  v int );
    

    This table is flawed, because it uses two columns, month and year, to represent one datum, an absolute month. Here's our specification for the new, calculated column:

    We'll do that as a linear transform, such that it sorts the same as (y, m), and such that for any (y,m) tuple there is one and only value, and all values are consecutive:

    create view cm_abs_month as 
    select *, y * 12 + m as am from month_value;
    

    Now what we have to test is inherent in our spec, namely that for any tuple (y, m), there is one and only one (am), and that (am)s are consecutive. Let's write some tests.

    Our test will be a SQL select query, with the following structure: a test name and a case statement concated together. The test name is just an arbitrary string. The case statement is just case when test statements then 'passed' else 'false' end.

    The test statements will just be SQL selects (subqueries) that must be true for the test to pass.

    Here's our first test:

    --a select statement that catenates the test name and the case statement
    select concat( 
    -- the test name
    'For every (y,m) there is one and only one (am): ', 
    -- the case statement
       case when 
    -- one or more subqueries
    -- in this case, an expected value and an actual value 
    -- that must be equal for the test to pass
      ( select count(distinct y, m) from month_value) 
      --expected value,
      = ( select count(distinct am) from cm_abs_month)  
      -- actual value
      -- the then and else branches of the case statement
      then 'passed' else 'failed' end
      -- close the concat function and terminate the query 
      ); 
      -- test result.
    

    Running that query produces this result: For every (y,m) there is one and only one (am): passed

    As long as there is sufficient test data in month_value, this test works.

    We can add a test for sufficient test data, too:

    select concat( 'Sufficient and sufficiently varied month_value test data: ',
       case when 
          ( select count(distinct y, m) from month_value) > 10
      and ( select count(distinct y) from month_value) > 3
      and ... more tests 
      then 'passed' else 'failed' end );
    

    Now let's test it's consecutive:

    select concat( '(am)s are consecutive: ',
    case when ( select count(*) from cm_abs_month a join cm_abs_month b 
    on (( a.m + 1 = b.m and a.y = b.y) or (a.m = 12 and b.m = 1 and a.y + 1 = b.y) )  
    where a.am + 1 <> b.am ) = 0 
    then 'passed' else 'failed' end );
    

    Now let's put our tests, which are just queries, into a file, and run the that script against the database. Indeed, if we store our view definitions in a script (or scripts, I recommend one file per related views) to be run against the database, we can add our tests for each view to the same script, so that the act of (re-) creating our view also runs the view's tests. That way, we both get regression tests when we re-create views, and, when the view creation runs against production, the view will will also be tested in production.

  • Create a test system database that you can reload as often as you wish. Load your data or create your data and save it off. Produce an easy way to reload it. Attach your development system to that database and validate your code before you go to production. Kick yourself everytime you manage to let an issue get into production. Create a suite of tests to verify known issues and grow your test suite over time.

  • Re: tpdi

    case when ( select count(*) from cm_abs_month a join cm_abs_month b  
    on (( a.m + 1 = b.m and a.y = b.y) or (a.m = 12 and b.m = 1 and a.y + 1 = b.y) )   
    where a.am + 1 <> b.am ) = 0  
    

    Note that this only checks that am values for consecutive months will be consecutive, not that consecutive data exists (which is probably what you intended initially). This will always pass if none of your source data is consecutive (e.g. you only have even-numbered months), even if your am calculation is totally off.

    Also am I missing something, or does the second half of that ON clause bump the wrong month value? (i.e. checks that 12/2011 comes after 1/2010)

    What's worse, if I remember correctly, SQL Server at least allows you less than 10 levels of views before the optimizer throws its virtual hands into the air and starts doing full table scans on every request, so don't over-do this approach.

    Remember to test the heck out of your test cases!

    Otherwise creating a very wide set of data to encompass most or all possible forms of inputs, using SqlUnit or DbUnit or any other *Unit to automate checking for expected results against that data, and reviewing, maintaining and updating it as necessary generally seems to be the way to go.

Unit Test Adapter threw exception: Unable to load one or more... in ASP.NET MVC

Using ASP.NET MVC 1.0 (current) I create a new default ASP.NET MVC project using Visual Studio 2008 on an x64 machine (Server 2008) and accept all the defaults and build and run it. Apart from having to set the System.Web.* assemblies as "Copy Local" it runs and brings up the default web app. When I try and run the unit tests on this project I get:

Unit Test Adapter threw exception: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..

Now if I repeat the same exercise using VS2008 on an x86 machine (Server 2003) then all 27 default unit tests run fine. (Also I don't need to mark the System.Web.* assemblies as "Copy Local")

Ideas for resolving the exception?

More Info: After trying some of the solutions suggested I started commenting out parts of the boilerplate test code that is generated with a new project. As such, I believe that the error is being generated by the inclusion of one of the following classes:

    public class MockIdentity : IIdentity
    {
        public string AuthenticationType
        {
            get
            {
                return "MockAuthentication";
            }
        }

        public bool IsAuthenticated
        {
            get
            {
                return true;
            }
        }

        public string Name
        {
            get
            {
                return "someUser";
            }
        }
    }

    public class MockPrincipal : IPrincipal
    {
        IIdentity _identity;

        public IIdentity Identity
        {
            get
            {
                if (_identity == null)
                {
                    _identity = new MockIdentity();
                }
                return _identity;
            }
        }

        public bool IsInRole(string role)
        {
            return false;
        }
    }

    public class MockMembershipUser : MembershipUser
    {
        public override bool ChangePassword(string oldPassword, string newPassword)
        {
            return newPassword.Equals("newPass");
        }
    }

    public class MockHttpContext : HttpContextBase
    {
        private IPrincipal _user;

        public override IPrincipal User
        {
            get
            {
                if (_user == null)
                {
                    _user = new MockPrincipal();
                }
                return _user;
            }
            set
            {
                _user = value;
            }
        }
    }
From stackoverflow
  • Do you have VS 2008 SP1 and .NET 3.5 SP1 installed in your Win2k8 box? By default VS 2008 installed 3.5 framework, but NOT SP1. Make sure you have both the framework SP1 and VS 2008 SP1 installed.

    Guy : Yes - got both installed - thanks for the idea though.
  • First, have you tried it in Release configuration? Have you done a clean on your solution?

    Have you tried constructing your test project? Take out the source files for your tests, delete the project from your solution and add a new test project that references the MVC app. Then re-add the test source files.

    Edit

    Are the classes and interfaces that you are using and implementing in scope from your tests?

    Edit Is it referencing the x64 not the x86 dlls?

    Guy : Thanks for the ideas Daniel but still no luck.
    Guy : Yes - remember that this all works when the project is checked out on an x86 machine.
    Guy : I don't know - how do I tell?
    Daniel A. White : Doesn't the debugger show what dll's are loaded?
    Guy : During the running of the unit tests? If so, where would I see them?
  • Did you try building your project as x86 project (Project properties ->Build ->Platform target) on x64 machine?

    Also, not sure about your unit testing toolkit, but NUnit, for example, can run as tests as either x86 or x64 (on x64 machine). If one of your assemblies accesses some 32-bit code (e.g. COM object), trying to run them under x64 will result in "Unable to load one or more of the requested types" error.

    Guy : I'm running MSTest - the default unit tester that comes with VS2008. I've tried building the projects as both x86 and x64. Thanks for the help.
    bh213 : Well, if x86/x64 is not an issue, then should only leave actual assembly files. I'd copy all files needed (Dlls) to a new directory and try running using MSBuild command line. When it works on x86 machine, just copy over to x64 and see if it works there.
    Guy : Can you explain that in more detail? I don't exactly follow what you'd do here...
  • I'm not sure about the subtleties of what's going on with the x64 verus x86, but using custom identity/principals can cause some interesting little glitches to happen, especially if using cassini (the built-in vshost webserver - which I think is what you end up using by running local unit tests within VS). I ran into this issue before, and rather than detailing it here, I'll post a link to some good info. Again, I'm not sure if this is related to your problem (my not being an MVC guru), but take a read through this. Food for thought:

    http://www.lhotka.net/weblog/UpdateOnMyStrugglesWithTheASPNETDevelopmentServer.aspx

    EDIT: so ultimately, this may be an issue of serialization failure, even if this particular edge case is not relevant. Have you tried marking your mocked iidentity/iprincpal objects as [serializable]? Remember that visual studio is a 32bit application; perhaps testing it on IIS (if not cassini) with a 64bit application pool is causing a context switch somewhere which causes the mock identities (if they get assigned as a thread's identity) to get marshalled across a boundary like that - the lack of a [serializable] attribute will probably cause a TypeLoadException.

    Does it still throw if you set IIS to use a 32bit application pool (on your 64bit server)?

    -Oisin

    Guy : Is IIS involved when you're running unit tests from VS2008? I didn't think that it was...? From my understanding unit tests don't spin up Cassini or use IIS...
    x0n : sorry, yeah, you're surely right. I wasn't really thinking about the unit test stuff - that runs as a standard library project, right? I was thinking for a moment that those tests ran inproc with the webserver... i'm not really a unit test guy (yet)
  • I'm wondering if the more significant difference is 2k8 vs 2k3 than 64 vs 32bit. Did you spawn Visual Studio as Administrator? An assembly might be missing due to the Virtual Store of windows 2k8. If this is a development desktop running 2k8 you might want to consider disabling the Virtual Store, it's in you policy labeled as "User Account Control: Virtualize file and registry write failures to per-user locations"

    Guy : Yes I am running VS2008 as Admin. Yes it's a 2k8 server being run as a desktop development environment. UAC is disabled on this machine.
  • I notice some of the types (specifically IIdentity and IPrincipal) you are implementing are not located within a System.Web.* assembly.

    Have you tried marking the System.Security.Principal assembly as "Copy Local"?

    Guy : That assembly is not being referenced in the project so not possible to mark as Copy Local.
  • This reminded me of an old blog post I once read. Perhaps you can use the same technique to debug the cause of the error:

    http://www.agileprogrammer.com/oneagilecoder/archive/2007/11/17.aspx

How to access Actionscript from Javascript in Adobe AIR

I have an AIR application written in html/javascript and I want to use the Actionscript print functions but I have no experience in Actionscript for AIR.

Where do I put the Actionscript code ? Does it go into an mxml file or does it need to be compiled into a Flash application. Where do I put it and how do I include it into the html document ? Finally, how do I call the AS function from Javascript ?

=====update=====

I know I have to compile either an .mxml or .as file into .swf using mxmlc and I have the following in my .as file:

package {
    import mx.controls.Alert;
    public class HelloWorld {
        public function HelloWorld():void {
            trace("Hello, world!");
        }
    }
}

Or alternately, this in a .mxml file:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
       import mx.controls.Alert;

           public function HelloWorld():void {
               Alert.show("hello world!");
               trace("Hello, world!");
           }
        ]]>
    </mx:Script>
</mx:Application>

This compiles OK, but when I include it in a html file with:

<script src="actionscript.swf" type="application/x-shockwave-flash"></script>

I get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at mx.managers::FocusManager/activate() at mx.managers::SystemManager/activateForm() at mx.managers::SystemManager/activate() at mx.core::Application/initManagers() at mx.core::Application/initialize() at actionscript/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/initializeTopLevelWindow() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler() at mx.managers::SystemManager/docFrameListener()

Any ideas what that means ?

From stackoverflow
  • You have to use air.trace where air is a predefined Javascript wrapper over utility AS packages.

    I was assuming you were doing AIR development using HTML/AJAX.

    However, otherwise, you need to use ExternalInterface to have the AS functions available to JS. Can you tell us why you need this?

Should you restrict developers internet access?

Our (small to medium-sized) company is going to start enforcing an internet policy which everyone, including the team of 4 senior developers, will be subject to.

Amongst other things, this means that developers will not be able to access:

  • web based e-mail (Hotmail, Yahoo, Googlemail)
  • instant messaging accounts (MSN Messenger)
  • social networking sites (Facebook)
  • streaming media (internet radio)

At the moment, we don't have any restrictions on our internet use, so I really want to find out what the effect on the team will be.

Please let me know your thoughts. What effect do you think this will have on the team (positive or negative).

From stackoverflow
  • Being treated like a child. That can't have any bad effects, can it?

    Adam Robinson : +1, amazingly on the nose
    Varkhan : Yeah... also, Craig, you should better start looking for another job, for I don't foresee a bright future for your company...
    Darryl E. Clarke : +1, very very true.
    cletus : Sorry but this issue is way more complex than that, despite all the people voting for what they want to hear.
    Alister Bulman : Of course it's more complex. Just let everyone eat the bread, and watch the circus.
  • Why will you be doing this? Have you had problems with it in the past? It seems to me like premature optimization. If someone doesn't get his work done, fire him. Simple as that.

  • I'd be out of commission: I live on railscasts.com, etc.

    If you're going to go nazi, why not just watch what is being done as it is now and try to curtail abuses? Hitting everyone with this right out of the gate assumes that everyone is an abuser and your morale dive will reflect this. I don't support doing the Big Brother on your employees, but if you're going to go down the evil empire road, you might as well do yourself a favor and not alienate your entire employee base.

    Either way, you'll regret the decision. Deal with problem employees as problem employees. Don't treat everyone as guilty from the get-go.

  • You might want to block online job-search sites too, because they're probably going to start using them as soon as you block the other ones. I know I would.

    Australian Study Says Web Surfing Boosts Office Productivity

    cletus : You'll note that study also shows that there are limits beyond which it becomes basically addiction and not productive at all.
    Alister Bulman : and get another ream of paper in - there'll be a run on the printer for resume/CVs
    Adam Robinson : @cletus: clearly the way to combat that is simply to eliminate access altogether
  • Developers aren't monkeys, and neither are your other employees. If you need to monitor, fine, but taking away any form of distracting internet browsing is just going to make your team members spend more time finding ways around it (and they will) than they might "waste", and they'll resent you.

    Edit:

    I'm "baffled" by the fact that so many people don't seem to grasp that internet access can be -- and, I would venture to say, often is -- considered to be part of compensation. A developer (or any employee) has just as much of a right to expect unfettered internet access as a business owner or manager has to deny it. It's no different from any other amenity in this regard; if I have a prospective (or current) employer who offers me full access and one that doesn't but is otherwise equivalent, I'm going to go with the one who offers it, just as I'd go with one that offers me other bonuses like a gym, sponsorship deals, or better health insurance rates. The beauty of the capitalist system allows the wisdom of a particular business decision to be borne out in the aggregate success (or lack thereof) of the people and businesses that make it.

    You can view it as a sense of entitlement if that fits your "them darn kids" sensibilities, but a sense of entitlement is what runs the business model. Workers feel they're entitled to their compensation, businesses feel they're entitled to the employee's work. They come to the mutual agreement that they'll trade one for the other. Internet access isn't any different.

    And so, if you're providing them with full access now and plan to limit that, then expect the same reaction you'd get from limiting any other benefit.

  • If it's a small company I think that the team leaders/managers should know what's going on and provide discipline when required.

    Blocking of sites should only be required if the working culture within the company is poor.

  • If you really really have to then restrict Facebook, YouTube and so on, leave access to sites and forums about developing. I would leave some internal messaging system between them so they can complain about it and make a plan to start they own company, buy yours and fire all the bosses...which means all that will most probably have negative effect.

  • I don't quite like the idea... In the company I work for they disabled all web pages that contained blog in the url, and we had to make requests to get access to a couple of boost proposed libraries that are held in such servers.

    Me and a couple other colleagues have snippets, instructions, comments from other developers in our personal email accounts on common servers.

    I can see and understand streaming media and social networks, but the problem is that when you start you must set the line at one point or another and getting the right point is probably not easy.

    Also this kind of moves discourage the workers, it removes part of the feeling of belonging as it turns the company into an opponent. The company can be seen as the external entity you fight against. The company does not belong to you, you no longer belong to the company.

    Orion Edwards : +1. The comment about turning the company into an opponent is spot on.
  • What's the point? Even if i go check my mails, visit dating sites etc. it only provides me with brief scenery changes, refreshes me and adds a little joy in a boring routine day.

    I check gmail all the time. In fact on many days the page is constantly open. I don't want to be cut out from the rest of my life.

    Instant messaging could be a distraction. But we use Skype as a standard way of communication between colleagues.

    Social networking sites? Being not a user of those cannot say.

    Streaming media? I constantly listen to my favourite radio with classic music. It give me a great boost in productivity.

    Don't see what you wish to achieve? You'll just irritate people, they will get depressed and their productivity will drop. Someone maybe will go somewhere else.

    cletus : Social networking sites are the real problem though (in my experience) because for some people they're easy to get carried away on (arguably addicted).
  • Agreeing with everyone below, trust and honesty will get your farther then silly attempts to restrict. Anyone who really wants to subvert these restrictions can use open proxies and all sorts of fun tricks.

    You're just making it annoying to work. If you have to restrict web access to make sure your employees are working, you've got larger cultural and work ethic problems to address. You are also unfairly punishing good employees. If you have specific problems with specific people deal with them on an individual basis.

  • The only logical reason for blocking sites is to preserve bandwidth if you're billed by the usage. Other than that, monitor and fire the abusers. I know it echos what's already been said, but having come from a few large companies that tried several variations on the theme, blocking internet usage never has the intended effect - never.

  • You're solving the 'slackers' problem the wrong way.

    If you want to know the effect ask your staff. Tell them the 'problem' that needs solving (time wastage, bandwidth costs, etc) and the proposed solution. I'm sure they can do self governance better than IT.

    Failing that, you're really just admitting that your management team can't manage problems and you have to use accountant like 'rules' to solve people problems.

    This action will reflect badly on you (the management), and induces low morale to your staff as you're telling them you have no people skills or clue.

  • My question would be how much of these kinds of sites are being visited now? While we can speculate on its effects and describe what would happen if we had to live with it, there isn't any data to analyse what is currently going on. Perhaps those developers don't visit those kinds of sites at work and thus the effect is nothing is one possibility with an unknown probability.

  • When I lived in Romania, if one person in the apartment building didn't pay their hot water bill, they shut it off for the whole building.

    Where are your bosses from?

    : Your first point is a good one. The second point is just needlessly insulting. Also, I'll bet that the tardy person paid their water bill after that. Not that I'm condoning it. I'm just saying that glib answers don't solve complex problems.
    Adam Robinson : They are, however, often adept at pointing out the absurdity of proposed solutions.
    Kyralessa : Oh, now. As the saying goes, some of my best friends are Romanian. :) By the way, not only did they shut it off for everyone, they posted in the lobby a list of the bills and who did and didn't pay. I expect the system is a holdover from Communist times.
  • I've worked at a company that decided to ban anything with 'blog' in it (apparently "blogs are bad.... mmmmkay?"), which was a pretty ridiculous stance for development. They would add appropriate ones on a case by case basis but that just wasn't practical.

    It's at this job that I discovered SSH tunnelling where I created my own proxy back to my home machine to get a clean feed of the internet. There's not a lot you can do to stop that either.

    Someone else also quoted Workplace web bludging 'good for productivity':

    "People who do surf the internet for fun at work - within a reasonable limit of less than 20 per cent of their total time in the office - are more productive by about nine per cent than those who don't,"

    Curious language. 9% more productive overall or 9% more productive for the remaining 80% of the time? Also, cause isn't necessarily established. It may just be incidental to other factors.

    Anyway, I've seen plenty of cases where people spend all day on some sites. Biggest offenders are:

    • Facebook (by far the #1);
    • MySpace;
    • Ebay;
    • Sports sites;
    • Messenger sites (Google/Yahoo/Live/etc);
    • Youtube.

    Of those I think only Youtube has potential work-related use (lots of people post video tutorials and so forth).

    I found the attitude (here and IRL) from some people to be somewhat bizarre with regards to this. I personally have no problem with blocking the first five from that list. You're there to do a job, not check or update the profile of you or your friends. The idea that you should be paid to sit on Facebook for 2 hours (20% from above) a day I find patently ridiculous. Do it on your own time.

    In my office there's an issue of a magazine called Nett that has this on the front cover:

    "Why aren't I the boss yet?" Generation Y enters the workforce

    I think this is a pithy way of characterising this issue and I think it is particularly a Gen-Y thing: that sense of entitlement that colours this issue (and many others). The expectation of a fair day's work for a fair day's pay and the realization that you aren't doing anyone any favours by showing up to work to spend half the day on Facebook will hold you in better stead than demanding Facebook access or somehow thinking it justifies changing jobs if you don't get it.

    Metro Smurf : +1 for the generation y-hiners.
    Dave Sherohman : If 2 hours is 20% of your work day, then you *are* doing it on your own time. (2 hours is 20% of 10 hours, which would presumably mean the 8 hours that salaried employees are paid for, plus two hours of your own, unpaid, time.)
  • IM can be useful for development work. I frequently ask other developers things via IM and they also ask me. Facebook, internet radio and the like are useful for short 1-2 minute breaks, and such short breaks usually improve productivity.

    aib : Good point about IMs. I do that too.
    Ryu : Use an Internal IM like IRC or Jabber
    Bob The Janitor : use in internal chat client like jabber, that way the only people the can chat with are who there are support to be chatting with
  • If I was part of your company, I'd QUIT!

    For one, you will have to block ALL of the internet because otherwise they will just use Proxies to access their mail and any other black-listed sites. But if you do that, then how will your programmers use the internet professionally to conduct researches using Google or ask technical questions on StackOverflow?

    If you see a few programmers watching some videos on YouTube, why do you even care if at the end of the day they deliver? If they are late on their projects (most software companies are), then do they have valid explanations?

    Sometimes where I work, I won't feel like working for hours during the day and I'll browse a bit or do a bit of research by reading on the net. But then at night somewhere around 22:00 and midnight, where I'm more productive (and my boss doesn't see me), I'll get done what I missed out during the day and usually a lot more! My point is that my bosses aren't on my back for when its done and where it gets done. They just care that it does actually get done by the due date!

    Update:

    But where do we draw the line on unproductive habits? For example, I'm NOT a smoker, but when I walk by the hall I will always see the same group of people smoking. During a meeting once, which took a whole day, I could see outside and saw who smoked, so I counted how many times I saw people and tracked the average "smoke break". [I'm not a boss by the way]. Some people will go out and smoke as often as 6 or more times per day, while the average time was about 10 minutes. This is an entire hour wasted due to smoking... should we ban smoking at work also?

    I would agree that productivity loss due to the internet should be controlled by possibly banning the top 'social networks'. But anything else is pure control by the employer because not everyone will abuse the system. Don't punish everyone because of a few bad apples. Handle each abusive employee case by case and the example will be set for everyone.

    Ross : Not entirely true. Most web filtering packages can find proxies and block them on the fly. While they can be problematic (a classic example is blocking a page containing "Sussex" or "Essex") I've used perfectly fine solutions if you're using the internet honestly.
  • All those things beside WORK is call Life. If you have no life, good for you. I use all those "side" tools to get things done, get information, link with others.

    Those restrictions, as somebody else said, can be bypassed pretty easily by a 10 year old kid. Free web proxies are available anywhere on the net. Schools use protection to prevent kids from getting on porn sites, and they access them anyway!

    So you should tell people the problem in a big meeting and ask them for a solution. Sometimes they will find a solution which is harder on them than you could have proposed yourself. Things will almost stop for the next week, but the next and other weeks will become better and better.

    Keep an eye on your employees, as you would for stealing stuff - stealing time is the same thing. Give warnings to abusers, and let the others live !

  • Are you nuts?!

    EDIT -- Joke Disclaimer

    This humor does not reflect the thoughts or opinions of either myself, my company, my friends, or my cat; don't quote me on that; don't quote me on anything; you may distribute this posting and all its associated parts freely but you may not make a profit from it or include the posting in commercial publications; further redistributions of this document or its parts are allowed; jokes are subject to change without notice; jokes are slightly enlarged to show detail; any resemblance to actual persons, living or dead, is unintentional and purely coincidental; hand wash only, tumble dry on low heat; do not bend, fold, mutilate, or spindle; your mileage may vary; no substitutions allowed; for a limited time only; this offer is void where prohibited, taxed, or otherwise restricted; humor is provided "as is" without any warranties expressed or implied; user assumes full liabilities; not liable for damages due to use or misuse; an equal opportunity joke employer; no shoes, no shirt, no jokes; quantities are limited while supplies last; if defects are discovered, do not attempt to fix them yourself, but return to an authorized joke service center; caveat emptor; read at your own risk; parental advisory - explicit lyrics; text may contain material some readers may find objectionable, parental guidance is advised; keep away from sunlight, pets, and small children; limit one-per-family please; no money down; no purchase necessary; you need not be present to win; some assembly required; batteries are not included; action figures sold separately; no preservatives added; safety goggles may be required during use; sealed for your protection, do not use if the safety seal is broken; call before you dig; for external use only; if a rash, redness, irritation, or swelling develops, discontinue use; use only with proper ventilation; avoid extreme temperatures and store in a cool dry place; keep away from open flames and avoid inhaling fumes; avoid contact with mucous membranes; do not puncture, incinerate, or store above 120 degrees Fahrenheit; do not place near flammable or magnetic source; smoking these jokes may be hazardous to your health; the best safeguard, second only to abstinence, is the use of a good laugh; text used in these jokes is made from 100% recycled electrons and magnetic particles; no animals were used to test the hilarity of these jokes; no salt, MSG, artificial color or flavor added; if ingested, do not induce vomiting, if symptoms persist, consult a humorologist; jokes are ribbed for your pleasure; slippery when wet; must be 18 to enter; possible penalties for early withdrawal; slightly higher west of the Rockies; allow four to six weeks for delivery; disclaimer does not cover hurricane, lightning, tornado, tsunami, volcanic eruption, earthquake, flood, and other Acts of God, misuse, neglect, unauthorized repair, damage from improper installation, typos, misspelled words, incorrect line voltage, missing or altered serial numbers, sonic boom vibrations, electromagnetic radiation from nuclear blasts, customer adjustments that are not covered in the joke list, and incidents owing to motor vehicle accidents, airplane crash, ship sinking, leaky roof, falling rocks, mud slides, forest fire, broken glass, flying projectiles, or dropping the item; other restrictions may apply. If something offends you, lighten up, get a life, and move on.

    zvolkov : Apparently most programmers are sooo freaking serious that I should specifically disclaim all my jokes as http://www.michaelclark.name/jokes/disclaim.shtml
  • I think the effect will be simple -

    You'll have an immediate, large negative impact on morale.

    You'll probably lose many of your better people, since they'd rather work in a company where they'll be treated with respect.

    Depending on the current culture, you will likely reduce productivity, overall.

    If your company faced with employees abusing internet usage, I'd look into dealing with the individual problems, not trying to impose a wide-scale blanket solution that will make everybody unhappy.

    cletus : The idea that the better people will all leave cos they can't get to Facebook anymore is alarmist and preposterous.
    Reed Copsey : @cletus: I agree - it's more the idea that management is that worried and micromanaging what I do, instead of trusting me to work effectively, would have a negative impact on morale. Over time, this will drive people away. I don't think it'll cause anybody to leave overnight. :)
    Reed Copsey : I watched something very similar happen at a large company where i worked - it wasn't that they did any one thing that was bad - it was the attitude and many small things, and lead to 42% turnover the year following the changes (the year of the changes very little happened)
  • I've always said to my friends that we developers are lucky. Unless there is a HUGE library in the building where we work and an equally big codebase at our fingertips, we NEED Internet access. IM'ing with fellow developers might be a point of debate, but basic Web access for simple research is usually not.

    I think there's a question on ethics in all this. What's the difference between talking on the phone and e-mailing/IM'ing friends at work? What's the difference between taking a smoke/coffee break and watching a few short video clips? True, the temptation for doing the latter ones might be higher when you're spending most of the day in front of computers, but that is a problem we must solve as a whole race.

    I dare say the slackers will find a way to slack off, with or without Facebook.

    cletus : Talking on the phone, going on long breaks, etc are all pretty obvious. The problem with the internet is you're quietly sitting at your desk doing nothing so it's a lot harder to tell. BTW IMing was included in the above list.
    aib : You can always sit quietly at your desk doing nothing.
  • This is pretty standard from the recent jobs I've had.

    I agree with @cletus: do it on your own time, you're not paid to play. Most employees won't have the know-how to bypass the security, so it will work.

    Not only is it about time-wasting, but it's also about security. Doing this helps stop the spread of viruses on the company's internal network.

    John Saunders : blogs are not playing, neither are sites like OS that could be considered social network sites. Also, the MSDN forums are all at http://social.msdn.microsoft.com/. Not smart to cut those off.
    Gary Kephart : And what the companies that I have worked for have done is to accept requests for exceptions to the rule. Everything I have asked for has been reasonable and accepted.
  • I have worked for companies on both ends of the spectrum.

    Usually the use of internet is a reflection of the overall culture of the company.

    For example, where internet access was unmonitored, professionals were treated as such. In a culture where internet access is restricted, policies that most people take for granted (flexible hours, breaks as needed, etc) are restricted as well.

    That said, there are often reasons WHY the company evolved into a more restrictive enviroment.

  • Effects on your team:

    Only the people who cannot leave will stay.

    You will be left with the least productive people.

    I strongly suspect this is not a real question, but rather a troll post because it is nothing more than an inflammatory statement that is certain to rile up any technical discussion group.

    cletus : People leaving over FAcebook? Either alarmist and unwarranted or be glad to be rid of them if it's that important to them.
    Adam Robinson : Who said they would be leaving "because of facebook?" Maybe it's the streaming media? Maybe it's the personal email? Or maybe it's because they don't like being treated like redheaded stepchildren who can't be trusted with the computers on their desk.
    01 : Id not leave right away but id stop caring about company.
    Craig HB : This is a real question -- there is a possibility that certain sites will blocked.
  • I've worked in places which restrict internet access, and some that haven't. Here are some of my experiences. (Note, I've never had anything to do with such decisions, I've just had to live under them)

    When you first turn on the restrictions, you'll get a HUGE backlash. While it's not as bad as making everyone take a paycut, it is still a very effective morale killer.

    Once things have been around for a while and people are used to things, it won't have a big impact as long as you are sensible in what you block. For example, nobody cares that facebook or ebay are blocked, as everyone feels kind of guilty spending time on facebook at work anyway. I found that having had things like this blocked seemed to be beneficial as far as productivity goes.

    If you take it too far and block sites or things that people find useful, then it gets really annoying, and people will start to invent workarounds and often make things worse. One company had a policy of blocking all .zip and .exe files from the internet - so people just downloaded things at home and brought them in on USB sticks (along with god knows what other things). This also made it incredibly hard for people to do their jobs (try download anything software related that's not in a zip file), which leads to massive amounts of time wasting as people try to find a non-zip-file form of downloading the software.

    Basically, I'd make a very small list of sites that you'd consider to be totally worthless (ebay, facebook, maaaaybe youtube, and not much more), and just block those. Going any further is going to cause you more pain than it's worth, and you're not going to gain anything back in "productivity"

  • If one can't be trusted to do their work, they shouldn't have been hired and if they are, they should be fired.

    All developers work differently and when you're stuck on a problem it's sometimes best to take a break for a few minutes. That make be going for a 10 minute walk or checking the news or your facebook page.

    Also, in our office a huge amount of communication is over IM. In fact, it use to be required we were signed in on MSN and Skype. It's much quicker then email and usually quicker than walking over to someone else's office.

  • It may not be work related, but the fact is if I'm at work 50+ hours a week, I will use personal email to coordinate my life outside of work. If you block gmail most people will just send their personal email from their work address.

    When I was at a company that blocked gmail and wouldn't let me change my reply-to address, I just wrote myself a simple email program that sent email that appeared to be from my gmail address.

    I think blocking any site is misguided, but blocking web mail is really dumb.

  • One thing that I haven't seen noted yet: all the MSDN and TechNet forums have "social" in their URLs: http://social.msdn.microsoft.com/Forums/, and http://social.technet.microsoft.com/Forums/.

    As for me, I'd be right out of a company that did this. I wouldn't be doing this only because I'd be getting treated as a child; I'd be doing it because it would be a clear indication of stupidity on the part of Management. Why stay with a company whose Management are actually stupid?

  • As a developer(not a manager) I fully appreciate the need for the occasional break or distraction in order to start back fresh and allowing access to sites and tools that help your team(developers or other) be more productive is smart business. I also think in today's environment allowing "reasonable" access in order to handle personal business during your off time(ie lunch) shouldn't be unexpected.

    However the idea that your employer somehow owes you unhindered internet access is quite hilarious I think. And expecting free reign as if it were part of your "compensation" is quite naive. It is a tool that, in the work environment at least, is there to help you to do of all things....your work...not to entertain you! Would you expect your employer to supply you with a TV at your desk for those times you don't feel like working or just need a break? I think not.

    Fry : At the same time, they could take away your phone because you might get distracting personal calls and the personal items on your desk just distract you, so screw it - lets ban those as well. Seriously? It's like taking away a grocery Checker's calulator. You're not required to supply them with one, but wouldn't you rather have a happy employee with all the tools to do their job or a frustrated one? Especially when it's cheaper and easier to have them be happy?
    Dan Adams : Having the appropriate tools to do your job is important but being entertained while your supposed to be working isn't. An employer shouldn't be expected to allow the grocery checker to watch a movie or update his/her blog while they are supposed to be using the calculator to take care of customers.
  • Humm...

    No Online Music = No work will get done

    No Online Music = No inspiration for designs

    No Online Music = No patience for bugs

    No Google = A shit-ton of books you are going to have to buy me.

    No Google = Many wasted hours on small well documented bugs (external software...)

    No Internet = Outdated technologies

    No Internet = No use of open source code

    No Internet = Screw it I would have quit by now.

  • Any restriction adds the company a minus.. How many minuses do you want? How many minuses you can add before people will start quitting? I don't know but you should try to find out the answers! ROFL

  • Be prepared to also scout every port on every machine for OpenVPN, SSH and other such circumvention technologies. That is, for example, how I get around the Great Firewall to access all the sites the Chinese government think I shouldn't see.

UINavigationController embedded within tabBarController

have any example or code can show how to embedded a UINavigationController within tabBarController,typically we develop application is from UINavigationController rather than tabBarController,so i am so confuse now can help

From stackoverflow

Cross-Platform Generic Text Processing in C/C++

Hi,

What's the current best practice for handling generic text in a platform independent way?

For example, on Windows there are the "A" and "W" versions of APIs. Down at the C layer we have the "_tcs" functions (like _tcscpy) which map to either "wcscpy" or "strcpy". And in the STL I've frequently used something like:

typedef std::basic_string<TCHAR> tstring;

What issues if any arise from these sorts of patterns on other systems?

From stackoverflow
  • One thing to be careful of is to make sure for all static libraries that you have, and modules that use these static libraries, that you use the same char format. Because otherwise your code will compile, but not link properly.

    I typically create my own t types based on the stl types. tstring, tstringstream, and even down to boost types like tpath_t.

  • There is no support for a generic (variable-width) chararacter like TCHAR in standard C++. C++ does have wchar_t, but the encoding isn't guaranteed. C++1x will much improve things once we have char16_t and char32_t as well as UTF-{8,16,32} literals.

    I personally am not a big fan of generic characters because they lead to some nasty problems (like conversion) and, what's more, if you are using a type (like TCHAR) that might ever have a maximum width of 8, you might as well code with char. If you really need that backwards-compatibility, just use UTF-8; it is specifically designed to be a strict superset of ASCII. You may have to use conversion APIs (especially on Windows, which for some bizarre reason is UTF-16), but at least it'll be consistent.

    EDIT: To actually answer the original question, other platforms typically have no such construct. You will have to define your TCHAR on that platform, or else use a library that provides one (but as you should no doubt be able to guess, I'm not a big fan of that concept in libraries either).

  • Unicode character set + the encoding that makes the most sense for your data. I typically use UTF-8 because it's convenient with traditional C / C++ functions and the data I deal with doesn't cause too much bloat.

    Some APIs (Windows) and cross language tools (Java) use UTF-16 so that might be a consideration.

    One practice I wish we had been better at is to leave text as an array bytes for doing low tech operations like copying, simple comparison, simple searching, etc. When you need the richer more character aware operations you can convert to some super string (icu strings are nice -- but heavy) and define the layers / entry points that need to do this as opposed to naively doing it everywhere. The needless conversations kills our performance -- especially when combined with an XML DOM library which also uses the "super" strings.