Hey! People of the internet. I'm writing a couple if interesting posts about Android and coding in general. 

Gonna try to post at least once a week with interesting ideas about programming and the sorts.  And hopefully do some social sharing and some SEO to get more momentum.

So, watch this space! 

Posted
Authorpablisco

One of the first things we learn when checking a variable is within a given range is that we can't use this form: 0 < n < 100. Mainly due to the order of operands. Since (0 < n) computes into a boolean value which incidentally (at least in Java) cannot be compared with an integer. Although, if you are using C it would compile since it treats booleans as 0 or 1. However, the second part of the test would make the whole expresion true all the time.

The way we tend to write this in code is with something in the line of this: (n > 0 && n < 100)  which makes sense but we can do better. I think this notation is clearer:

(0 < n && n < 100) 

Although, hardly diverging from the former, here is easier to recognize the content of the test by leaving the subject in the middle. It's a closer resemblance with it's mathematical analogous.

In scala we can do more magic like this: 

class IntChecker(n: Long) {
def within(range: Range): Boolean = range contains n
}
implicit def int2Checker(value: Int) : IntChecker = return new IntChecker(value)
n within (1 until 100)

Scala casts our integer value into IntChecker when it realizes that we are calling the method within.

Or you can directly use this:

 (1 until 100) contains n 

It is possible to do a more natural expression with scala but I will cover that on part 2.

 

Posted
Authorpablisco
CategoriesCode

I'm writing this post just to check the capabilities of squarespace for code insertion. For future reference and personal test.

It works pretty much as expected. I only had to edit some of the css to format the ist code a bit nicely using this:

.line-numbers, .line-pre, .source-code {
font-size: small !important;
tab-size: 2;
}

And this last inset is done natively. They only support formatting for css, html, javascript and markdown. 

new PromptDialogBuilder(this)
.setPositiveButton(R.string.offer_signup) // sets the positive (ok) button text
.setPromptListener(new PromptListener.Impl() {
@Override
public void onEmailProvided(String email) {
// do whatever with the email
}
}) //
// This one now returns the AlertDialog.Builder
// and now we handle it as a normal Builder
.setTitle(R.string.offer_signing)
.setMessage(R.string.offer_need_email) //
.show();
The JS formatting works ok with Java. Will have to test other languages

Here is the Gist I tested:

Posted
Authorpablisco

This is my first post with squarespace. Let see how this platform behaves. So far it has a very straight forward and simple design and UX. Need to play around with the advanced settings. It would be nice if it had a reseller feature to create websites for third parties.

Bicho approves this post and sat on it.

Bicho approves this post and sat on it.

Posted
Authorpablisco