Burak Dede's Blog

Ghostery + Ublock Origin Extension Problem

April 21, 2017

I am a regular Chrome user and since I switched from AdblockPlus to Ublock Origin, one of favorite extension Ghostery is not playing along with Ublock Origin. I am constantly getting an error related to request being redirected to different locations.

ghostery ublock origin error

I dug a little and found out that it is because of the following reasons

  • I have strict rules to block all advertising and trackers in Ghostery
  • Google analytics is allowed on UBlock Origin
  • Since UBlock allowing while Ghostery is blocking there is the confusion

To solve it just allow Google Analytics request on Ghostery. That is it, no more extension error!

For those who think Ublock and Ghostery does the same job, it is not.

Android Support Library Confusion

March 28, 2017

Lets start with offical definition of the support library

When developing apps that support multiple API versions, you may want a standard way to provide newer features on earlier versions of Android or gracefully fall back to equivalent functionality. Rather than building code to handle earlier versions of the platform, you can leverage these libraries to provide that compatibility layer. In addition, the Support Libraries provide additional convenience classes and features not available in the standard Framework API for easier development and support across more devices.

What are the main benefits of using support libraries?

  • Backward Compatibility for newer API
  • Convenience Helper Classes
  • Debugging, Testing, and Utilities

Support library topic may be one of the most confusing parts of the Android development and whole SDK. I remember after Fragments introduced with API Level 11 (which if I remember correctly Honeycomb) they introduced a `support library to provide backward functionality for platforms earlier than Honeycomb. It was just a single library and you add your dependency to get Fragments functionality. As new versions launched this support library than grew into a massive library of code.

When feature does not exist on older version you have couple of options

  • Write your own support, really?
  • Runtime build check & prevention (that is just sweeping under carpet)
  • Offical support library

Offical support library is the safest option of all. The advantages would be there are people working on this full time so future updates, thoroughly tested so less buggy than your custom support library and come with helper classes as an extra.

Yes, support library thing seems confusing because it really is…

After support library got really big they divide it into a couple of versioned libraries.

  • support-v4
  • appcompat-v7
  • recyclerview-v7…..

v# scheme means that it will support all the way back to 4 or 7 API Level. But that would not be the case for all functionality. Offical doc

These are the most known ones but there are more. Check revision page for a list of changes and other ones.

When people say support library they are meaning support-v4 as the support library.

dependency support library

This is getting confusing especially using Fragments inside application. Normally you extend your activity from Activity class, if you support Fragments you would use FragmentActivity (this is not necessary if you are using native fragments instead of support one). This is all great, support-v4 library already have android.support.v4.app.Fragment and android.support.v4.app.FragmentActivity classes but the latest version of the Android Studio include appcompat-v7 as support library instead of support-v4 and most of the activity classes extend from AppCompatAcitivty.

support diagram

Some support libraries also include classes from other support libraries or directly depend on them. AppCompatAcitivity which comes with appcompat-v7 and extend from FragmentActivity from support-v4 so you get both of them if you just use AppCompatActivity. Above image explains it all better.

If you are going to support Fragments without AppCompat library you would need extra support-v4 library but if not appcompat-v7 already had it.

Android Debugging - Java Exception Breakpoints

March 27, 2017

Lets face it debugging is part of the process while developing mobile applications whether it is an Android app or not. It is really frustrating chasing for hours to find simple increment bug or non-called function after your application reach to this will become more frequent.

I will share you a feature that I have been using for a while which makes change-debug-test part much more effective in my opinion. Here is the usual flow

  • Add new feature
  • Build and sign app to test on device
  • App blows up and now look at what exception or error is
  • Nothing comes out, let’s attach debugger to see what’s going on
  • Wait until to come to that screen or feature

This is the general flow when you face with runtime exception they will be mostly NullPointerException but sometimes those are little trickier. Android Studio have a feature that allows you to add new generic breakpoint to catch Exception based on the filter.

Run -> View Breakpoints -> Add(+) -> Java Exception Breakpoint -> RuntimeException

android debugging exceptions

By doing above steps you are basically saying that hey create new breakpoint as soon as you catch any RuntimeException. After applying that next time your app throw RuntimeException it will be directly created breakpoint and go to that line with a debugger attached and you can inspect all the variables on that spot.

This is, of course, tricky because it will also catch/stop any exception thrown by runtime/framework libraries included but not directly related your code. Beware of that.

Book - The Power of Habit - Notes

March 23, 2017

The Power of Habit is the new book I am currently reading and for first few chapters it better than I expected. I value books based on how fast I can apply the knowledge to my life. Since this book is about daily habits, how the brain works and how we form new habits it is applicability is higher than other books.

My GoodReads Account if you wanted to follow what other books I am reading.

habit loop

Chapter 1 - The Habit Loop

  • Old habits die hard and literally they never die.
  • Old habits stay where they are inside the brain.
  • New habits form new patterns but old habits still ready to be activated.
  • When you have a habit of eating fast food at night you can change this habit with the new one but habit loop still triggers old habit inside the brain even though you stop eating fast food and replaced it drinking water instead.
  • Habits have cycle cue - routine - reward.
  • Most of our bad habits can work like domino if you can find the keystone habit and change it other will follow. The book includes a case of a woman which changes life somehow by changing keystone habit.
  • Your brain does not like your mundane daily life so it delegates or converts most of the tasks to habits and stay low profile.

brain activity

  • Delegation is not applicable when you are learning or doing something the first time.
  • Even though brain stop learning new things it can still form new habits.
  • Brain delegates its task to habit when habit started and take control back when habit end with the reward.
  • We can focus on other things while we are in habit cycle because the brain is not actively working in the period. eg. Driving the car while you remember that you forgot something
  • Habit loops are fragile especially cue part. When the brain senses a little change habit loop breaks.
  • When scientists changed reward place rats had a hard time figuring out what to do. When they use cat sound instead of a click sound on cue phase could not figure out what to do.

Chapter 2 - The Craving Brain

craving habit loop

  • Pepsodent toothpaste become so popular that it changed daily toothbrushing habits of Americans.
  • Hopkins (founder of the Pepsodent campaign) created simple cue-reward from daily life and turn it into habit
  • The real science behind the toothbrushing habit was habit created craving.
  • Hopkins rules become defacto standard on marketing (even though most of them already tried before Hopkins)
  • Febreze case is wildly interesting. It is hard to find the right cue-reward mechanism.
  • Febreze first positioned itself as a product to get rid of the bad smell (literally removing it). This is failed at first
  • Febreze repositioned itself as an after cleaning product which created another cue-reward with craving good smell after cleaning session.
  • Craving phase happen after you got the reward and sometimes it is so compelling that it emerges on cue phase too (experiment on monkeys with grape juice shows that monkeys create spikes in brain activity even on the cue phase after multiple tries).
  • Some products have pseudo ingredients inside them to trigger craving and habit loop. Toothpaste contain sulfate even though it doesn’t have to. It creates foam effect which people think that it works when foam appears along with herbal sense.
  • To learn new habits spark craving sense. If you want to run or exercise put your jogging shoes somewhere visible to remind that.

Chapter 3 - The Golden Rule of Habit Change

This chapter seems boring comparing to other chapters.

  • Habits seems easy to replace but it not easy in practice.
  • Belief is biggest factor when you wanted to change something.
  • Replacing habit with group of people helps AA meetings etc.
  • Old habits re-emerges in high stress situations but it is managable with purpose.

Chapter 4 - Keystone Habits

  • This chapter is more connected than previous one moving mainly around Alcoa case
  • Finding keystone habit is an important routine for bigger organizational changes.
  • Alcoa did that by putting safety in the first priority.
  • Changing safety habit also created a tight network of communication loop because everyone in the chain must report accidents immediately.
  • This network of communication soon turn into the first version of corporate mailing.
  • Corporate mailing and free communication lead to ideas from all sort of employees which company struggling to find a solution.
  • Phelps (swimmer) case is also covered which have a routine created by his first trainer.
  • Phelps applied his routine rigidly before each competition and prepare himself for unexpected situations (goggle case.)
  • Researchers found out that keeping a daily log of what you are eating can help people change their daily eating habits.
  • When they see so much junk food they choose to go with health choices or they can see their eating patterns on time basis.

Chapter 5 - Starbucks & The Habbit Of Success

  • This chapter revolve around the organizational approach by Starbucks to train their employees with habit loop
  • Every new employee joined Starbucks will take series of training for situations that both lead to personal and organizational success.
  • Book talk about the case of drug addict parents son Travis and how turned his life around after joining Starbucks.
  • Willpower also have a big role for habit development.
  • Willpower works like a muscle and have a finite ability. So people need to keep their willpower sharp and ready.
  • If you spent your willpower for routine daily activities you will not have enough to do what you wanted to do.
  • Books talks about series of experiments to test willpower such as cookie experiment. When part of a group given cookie and told not to eat ramen while other group told the opposite. Cookie eaters did not have a hard time resisting ramen while eating the cookie but other group had a hard time dealing with the situation.
  • Both groups were given hard to solve problem after resisting their urges but the Ramen eating group have a hard time focusing and solving problems while cookie eating group tried to solve the problem longer.
  • Starbucks took a step further and gives employees perks like free gym membership etc. but employees had a hard time finding willpower to use them
  • Employees daily routine is exhausting enough that after work it is hard to follow the routine.
  • Starbucks developed system called LATTE which employees can take action for already practiced situation like dealing with angry customer, wrong order
  • Every new employee given booklet to write those situations down and define what they will do when they face the situation again.
  • LATTE means Listen, Acknowledge, Take Action, Thank Them, Explain Situation

powered by TinyLetter