Permalink
Browse files

Renamed posts with proper dates

  • Loading branch information...
1 parent 7cf8fe2 commit b32bfa7f582ff02f7567eb94849d842ed0515e25 @zmcartor committed Mar 20, 2013
@@ -0,0 +1,36 @@
+---
+layout: post
+title: "@SpeakingSecret Python Twitter Bot and Natural Language Processing"
+description: ""
+category:
+tags: ['python', 'NLP']
+---
+{% include JB/setup %}
+
+I’ve been playing around with the Twitter Tools library for Python after being inspired by Vivek Haldar’s post:
+
+
+
+My bot is fairly simple and is currently hosted on my github [here][2]. Instead of using Eliza for psychoanalysis conversation, I decided to go with Cleverbot as an alternative. Cleverbot has it’s own Python API [which is pretty fun][3].
+
+The SpeakingSecret bot is hosted on my laptop, so she might always be available for divination depending on astral connections. Be patient..
+
+**Going further, the Python Natural Language Toolkit**
+
+I’ve just started delving into the powerful NLTK to give this bot it’s own brain. Hooking it up to an AI like Cleverbot is fun, but I ultimately intend to create a pluggable interface that will allow different bot personalities to interact with those seeking wisdom on Twitter.
+
+[%2B] Python NLTK: [Project Page][4]
+
+[%2B] Great book on Python NLTK and the subject matter in general. [(Amazon)][5]
+
+[%2B] [Twitter Tools][6]
+
+[%2B] SpeakingSecret on [Twitter][7]
+
+ []: http://blog.vivekhaldar.com/post/2830035130/how-to-write-a-twitter-bot-in-python
+ [2]: https://github.com/zmcartor/SpeakingSecret
+ [3]: http://code.google.com/p/pycleverbot/
+ [4]: http://www.nltk.org/
+ [5]: http://www.amazon.com/Natural-Language-Processing-Python-Steven/dp/0596516495/ref=sr_1_1?ie=UTF8&qid=1304910337&sr=8-1
+ [6]: http://mike.verdone.ca/twitter/
+ [7]: http://twitter.com/#!/speakingsecret
@@ -0,0 +1,49 @@
+---
+layout: post
+title: "Coffeescript and QR Codes"
+description: ""
+category: 'code'
+tags: ['coffeescript' , 'html5']
+---
+{% include JB/setup %}
+
+The emerging prevalence of QR codes is slowly turning the urban landscape into a hyperlinked, cyber-punk augmented reality. These blocky, alien codes connect the terrestrial landscape with the limitless possibility of the Internet.
+
+![][1]
+
+For generating your own QR codes and turning your neighborhood into a Snowcrash-esque hyperreality; I present Blocky: A Client-side QR code library written in CoffeeScript.
+
+Blocky began as a way to generate configurable QR codes without relying on any 3rd party service. All QR code generation is performed clientside and displayed via HTML5 . I’m currently adding support for SVG and other types of display methods should the need arise. At it’s core, Blocky uses the awesome SVG library created by Kazuhiko Arasé. [1]
+
+**Let’s generate some funky QR codes!**
+
+The constructor signature looks like this:
+
+new Blocky( QR\_code\_message, id\_of\_container , config_object)
+
+A element is appended to the container.
+
+The config object takes the following values:
+
+* **cell_size**: the size of the QR cells. Generally just think of it as the size of the QR code. Default 4.
+* **black**: the color to use as ‘black’ in the QR code. pass as a quoted rgb value like “rgb(1,2,3)”
+* **white**: just like black, only… white.
+* **error_level**: the QR error level to use. Acceptable values: M , H , Q, L. Default H
+* **color_scheme**: there are several default color schemes avaialble.
+
+Try out these color_scheme values to get started: watermelon , wedding, arctic or spicy.
+
+Check out the project on Github: [Blocky on GitHub][2]
+
+References:
+
+[1] QR code lib by Kazuhiko Arasé
+
+
+
+[2] QR codes Wikipedia: [][4]
+
+ [1]: http://media.tumblr.com/tumblr_lx4t2taJjQ1r4xvaq.png
+ [2]: https://github.com/zmcartor/Blocky
+ []: http://www.d-project.com/qrcode/index.html
+ [4]: http://en.wikipedia.org/wiki/QR_code
@@ -0,0 +1,49 @@
+---
+layout: post
+title: "We can do better.. no more debugging with console.log"
+description: ""
+category:
+tags: []
+---
+{% include JB/setup %}
+
+This is an appeal to JS developers everywhere.
+
+We can do better than console.log when debugging our code. I know how easy it is to debug via console.log and how fun it is to hit ‘refresh’ and then eagerly check the Firebug or Chrome console. I know it’s almost like being a child at Christmas : *“What did console-claus output for me!!”*
+
+Errant debug statements are always cleaned from the code before it ships, right?
+
+(Yeah, probably…)
+
+For fun, keep the JS console open while browsing the Internet today. Be amazed at the hidden world of errant console.log(..) calls unfolding before your eyes..
+
+Oh, and console.log(..) crashes your shit on IE huh? That’s a real bummer.
+
+### What do to
+
+*TL;DR - You’ll be able to debug faster and may learn a thing or two about your code.*
+
+A symbolic debugger offers some big advantages over console.log(..)
+
+1. The ability to see the entire runtime environment at once, including local variable values. A complete view of the execution environment, not just a slice.
+2. The grind of ‘place debug code/refresh’ gets tedious and can turn into a time waster. A symbolic debugger speeds up the process through live tracing and dynamic breakpoints.
+3. No extra code to clean up after debugging is complete.
+
+Get familiar with Firebug Script Console, or the Chrome/Safari developer tools.
+
+**Chrome/Safari**
+
+
+
+**Firebug**
+
+
+
+
+
+###
+
+ []: http://www.we-are-gurus.com/blog/1578-avoid-console-log-error-with-ie "console.log and IE"
+ []: http://www.nsbasic.com/app/tutorials/TT10.htm "http://www.nsbasic.com/app/tutorials/TT10.htm"
+ []: http://getfirebug.com/javascript "http://getfirebug.com/javascript"
+ []: http://getfirebug.com/wiki/index.php/Script_Panel "http://getfirebug.com/wiki/index.php/Script_Panel"
@@ -0,0 +1,18 @@
+---
+layout: post
+title: "Why I still buy paper programming books"
+description: ""
+category: 'productivity'
+tags: []
+---
+{% include JB/setup %}
+
+I have a secret , I still pay money for and read *paper* programming books.
+
+When I’m reading a book, I’m the mood to learn something. Distractions must be eliminated. Electronic books exist on the computer, which is pretty much a massive sucking vortex of distraction.
+
+Books dont have hyperlinks. There’s only one thing to do with a book, read it. (and maybe throw it at a raccoon. but that’s different.)
+
+It’s impossible to cut/paste code from a paper book straight into an editor. (An urge that is sometimes hard to suppress with electronic books.) Typing in the code myself improves muscle memory and really makes the memory ‘sticky.’
+
+Books are also fun to lend out. And if you get a bunch of them on your bookshelf, people will think you’re smart* ;)
@@ -0,0 +1,12 @@
+---
+layout: post
+title: "There are no couches in the woodshop"
+description: ""
+category: 'productivity'
+tags: []
+---
+{% include JB/setup %}
+
+Dont waste time ‘thinking’ at a computer. Step away, and draw out the idea on paper, a whiteboard, lipstick on a mirror - whatever. This media is static - which is important if any thinking is to occur. Only after there’s something to say should the computer be in use. Remember, a computer is a distraction machine. You can’t check twitter while using a belt sander or Miter Saw.
+
+The woodshop is for DOING things. There is a reason people don’t hang out in the woodshop on a couch chatting or browsing catalogs. Treat your time at the computer as you would sitting at a workbench. You are paid for your thoughts. It just so happens you also know howto express your thoughts as executable code to a machine.
@@ -0,0 +1,162 @@
+---
+layout: post
+title: "iOS Network Testing"
+description: ""
+category: 'code'
+tags: ['ios' , 'testing']
+---
+{% include JB/setup %}
+[Permalink](http://hackazach.net/post/44988952817/ios-network-testing "Permalink to HackaZach; • iOS Network Testing")
+
+During development of an API client, do you require VPN connectivity to hit web service? Is a network service your app relies on a little less than completely reliable? oh and each network error handler has been tested to ensure things keep working, right? Yeah - Maybe not. Network testing can be a real pain in the ass. The aim of this article is to lower the aching pain in your backside while testing iOS apps; and to hopefully make it a part of normal workflow.
+
+This article contains a sample walk-through of testing an imaginary web service with ILTesting, AFNetworking and Kiwi. It’s assumed the reader is familiar with the basics of Cocoa Touch, XCode and project creation.
+
+If you’re a solid iOS dev but not familiar with Kiwi or AFnetworking, please check them out:
+
+[Kiwi][1]
+
+[AFNetworking][2]
+
+It should be noted the approach shown using ILTesting will work with most any testing framework or networking library on iOS.
+
+**Example DogPark Application**
+
+The example application repo is located here on Github: [DogPark][3]
+
+In our example application, we’ll be testing an implementation of an imaginary Dog Park API client. The client sends requests over HTTP and presently has two methods:
+
+{% highlight objective-c %}
+@interface HKZDogParkAPIClient : NSObject
+- (void)fetchProfile:(int)profileId block:(void(^)(NSDictionary *dog, NSError* error))clientBlock;
+- (void)signup:(void(^)(NSDictionary *dog, NSError* error))clientBlock;
+@end
+{% endhighlight %}
+
+We’ll get to the fun of testing a Dog Park API soon, but first a little about the network testing library we’ll be using.
+
+**Intro To ILTesting ([GitHub][4])**
+
+
+The magic behind ILTesting is simple: it ingeniously registers itself as an NSURLPrototcol handler thereby getting “first dibs” to handle HTTP requests from the application. (A more technically in-depth article on NSURLProtocol is available here : [NSHipster][5] .)
+
+The registration of a pre-defined HTTP handler effectively keeps our app from hitting the network. (This speeds up our tests!) But the main point is predictively crafting an HTTP response for a given URL.
+
+(If you’re wondering ‘why not just mock AFNetworking instead’, I shy away from mocking code that I did not write myself.)
+
+Let’s take a look at a couple ILTesting class methods:
+
+{% highlight objective-c %}
+// beforeEach/afterEach are Kiwi constructs
+
+beforeEach(^{
+ //register as Protocol delegate, the magic begins
+ [NSURLProtocol registerClass:[ILCannedURLProtocol class]];
+
+ // Default HTTP status code
+ [ILCannedURLProtocol setCannedStatusCode:200];
+
+ // Configure ILtesting only for certain verbs if you like
+ [ILCannedURLProtocol setSupportedMethods:[[NSArray alloc] initWithObjects:@"GET",@"POST", @"PUT", nil]];
+
+ // Default headers. Ill be returning JSON here.
+ NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
+ [headers setObject:@"application/json; charset=utf-8" forKey:@"Content-Type"];
+ [ILCannedURLProtocol setCannedHeaders: headers];
+ });
+
+ afterEach(^{
+ // We must unregister the class after each test.
+ [NSURLProtocol unregisterClass:[ILCannedURLProtocol class]];
+ });
+{% endhighlight %}
+
+**The ILTesting Delegate**
+
+ILTesting allows for delegation of client response data to a class which implements the protocol.
+
+ The protocol-delegate protocol looks like this and includes several optional methods:
+{% highlight objective-c %}
+@protocol ILCannedURLProtocolDelegate <NSObject>
+- (NSData*)responseDataForClient:(id<NSURLProtocolClient>)client
+ request:(NSURLRequest*)request;
+@optional
+- (BOOL)shouldInitWithRequest:(NSURLRequest*)request;
+- (NSURL *)redirectForClient:(id<NSURLProtocolClient>)client
+ request:(NSURLRequest *)request;
+- (NSInteger)statusCodeForClient:(id<NSURLProtocolClient>)client
+ request:(NSURLRequest*)request;
+- (NSDictionary*)headersForClient:(id<NSURLProtocolClient>)client
+ request:(NSURLRequest*)request;
+@end
+{% endhighlight %}
+
+Within the sample application, the delegate is implemented in HKZFakeWebsServer.
+
+A tip for dealing with large APIs is to have several different classes each implement CannedURLProtocol and break up response testing between various functional areas. Ex - billing, user authentication, etc.
+
+Enough stuffy code talk, let’s get going and have some fun!
+
+**Back to the DogPark**
+
+**![image][6]**
+
+So anyway, we need to test our example APIClient methods. When beginning network testing, this process has proved successful:
+
+1. Capture the desired JSON response from the API and save it within a file. (In the sample application, these are kept within the DogParkTests/JSON folder.
+
+2. Create a trigger within the ILTesting delegate to serve the response.
+
+3. Write a test which utilizes the response.
+
+Take a look at HKZFakeWebserver which implements ‘*responseDataForClient’* which is self explanitory ;) - it loads various JSON files as response data when specific URLs are requested. The request is matched on HTTP verb and path.
+
+{% highlight objective-c %}
+@implementation HKZFakeWebserver
+ // This function returns the correct JSON data, or whatever for the requested URL
+// via the ILURLProtocol
+ - (NSData *)responseDataForClient:(id<NSURLProtocolClient>)client
+ request:(NSURLRequest*)request {
+ NSData *responseData = nil;
+ // Dog profile information
+ if ([request.URL.absoluteString isEqual:@"http://dogpark.net/api/profile?id=33"] &&
+ [request.HTTPMethod isEqualToString:@"GET"]) {
+ NSBundle *bundle = [NSBundle bundleForClass:[self class]];
+ NSString *resource = [bundle pathForResource:@"profile" ofType:@"json"];
+ responseData = [[NSData alloc] initWithContentsOfFile:resource];
+ }
+ // Error handling for DogPark signup
+ else if ([request.URL.absoluteString isEqual:@"http://dogpark.net/api/new"] &&
+ [request.HTTPMethod isEqualToString:@"POST"]) {
+ // Post data, if we need it is here
+ // NSString *postString = [[NSString alloc] initWithData:[request HTTPBody]
+ encoding:NSUTF8StringEncoding];
+ NSBundle *bundle = [NSBundle bundleForClass:[self class]];
+ NSString *resource = [bundle pathForResource:@"signupError" ofType:@"json"];
+ responseData = [[NSData alloc] initWithContentsOfFile:resource];
+ }
+ return responseData;
+}
+@end
+{% endhighlight %}
+
+**Taking things further - Completing the implementation**
+
+Within the sample application, both tests presently fail. I leave the implementation of the client to the reader as an exercise in using ILTesting. The example code also serves as a reference to employ this testing method in your own project.
+
+Happy testing!
+
+__References:__
+
+1) Original idea of injecting test data via NSURLProtocol goes to Claus Broch : [www.infinite-loop.dk][8]
+
+2) Article ['Using nsurlprotocol for injecting test data'][7]
+
+ [1]: https://github.com/allending/Kiwi/wiki/Guide:-Up-and-Running-with-Kiwi "Kiwi"
+ [2]: https://github.com/AFNetworking/AFNetworking
+ [3]: https://github.com/zmcartor/DogPark-ILTesting
+ [4]: https://github.com/zmcartor/ILTesting
+ [5]: http://nshipster.com/nsurlprotocol/
+ [6]: http://media.tumblr.com/547a729f43c4bddfcc8603571dc8ecb9/tumblr_inline_mjfb450f2O1qz4rgp.jpg
+ [7]: http://www.infinite-loop.dk/blog/2011/09/using-nsurlprotocol-for-injecting-test-data/
+ [8]: http://www.infinite-loop.dk

0 comments on commit b32bfa7

Please sign in to comment.