Skip to main content

Posts

Showing posts from May, 2014

Fun with Python: raw_input()

Introduction This is the first post in the Fun with Python series. It approaches Python not with a view to learning what a variable is or what a function is but rather assumes that you have some background in these things from JavaScript, Java, C, etc. and simply want to do fun stuff with Python without trailing through all this detail all over again.
User input The aim of this post is to show how we take and use input from the user. The example is hacked together at speed with web searches and educated guesswork while keeping an eye on the documentation. It is tested in version 2.7.5 on the Mac OS X.

The following code does a few things:

creates a file that can be run from Terminal using python filename.pydemonstrates the use of commentsprompts and accepts user inputdemonstrates the creation and use of a functiontests equality in combination with a if/elif/else group of statementsconcatenates stringsshows how an input string is converted to its int valueadds two int values and conver…

The inner world of a blockquote (HTML5/EPUB3)

The IDPF Accessibility QA Checklist makes one mention of blockquotes and that is to check that:
Headings have not been used in blockquote and figure elements Elsewhere in the EPUB3 spec we don't find specific reference to <blockquote>, so we assume based on this statement,
The XHTML document type defined by this specification is based on W3C [HTML5], and inherits all definitions of semantics, structure and processing behaviors from the HTML5 specification unless otherwise specified. that we should be applying the rules of HTML5. So what are the rules of HTML5 for blockquotes? Well they differ from HTML4 for a start.
Blockquotes Where in HTML4 and EPUB2 we were required to nest <p> tags inside all <blockquote> tags, now we are free to place text directly inside the <blockquote>.

So we can do stuff like this:

<blockquote>This is a single sentence displayed as a blockquote</blockquote> Paragraph tags As before if we have paragraphs inside blockquo…

Text-level semantics: italics (i), emphasis (em), bold (b) and strong (strong) in EPUB3

Following Colleen Cunningham's tweet yesterday and the discussion that followed, I thought it worth examining the differences between the text-level semantics of italics (i), emphasis (em), bold (b) and strong (strong) in EPUB3.

Anybody implementing <em>&<i>, <strong>&<b> in EPUB3 ebooks? Might add to conversion guidelines but challenge is judgement calls. #eprdctn
— Colleen Cunningham (@BookDesignGirl) May 27, 2014
italics and em (and cite) Italics are the most common form of emphasis in books (outside of manuals and guides) and are used for a number of reasons. These are the main ones:

to identify a book title <cite> [update: thanks to @indiamos]to identify a foreign word <i>in place of quotation marks to identify a keyword <i>to identify that the word should be stressed when pronounced <em>
Next to each of the scenarios, I have placed the relevant tag that you would use. And it is logical that EPUB breaks italics into <…

#saturdaygames: Team17 on iOS special edition

1. Alien Breed If you do not feel compelled to play this from start to finish, then there must be something wrong with you. This is a golden opportunity to actually complete the game without suffering the loading time of the original. And the great door opening and closing noises are as great as they ever were. Buy it, enjoy it, finish it.
2. Superfrog It's recently been released and it's about a frog who is a superhero. I never played the original, but it's a platform game with a good level of difficulty and it's challenging and compelling enough to keep you going, but I'm not sure it's really a challenge for the Rayman Run series or another game that was set in a mystical forest, which I can't remember the name of but really liked at the time.
3. Worms, Worms 2, Worms 3, Worms Crazy Golf Choose your edition, there's enough of them. I really want to like Worms as much as Team17 do, but I'm afraid the magic wore off a good many years ago. The golf …

Running a simple Python script from inside your app (OS X/Xcode)

Step 1 The first requirement is a python script, so go ahead and create this in your favourite text editor:

#!/usr/bin/python

print "Hello World!"
The path to the python installation is important here and must be included.
Step 2 Next you need to set the permissions so that Xcode will be able to run the file at run time. We do this by opening Terminal and entering the following command:

chmod 777 hello.py
Note: Either you need to be in the directory where the file was saved to do this or you need to include the full file path where I have hello.py.
Step 3 You are now ready to drag the file into an OS X project. And once you've done this add the following code to your AppDelegate file:

