Skip to main content

Tech

[EP] Migrating old data

2 min read

First things first, I want to migrate old users' data to Swift objects:

// Didn't want to use CoreData just for one object, so I was creating an array of arrays: 
// array[0] = recurring time, array[2] = name, etc. 
// Don't laugh, it was a long time ago :)
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: dat];
kConstants.allTheData = [unarchiver decodeObjectForKey: @"dic"];
[unarchiver finishDecoding];

to:

Continue reading →

Rewriting Expenses Planner

25 sec read

I started doing it at some point, but never got through with it, but with the release of Swift 2.0, there's no better chance to try all the new things and come out with a better app as well. I will be writing my journey, which won't be too long, since the app is pretty simple, but I can see quite a few hurdles ahead.

I will prefix post titles with [EP] when writing about it. Stay tuned.

Shadow system for Unity

45 sec read

Super Fast Soft Shadow system for Unity:

We're the authors of Chipmunk2D physics engine and Cocos2D-SpriteBuilder maintainers. We recently rewrote the Cocos2D renderer and added lighting effects, and now we're back to writing Unity plugins!
[...]
Shadow mask generation occurs in a single pass - it doesn't use expensive image filters or pixel shaders to soften the shadows. This means it runs great on mobile!
[...]
Physically realistic penumbra, umbra, and antumbra rendering is based on configurable light sizes. This produces accurate rendering when the light source is larger than the objects casting the shadows.

Xcode UI testing

1 min read

This is really, really awesome. Run your app and press the record button (next to the enable/disable breakpoints): as you navigate your app, code will be automatically generated. A quick test for LTHMonthYearPickerView:

let app = XCUIApplication()
let toolbar = app.toolbars
 
app.pickerWheels["2015, 46 of 91"].swipeUp()
toolbar.buttons["Done"].tap()
 
let textField = app.children(matching: .window)
	.element(boundBy: 0)
	.children(matching: .textField)
	.element(boundBy: 0)
 
XCTAssertTrue(textField.value as? String == "June / 2034")
XCTAssertFalse(textField.value as? String == "June / 2033")

The value property is, as described in the documentation:

The raw value attribute of the element. Depending on the element, the actual type can vary.

Reading time

45 sec read

I always wanted to add this to my posts, but never really got to do it. As usual, this was also easier than expected. I'm surely using some bad practices, but it got the job done.

I installed the readtime gem, and added some HTML:

<% reading_time = content.reading_time(format: :approx)
   if reading_time.to_s['seconds']
     reading_time = '1 min'
   else
     reading_time = reading_time.gsub!('minutes', 'min')
   end
-%>
<%- if (published_at = Time.at(date)) -%>
  <h4>
    <time datetime="<%= published_at.strftime('%B %e, %Y') -%>">
      <%= published_at.strftime('%b %e, %Y') -%>
    </time>
    <%= "- #{reading_time} read" -%>
  </h4>
<%- else -%>
  <h4>
    <%= "#{reading_time} read" -%>
  </h4>
<% end -%>

Broken site

45 sec read

When I wrote about improving the images, one of the code blocks was for CSS, and two were for jQuery. Since it was more or less the first time I wrote jQuery, I thought it might have extra syntax over js, so I set the block's language to jQuery.

Sadly, the pygmentation gem was returning an error of unknown value "jQuery", or something like that. Silly me for not testing locally, but it would have been much more elegant for the gem to not colorize anything in that block, instead of returning a 500 if the language passed in is invalid.

Improving the syntax coloring

1 min read

Until now I used pygments gem. I'm pretty sure it would have been just as good to keep using it, but I switched to rouge:

class HTML < Redcarpet::Render::HTML
  include Rouge::Plugins::Redcarpet
  
  def block_code(code, language)
    Rouge.highlight(code, language || 'text', 'html')
  end
end

Then I swapped my pygments.sass file to pygments.scss and filled it with the theme from http://rouge.jneen.net, since I quite like it, and that was it. I'm pretty sure I will tweak the theme in the near future, but I'm happy for now.

There's also this little helper rougify style monokai.sublime > syntax.css.