Skip to main content

Tech

Swift and enums #2

1 min read

Continuing where we left off last time, is another little trick I like to use with enums:

func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, referenceSizeForFooterInSection section: NSInteger) -> CGSize {
  if .products == Section(rawValue: section), conditionOne, !conditionTwo {
    return CGSize(width: 10, height: 20)
  }
  else if .shippingDetails == Section(rawValue: section), anotherCondition {
    return CGSize(width: 10, height: 40)
  }
 
  return .zero
}
Continue reading →

Search vulnerability

2 min read

I recently wrote that I added a visual representation for when a search is performed, by autocompleting the search field with the search query. Everything appeared to work as expected.

Some time ago I added Tinfoil Heroku addon and never saw any security problems. I even thought I will never see one. But I started seeing a couple about Cross-Site Scripting in HTML tag. I went to their dashboard, clicked on reproduce the attack, it took me to my website, with a search performed, the search query was autocompleted, as expected, but a tag was also injected in the search field:

Continue reading →

iOS good practices

25 sec read

This is a really nice resource, I'd suggest on at least reading it, if not bookmarking. Even seasoned developers will find useful stuff inside, but if you are a junior, or have one in your team, it's definitely a must-read.

It goes hand-in-hand with this awesome resource list.

Swift and enums #1

2 min read

This will only work for enums that are Ints, start from 0, and increment by 1 - for example tableView / collectionView sections, but I think it's a nice little trick that I always use:

private enum Section: Int {
  case products
  case shippingDetails
  case paymentDetails
  case totalValue
  case numberOfSections
}

Now you can do the following:

Continue reading →

SASS' Mixins

1 min read

I recently saw a nice example of Mixins for SASS. So I went ahead and created a few, since I really dig them:

@mixin responsive_width($width) {
  @media screen and (max-width: $width) { @content; }
}
 
@include responsive_width(475px) {
  // Custom styles for width <= 475px
}
 
@mixin light_bottom_border($size) {
  border-bottom: $size solid $light_gray;
}
 
blockquote {
  @include light_bottom_border(5px);
  @include light_top_border(5px);
}
 
article {
  @include light_bottom_border(1px);
}

I also unified most of the website's colors with variables like $link_color, $gray_color and $text_color. Maybe one day I will try to unify the paddings and margins as well.

This was fun, and surprisingly satisfying.

Improving the search

1 min read

I wanted a visual representation and helper for the user when a search is performed on the site. So I thought about autocompleting the searched term in the search field. At first I tried with jQuery:

var query = decodeURIComponent(location.search)
  .split("=")[1]
  .replace(/[\+]/g, " ");
$('input.search').val(query);
$('input.banner-search').val(query);

But this had a small delay and the slight inconvenience of having to replace + with a space, and to decode the URL. So I ended up with some really simple ruby, inside layout.erb:

<% query_params = request.params['query'] %>
<input type="text" [...] value='<%= query_params %>'/>

Fastlane and Alfred

2 min read

One more thing that helps me with the Fastlane flow is an Alfred workflow to run the lanes. It was really easy to create, and here's how: open Alfred, go to Workflows, press +, Templates, Essentials and choose the Keyword to Terminal Command. Give it a name, a description, and a keyword (without a parameter), then paste the following in the script field:

cd ~/path/to/project && fastlane release_minor && exit

This will open the Terminal, cd to that path, run the fastlane command, then close the respective window.

Continue reading →

TextFields with inputView

1 min read

Let's say we have a textField with an UIPickerView as its inputView.

The first problem is that we want the textField to not be editable, because we populate it with the value picked from the picker. This is the simple part:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  return emailTextField == textField
}

The second problem is that the textField is still tappable, it still gets focus and the caret is still visible.

Continue reading →