- (void)runPythonScript {

NSTask *task = [[NSTask alloc] init];

        // file must be made executable using chmod 777 in Terminal
NSString *pythonFile = [[NSBundle mainBundle] pathForResource:@"hello" ofType:@"py"];
[task setLaunchPath:pythonFile];

[task setStandardInpu…

Are books data?

The arguments Some people out there will tell you that books are data and others will tell you that they simply aren't. Take for example the following three articles.
1. A Publisher’s Job Is to Provide a Good API for Books: You can start with your index (Hugh McGuire) Early last year this article by Hugh McGuire set in motion an excited discussion across the Internet about the possibility of looking at the index as an API and the book as data.   2. If Book Then . . . what now? Books face the future (Frank Rose) A couple of months later Frank Rose's article appeared, which reported on the IfBookThen conference, where the argument very much centred around books as tech, data, and opportunities to hyperlink to other places. 3. The unXMLing of digital books (Liza Daly) It seems strange that after all this excitement around the book as data, which the above two articles reflect, that we are back at calling the book a blob and being told that we shouldn't worry about structurin…

UICollectionView: A super simple example (iOS/Xcode)

In this example a UICollectionView will be created. Cells will be added using a BarButtonItem 'Add' button and they will be deleted by tapping on them.
Storyboard The first step is to create a Single View Application with the name SimpleCollectionView.

Now open the Storyboard for the iPhone or iPad (whichever one you're going to be using to test the app). Drag out a Collection View ControllerWith the new view controller selected go to the Editor menu and select Embed In -> Navigation ControllerNow drag a Bar Button Item to the top of the Collection View ControllerClick to select the Bar Button Item and in the Attributes Inspector, change the Identifier  from Custom to AddClick the cell inside the Collection ViewIn the Attributes Inspector  -> Collection Reusable View -> Identifier box type: Cell.Move the arrow that identifies the original View Controller as the initial view controller to the Navigation ControllerDelete the original View Controller that was created…

How to include C code in an Xcode project

Apple tells us that 'Objective-C is a superset of the C language', but what does this mean when it comes to including C code in Xcode projects? This post begins to explore that question.

C primitive types It is likely that you already use C primitives in your code, i.e. int, double and float, to denote number types. In which case you are already mixing C with Objective-C.
C arrays You could if you wished use int arrays and char arrays as well, for example:

int arr[] = {1,2,3,4,5};

    NSLog(@"%i",arr[3]);
Although most likely you are using NSArray and NSMutableArray. C functions To take a step further, let's grab a C function from the University of Strathclyde site and insert it into our code:

double power(double val, unsigned pow)
{   double ret_val = 1.0;
    unsigned i;

    for(i = 0; i < pow; i++)
        ret_val *= val;

    return(ret_val);
}
It's the equivalent of writing:

-(double)valueOf:(double)val toThePower:(unsigned)pow {

    double ret_val = …

NSOutlineView, NSBrowser and NSTreeController in brief (Xcode/OS X)

This is a very brief look at NSBrowser, NSOutlineView and NSTreeController providing links to information.
NSBrowser NSBrowser is used for working with data in columns, in a similar way to Finder's navigation of files and folders in column view.

Programming Topics guide

Class Reference
NSOutlineView NSOutlineView is a subclass of NSTableView. It is the approach to navigating folders and files in apps like TextWrangler, Textastic and Scrivener, where information is contained in a sidebar.

Programming Topics guide

Class Reference
NSTreeController "The NSTreeController is a bindings compatible controller that manages a tree of objects" - Apple

It can be used to navigate XML tree structures as in this example: Tree Based XML Programming Guide

See also Cocoa Bindings Programming Topics


Edit Scrivener (OS X) files on an iPad using Textilus

Textilus is a Rich Text File (RTF) editor that can link and sync with Scrivener via Dropbox.
Step 1 - Create sync folder in Scrivener (OS X)
From the top menu bar select File -> Sync -> with External Folder ...


and then choose/create a folder in Dropbox for your sync folder, and set all Format options to RTF before pressing Sync.
Step 2 - Connect Textilus You'll need to have Textilus and Dropbox installed on your iPad for this to work.

Open Textilus and tap the settings cog and choose Link With Dropbox.
Step 3 - Create a QuickLink to your folder
Create this link by tapping the Dropbox book-type icon and then navigating to your sync folder that you created in Step 1 before tapping 'QuickLink' (which is next to the Done button).
You now have another book-type icon that will take you direct to this folder.
Step 4 - Editing and syncing from Textilus 
 You can now open and edit documents.




To sync changes, tap on the sync icon in the top right corner.



Step 5 - Sync changes b…

Positioning with CGGeometry and re-orientating with autoresizingMask (iOS/Xcode)

Let's do something really simple to get to grips with positioning a view programmatically for any size screen in iOS.

Here's some code that can be placed inside the viewDidLoad of your initial view controller.
First we create the view, which is relative in size and position to the frame of the view controller's main view.
UIView *blue = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame)*0.25, CGRectGetHeight(self.view.frame)*0.25, CGRectGetWidth(self.view.frame)/2, CGRectGetHeight(self.view.frame)/2)];
Second, so that we know it's there, we add some colour. blue.backgroundColor = [UIColor blueColor];
Finally because we want the view to remain the same relative size and relative position in any orientation we throw the whole works at the autoresizingMask.
blue.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargi…

Scrivener 3.0: Wishlist

I recently purchased Scrivener (2.5) during a MacUpdate promo (still available at the time of writing). It is a really good app, and I could list all its benefits for structuring the writing of large documents, but there are some features that if added would make it not only a better tool for writing but also an app that might be extended into book production. And it is these features that I wish to focus on here.

Note: I am very new to Scrivener, so these are early observations. If you have knowledge to contradict my findings, please post in the comments. (And of course if you have your own wishes to cast out into the world, please add those to the comments too.)

Auto-update redefined styles You can create a style, or what Scrivener calls a preset format, by using the Format menu (Format->Formatting->New Preset From Selection). However, when you choose to redefine a format (Redefine Preset From Selection) it doesn't auto-update all the other instances in the way you'd …

How to fix one of the most annoying shortcuts in Microsoft Office for Mac 2011

The global shortcut key for redo across OS X is Command + shift + Z, and this is hardwired in the brains of most users. In MS Office, the shortcut key for redo is Command + Y.

In Word, Command + shift + Z does something else, something called ResetChar. I have no idea what this is but if you press Command + shift + Z by accident in Office, like I do tens of times a day then you will not afterwards be able to fix the mistake with Command + Y, so I say overwrite it for the sake of saving much annoyance.

In Excel, Command + shift + Z selects all visible cells as a default. Now that sounds useful, and less likely to interfere with redo. So this one's your call, but I'd overwrite that too.


WordSelect Tools menuChoose 'Customize Keyboard...'Select 'Edit' in the 'Categories' listSelect 'EditRedoOrRepeat' in the 'Commands' listPlace your cursor in the 'Press new keyboard shortcut'Press the Command + shift + Z keyboard combinationClick O…