Skip navigation

Monthly Archives: September 2009

“watching nonprogrammers trying to run software companies is like watching someone who doesn’t know how to surf trying to surf”

I read that, and i’m like THANK YOU

LOL!! joel refers to the 1984 mac commercial on page 32. He starts to point at how the whole MAC thing.. macusers have a distinct groovy personality from pc users. or something.

Advertisements

Instead of fighting with libcurl you could just use WinInet for your http needs if you are married to the Windows platform.

A quick example follows, great article, and as usual pretty difficult to navigate msdn docs

#include <windows.h>
#include <wininet.h>

#include <stdio.h>
#include <stdlib.h>

#pragma comment ( lib, "Wininet.lib" )

int main()
{
  HINTERNET hInternet = InternetOpenA("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );

  HINTERNET hConnection = InternetConnectA( hInternet, "you.appspot.com", 80, " "," ", INTERNET_SERVICE_HTTP, 0, 0 );

  HINTERNET hData = HttpOpenRequestA( hConnection, "GET", "/", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0 );

  char buf[ 2048 ] ;

  HttpSendRequestA( hData, NULL, 0, NULL, 0 ) ;

  DWORD bytesRead = 0 ;
  DWORD totalBytesRead = 0 ;
  // http://msdn.microsoft.com/en-us/library/aa385103(VS.85).aspx
  // To ensure all data is retrieved, an application must continue to call the
  // InternetReadFile function until the function returns TRUE and the
  // lpdwNumberOfBytesRead parameter equals zero. 
  while( InternetReadFile( hData, buf, 2000, &bytesRead ) && bytesRead != 0 )
  {
    buf[ bytesRead ] = 0 ; // insert the null terminator.

    puts( buf ) ;          // print it to the screen.
    
    printf( "%d bytes read\n", bytesRead ) ;

    totalBytesRead += bytesRead ;
  }

  printf( "\n\n END -- %d bytes read\n", bytesRead ) ;
  printf( "\n\n END -- %d TOTAL bytes read\n", totalBytesRead ) ;

  InternetCloseHandle( hData ) ;
  InternetCloseHandle( hConnection ) ;
  InternetCloseHandle( hInternet ) ;
  
}

google app engine

index.py

class Person( db.Model ) :
  name = db.StringProperty()
  
class TPerson( webapp.RequestHandler ) :
  def get( self ) :
    
    # run once
    '''
    people = [ 'John Hopkins', 'Bob Jordan', 'Mike Bobs' ]
    
    for person in people :
      p = Person()
      p.name = person
      p.put()
    '''
    
    people = db.GqlQuery( 'select * from Person' ).fetch( 1000 ) 
    
    # if you don't .fetch(), then the addition of dynamic
    # properties won't work here.
    for person in people :
      person.shortname = person.name[ 0:2 ]
    
    self.response.out.write( template.render( 'TPerson.html', { 'people' : people } ) )

application = webapp.WSGIApplication([
  
  ( '/TPerson', TPerson ),
  
  ], debug=True )



def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()

TPerson.html

{% for p in people %}
<p>{{ p.name }}</p>
<p>{{ p.shortname }}</p>
{% endfor %}

I got this error in my google app engine application

it says something to the effect of

<type ‘exceptions.ImportError’> Python 2.5.4: c:\python25\python.exe
Wed Sep 09 12:29:14 2009
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

c:\program files (x86)\google\google_appengine\google\appengine\tools\dev_appserver.py in _HandleRequest(self=)
2921 infile,
2922 outfile,
2923 base_env_dict=env_dict)
2924 finally:
2925 self.module_manager.UpdateModuleFileModificationTimes()
base_env_dict undefined, env_dict = {‘APPLICATION_ID’: ‘mohammad’, ‘CURRENT_VERSION_ID’: ‘1.1’, ‘REMOTE_ADDR’: ‘127.0.0.1’, ‘REQUEST_METHOD’: ‘GET’, ‘SERVER_NAME’: ‘localhost’, ‘SERVER_PORT’: ‘8080’, ‘SERVER_PROTOCOL’: ‘HTTP/1.0’, ‘SERVER_SOFTWARE’: ‘Development/1.0’}

Really the problem was I has put a leading slash in my app.yaml where one should not be

- url: /home
  script: /home/index.py

Really this should be

- url: /home
  script: home/index.py

So there was no leading slash on script: EVER.