Skip to main content

Posts

Showing posts from 2018

Adventures in PayPal: Three Essential Links for PHP Integration

REST API integration of PayPal using PHP is the main page that you'll need to bookmark. It links to some very distinct and largely unconnected pages that are each very important for understanding the use of the API. This unconnectedness means that you follow one link and then it is difficult to find your way back to the other equally important pages, which are linked not through hyperlinks but through each being necessary to understanding the whole. Once you have downloaded the latest release of the SDK  and followed the starting instructions with Making your First API Call  using the Wiki Page for the PayPal PHP SDK there are three equally important pages: PHP Source Docs  - lists all the classes and their methods PHP Sample Code  - infuriating for the difficulty it presents in copy and paste, but nonetheless essential PayPal API Reference  - this is a language agnostic resource and explains the composition of the calls and the JSON, outlining what is required and what is

Swift: Why try? isn't good enough for JSON

I find myself writing code like this when handling JSON using Codable, because of the instances where the value of the same key might be of variable types: init(from decoder: Decoder) throws { do { let anim = try AppearAnimation(from: decoder) self = ComponentAnimation.appear(anim) } catch DecodingError.typeMismatch(_, _) { } catch { throw error } do { let anim = try FadeAnimation(from: decoder) self = ComponentAnimation.fade_in(anim) } catch DecodingError.typeMismatch(_, _) { } catch { throw error } do { let anim = try MoveAnimation(from: decoder) self = ComponentAnimation.move_in(anim) } catch DecodingError.typeMismatch(_, _) { } catch { throw error } do { let anim = try ScaleFadeAnimation(from: decoder) self = ComponentAnimation.scale_fade(anim) } catch {

Swift: Codable Encounters of the Enum Kind

In my everyday life I am a publisher working with tools like InDesign but also performing web development and in part experimenting and developing on iOS and Android. Working with JSON is a passion of mine, but it's not one that I get to indulge full time. So I spend long periods of time away from Xcode and Swift during which I easily forget all the stuff I learnt about Codable aside from the basics. But recently I returned to my JSON work that I started before the Codable protocol was added to Swift and started stripping out my own bespoke JSON approach and replacing it with Codable elements. One question I had was regarding the behaviour in the situation where you have a codable enum with a raw type of String. What would happen if that enum was inserted as the type of a property where a string would be present in the JSON. My hope was that if the string received matched the raw type of one of the enums then all would work well. Otherwise there would be more complicated w

Local Storage: How to debug it and why Safari throws errors

If you are testing localStorage with files on your machine, you will find that Chrome and Firefox have no problem with this and work normally but Safari refuses to store any key/value pairs when the page is not delivered via a server. Safari throws the error "SecurityError: The operation is insecure." inside the Debugger (Develop > Show Web Inspector > Debugger) and the Local Storage remains empty (Develop > Show Web Inspector > Storage > Local Storage). The solution is to either serve remotely or to use MAMP , for example, rather than attempting to load the html directly from your machine. Alternatively, use Chrome and Firefox to test locally. You can also Disable Local File Restrictions in the Safari Develop menu as a solution. Did they remove the "disable local restrictions" or something like this in the dev menu? — Jiminy Panoz (@JiminyPan) August 11, 2018 Thanks to Jiminy Panoz for the reminder on this last point and his recommend

InDesign: Seven ways in which indexing could be improved

Enable character formatting of entries Enable selection of multiple entries for deletion Make the existing entries searchable in the dialog box for creating a new entry (add find field) Make the new entry dialog box expandable so more of the existing entries can be viewed at once (rather than scrolled) Add option to expand all references/topics Fix shortcut bug Develop innovative ways to automate indexing (e.g. add entries by bulk searching) Follow @sketchytech

InDesign: Workarounds for Indexing Bug (macOS)

Bug If you regularly use InDesign for indexing you might be aware of a long-standing bug whereby having used the entry type "For Next No. of Pages" entries made afterwards using the shortcut of dragging out a topic to the new entry icon at the bottom of the Indexing window, or created using an alt-click of the new entry icon repeats the same page range no matter how many times you open and reset to "Current Page" and then keeps repeating this behaviour. Workaround To reset the Indexing shortcuts and make them forget the page range do the following: Use shortcut in usual way. When extended page range appears open the entry, select "Current Page" and press OK. You'll notice that the page range doesn't immediately update and remains as a range. Do not press the sync button, instead re-open the entry and press OK again. You should now be able to use the indexing shortcuts as normal (until the next entry of a page range, after which you

Android: Toolbar, Action Bar and Menu Items (including Spinner)

It's very easy to drag out a Toolbar when designing your interface but you can't just drop buttons into it. There is a more mystical way of construction to enter into. Toolbars hold a menu. The main toolbar that you see when you create an empty app is assigned Action Bar status in the onCreate method. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); You will also notice its menu being "inflated" later in the onCreateMenuOptionsMenu method. getMenuInflater().inflate(R.menu.menu_main, menu); The setting of the Toolbar as an Action Bar enables the following: Once you set the toolbar as an activity's app bar, you have access to the various utility methods provided by the v7 appcompat support library's ActionBar class. This approach lets you do a number of useful things, like hide and show the app bar. To use the ActionBar utility methods, call the activity's getSupportActionBar() method. This method returns a re

Android: Adding and referencing an XML resource

Adding an XML resource Inside your res folder is a values  folder you can right-click on this and create a New > Values resource file . Inside this, for the purpose of creating a simple list of strings, we can simply place  tags and strings in an identical way to that in which we find in the strings.xml file: <resources><string name="app_name">DraggingView</string></resources> If we want to create an array however, whether that be an integer or string array we must first identify the array as such by additional level of nesting: <resources> <string-array name="font_sizes"> <item value="10">"10"</item> <item value="15">"15"</item> <item value="20">"20"</item> </string-array> </resources> Referencing the XML resource To then reference that resource within your java code, we can wri

Android: Popup menu

This example uses a Basic Activity type app with a round button (FloatingActionButton) that hovers over the bottom right of the interface. Creating the popup menu To create the popup menu it is necessary to first instantiate and then add items before adding a listener ( OnMenuItemClickListener ) to identify the item clicked. It is also necessary to know the view from which the menu will originate. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); final PopupMenu menu = new PopupMenu(this, fab); menu.getMenu().add("Add Image"); menu.getMenu().add("Add Text"); menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // insert your code here Log.d("menu title: ", item.getTitle().toString());

Android: Drag and drop a view onto another view

Understanding the Drag and the Drop In enabling a user to perform a drop and drag action you have a view that is being dragged and a view that is being dragged to . The listener that will activate the drag, e.g. a long press, is attached to the view that will be dragged . While the view that is being dragged to has the drag listener attached to it. A single view can be dragged onto many different views if those views each have drag listeners set and ready to respond positively. Likewise multiple views can be dragged onto the same view that is being dragged to . View Being Dragged To Starting with the view being dragged to, which is an essential if you are going to be able to drop your draggable view anywhere, we have the following code. (See below for further explanation.) // A view is identified from the layout file within which other views can be dragged (mainView) RelativeLayout mainView = findViewById(R.id.mainView); mainView.setOnDragListener(new View.OnDragListener() {

Life in the Real World: PDF to EPUB Conversion Using Google Docs

Did you know that you can convert a PDF into a range of formats simply by uploading to Google Docs? These currently include Word (.docx), Open Document Format (.odt), Rich Text Format (.rtf), Plain Text (.txt), Web Page (.html, zipped), and yes EPUB (.epub). With your mind suitably blown, let's get down to the practicalities. The first of which is that when you upload a PDF to Google Docs it is going to need a bit of cleanup. How much cleanup depends on the complexity of the document but a basic PDF with headings, word breaks, running heads,  footnotes and blockquotes you'll find needs the running heads removed, the spaces between pages deleted, the word break hyphens removed, blockquotes re-indented, some merged lines separated, footnotes re-activated, etc. But at least italics will be retained. A licence to print money Once you've done the clean up, then you can download the file as an EPUB by simply selecting File > Download As > EPUB Publication. And there i

UIButton at your Convenience

UIButton is one of those classes where you have to take quite a few steps to set up an instance if you require anything beyond the default. For example, I would like to create a round button with a title, border, background colour, etc. extension UIButton { convenience init(withRadius radius:CGFloat, title:String, titleColor:UIColor, target:UIViewController, selector:Selector, backgroundColor:UIColor, borderColor:UIColor, borderWidth:CGFloat, position:CGPoint) { self.init() self.setTitle(title, for: .normal) self.setTitleColor(titleColor, for: .normal) self.addTarget(target, action: selector, for: .touchDown) self.backgroundColor = backgroundColor let diameter = 2 * radius self.frame = CGRect(x: position.x, y: position.y, width: diameter, height: diameter) self.layer.cornerRadius = radius self.layer.masksToBounds = false self.layer.borderWidth = borderWidth self.layer.borderColor = borderColor

It's time to stop unzipping your EPUBs and start using zip properly on macOS

I'm no zip guru and trust me, if I can use a GUI I will but I've come to realise that I'm wasting a lot of time zipping and unzipping, and while BBEdit does a good job of allowing us to browse EPUBs and edit EPUBs, it has its limitations. Zipping an EPUB There are a variety of ways you might arrive at an EPUB: for example, outputting from an app like InDesign, or Pages, etc., or creating using the save option in epubcheck's expanded validation process  (thanks to bowerbird for  drawing my attention to this ; see also  Jorge's comment on this post ), or manually zipping. My way I usually output from InDesign and then unzip to make fixes and changes. Currently when I need to re-zip, this is the code I use: zip -Xr9D ../book.epub mimetype META-INF OEBPS -x *.DS_Store Note: it is important that prior to running this code you change the current directory you are in, so that you are inside the main folder of the EPUB you wish to zip. The code will then create th

Swift and XML Episode 1: Defining XML using Swift

XML is a very simple language at heart. It contains elements , i.e. those types that are primary to a tag, e.g. <paragraph> or <p>, and which are also used to close tags, e.g. </paragraph> or </p>, it then has attributes , which are secondary but which are also contained within the boundaries of the the tag, e.g. class="regular", which is contained like so <p class="regular">. Finally we have the content , which can be one of two things: text or another element nested within the first. Since everything begins in XML with the top-level element, that's what will start with too: struct Element { let name:String let attributes:[Atrribute] let content:[Content] var self_closing:Bool { return content.isEmpty } } We have now the most important thing, our ability to create instances of an Element, we also have the ability to be aware if the element we are dealing with has no content and will hence need self-

Useful links for the future of EPUB: Specifications, repositories and drafts for 3.0.1 to 3.2

Twitter In Feb. 2017, the merger of the  IDPF with the W3C was announced , at which point the  EPUBZone  twitter feed, run by the  IDPF , went quiet along with the  associated website  for the twitter feed. Outside of the main  W3C one , there doesn't appear to be a replacement for this feed. EPUB 3 Community Group @ W3C On 6 Feb. 2017, the EPUB 3 Community Group was made public and from here we find a link to the EPUB 3 Community Group Work Repository on GitHub. The Community Group page also has an archive of mail that has been exchanged and an RSS Feed. Further, you can view all participants  and join the group yourself, or simply make contact. EPUB 3 Community Group General Repository Contained on the GitHub repository of the Community Group you can find a handy page of links to all docs from EPUB 3.1 backwards . The EPUB 3.1 links take you to W3C pages, while the links to earlier spec, i.e. for EPUB 3.0.1 backwards, take you to the IDPF site. EPUB 3.2 Reposito

EPUB Quick Fixes: Cover image not displaying in Finder or eReader Libraries

If you notice that some of your EPUB files, instead of displaying their cover within macOS Finder, or on an eReader, display this: Or some other generic placeholder identifying the default app in which the file will open, you haven't identified the cover correctly inside your content.opf file. There are two steps to fix this: Within the <manifest> tags of your package (within the opf file), and separate to a declaration of the xhtml of the coverpage you need to identify the image itself that you are using for the cover, e.g.  <item id="CoverImage" href="images/cover_image.jpg" media-type="image/jpeg" properties="cover-image" /> , making sure to include the attribute properties with a value of "cover-image", as shown, along with all the other attributes (of course pointing to your actual image). The first step has fulfilled the require of the EPUB 3 standard but now you also need a line in your <metadat

Digging the Meta in EPUB 3: Using the meta element to extend metadata in EPUB 3, 3.0.1, (not 3.1) and 3.2

One of the main areas addressed in recent changes to the EPUB spec is metadata, which is undeniably an important area. So I'm taking an opportunity here to look briefly but closely at the opportunities we are afforded within the content.opf file for enhancing the depth of our metadata. We can see from the EPUB documentation that the opportunity exists to use ONIX  to denote perhaps the use of a DOI through the meta/refines/property trio (which sometimes becomes a four-piece through the identifying of a scheme, as it does here): <metadata xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier id="pub-id">urn:doi:10.1016/j.iheduc.2008.03.001</dc:identifier> <meta refines="#pub-id" property="identifier-type" scheme="onix:codelist5">06</meta> … </metadata> Or to inform the use of an ISBN: <metadata xmlns:dc="http://purl.org/dc/elements/1.1/"> … <dc:ide

Apple News Format API in Swift: GET Channel, Section and Article Data (Swift 4)

You can use the online tool to create your own Apple News posts through iCloud.com, no problem. You can also look to  Apple's python scripts as a way to upload, download and delete articles. If it's a Swift equivalent you want, then you'll need to roll your own. And that's what I start to do here having covered a couple of side notes first. Side notes about Python To use the Python scripts I needed to use easy_install to install requests on macOS. Side notes on News Preview To use the News Preview app , and start exploring the Apple News Format, you need to have Java 8 installed, Xcode and Xcode command line tools, and a channel id (although Apple does provide a preview channel id in the readme file if you're not yet signed up to Apple News as a content provider). Once you have everything installed grab the example articles  and start learning. Python: GET Channel Data This is the Python code that Apple provides in its documentation for returning channe

Scrivener 3: Getting Started on a Novel in 10 Questions

The first thing you'll need to do is to select File > New Project... from the menubar, followed by Fiction > Novel in the dialog box that opens. Now we can start asking questions. Question 1: How do I give my book a title? Slow down, you might want to start with a title but Scrivener views this as something likely to be in flux until the end, so the developer expects you to set this at compile/export time rather than at the beginning of writing. To see where you'll set things like your book title, author, etc. go to File > Compile or Option + Cmd + E . Now on the righthand side click on the luggage tag icon (for metadata) and you'll have a series of boxes for setting the title and name. Question 2: What about the rest of the front matter? In the Binder (i.e. the panel on the left of the main window) you will see the Front Matter icon with an arrow next to it for expanding and collapsing. Inspecting the contents of this you will see, for example