Useful bash commands

This article is a living document and I’ll update it with new commands and change and fix any of the existing ones as needed.

Start CouchDB in a Docker container

Start CouchDB version 2.3.1 in a Docker container with port 5984 open so it’s available on the host on the same port.

sudo docker run -p 5984:5984 -d couchdb:2.3.1

Start CouchDB version 2.3.1 in a Docker container with all relevant ports open, a node name couchdb-0-project with a volume named volume-0-couchdb mounted to /opt/couchdb/data so CouchDB can use it for permanent storage.

sudo docker run -itd -p 5984:5984 -p 5986:5986 --name=couchdb0 -e NODENAME='couchdb-0-project' --mount 'source=volume-0-couchdb-project,target=/opt/couchdb/data' couchdb:2.3.1

Restart the container based on --name=couchdb0 on subsequent runs with

sudo docker restart couchdb0

Connect to a remote CouchDB that’s only listening on localhost

If your server is, your username on that server is username, your ssh daemon is listening on a non-standard port 1000 (standard is 22), running this command will log you into that ssh server and create a tunnel from the server’s port 5984, where CouchDB normally listens, and your local port 22222.

This allows you to open http://localhost:22222 to reach your server’s CouchDB through the tunnel, with Fauxton available at http://localhost:22222/_utils.

ssh -p 1000 -L 22222:

In case your ssh server doesn’t use a non-standard port, and only uses port 22, the command becomes even simpler.

ssh -L 22222:

Any other useful command that you think should make this list?

This article is a living document and I’ll update it with new commands and change and fix any of the existing ones as needed.

What happens when there are no more plants?


If you stop and think about what happens when all the plants are gone, it can become obvious. If it’s not, maybe the results of the simulation can shine some light.

With energy source running out, beings closer to the top of the food chain can still survive and make progress for a while, by feeding on those lower in the food chain. Oblivious to their upcoming destiny, however, sooner or later they go extinct too.

Z. Fras, “Artificial life simulation,” M. S. thesis, University of Zagreb,
Zagreb, Croatia, 2014.

Is it weird to quote your own thesis? I don’t know, is it? Perhaps.

Let’s pretend that’s fine for a bit, because the data is real, the simulation is real, the title is obvious and the world is, not just metaphorically, on fire, so you’re not here for the answer to the question, you’re here to go deeper. You’re here because you hope there’s more. You’re still reading because you hope we can do something about it and you want to know what your part is. Or that’s my mental image of the kind of person you are.

If it was all black and white, we would end here. Quite literally. We’re killing our forests, our plants are dying, simulations are predicting our demise. We ought to write our eulogies as we look at the smoke raising on the horizon as the setting sun paints beautiful, bloody, hues. Our only hope for life would be the Phoenix of the next civilization raising from these ashes, thinking to themselves “What the heck happened to these guys, they had such advanced technology…”. Because life finds a way, and if it was a movie, it leaves room for a sequel.

Luckily, world has shades of gray, and like the bloody sunset, it has color, visible and invisible spectrum. Simulations are not copies of the real world, and this is our first movie, not the sequel.

Let’s dive in

This is not the only outcome observed in the simulation. Two other, at the first glance, equally gloomy outcomes, appeared frequently.

  1. Beings on top of the food chain exhausted their life sustaining resources, and essentially eradicated the world until there was nothing left but plants. This outcome is not that interesting to us humans. The solution sounds simple, we all just (if by lack of choice) go vegan. Until this scenario turns into the one this article is about. So, in your mind, just prepare to go vegan and bundle them together.
  2. Due to sheer luck of the draw and fortunate initial placements, life arranged itself in favorable position of energy flow that led to overpopulation. So overpopulation is fortunate? Compared to extinction, certainly. Our universe is huge, there is still plenty of space to populate. Beings in the simulation bent the rules of the physics engine in rare fluke cases and escaped the confines of their safe little bubble. Just like them, humanity too is exploring the vicinity of our little bubble. Outside of it, our universe is a very hostile place.

If we bundle the first alternate outcome (or convince ourselves it’s fine to ignore it), we notice how obvious the second one is. We’re making accelerated progress with SpaceX, Blue Origin, NASA’s latest plans, and plenty of other, lesser known companies. The only thing left is to address the main one.

The main topic of this article, what happens when all plants die, is also obvious. Yet, while obvious, it carries inherent dangers.

Have you ever thought about what would happen if there were no more plants? A chain reaction!

Tweet this

Inherent dangers

While the answer to the question “What follows the extinction of plant life?” is obvious and the dangers seem obvious too, what’s not obvious is that it’s a chain. A food chain.

And change in chains travels as a wave. Those who spend time with me on a daily basis (hello teammates) now smiled a bit, sensing a physics lesson coming up. I’ll keep it light, promise. When something happens on one end of the chain, the effects influence their neighboring link, which influences their neighboring link, which influences their neighboring link… Effects are slowly making their way throughout the whole chain and finally reach the other end of the chain. The longer the chain, the longer it takes for changes to propagate.

But Zvonimir, that’s obvious, everybody can see it coming!

Yes, it’s easy when you’re looking from the side. It’s a lot harder when you’re one of the links in that chain. What makes it even harder is visible in those graphs at the beginning. The chain effect allows those removed from the source of disturbance to continue unaffected and even prosper, oblivious that the ground is disappearing under their feet until the change is there and takes them with it. That’s what happened to the beings on the top of the food chain in the simulation. And it might be already happening to us. All the deforestation and fires certainly suggest so. And we wouldn’t feel the effects right away either.

Diving deeper

If we take a look at the number of species extinctions and human population growth correlation, we can pretend that correlation implies causation and that because other species go extinct we can prosper.

Let’s laugh a little and move on from that idea because correlation doesn’t imply causation. Instead, have a look at the graphs from the beginning again. Notice how plant life numbers (green graph) start to drop while second tier life (blue graph) and top tier life (red graph) prosper. It takes plants going bellow a certain threshold for the second tier life to start feeling the effects. It’s the point of no return for these simulated populations. Top tier life continues to prosper for awhile until a lower tier hits a similar threshold. This cascade continues as the effects spread through the chain. The longer the chain, the longer it takes for the top tier to become affected by them.

We know these are not faux correlations implying causation because simulated beings are coded to be dependent on the lower tier beings for food.

If you were to create a graph showing extinctions count and top tier population growth from the results of the simulation, it would exhibit the same pattern we see happening in the world around us.

Let that linger for a few seconds.

Now what?

The silver lining is the color we’re surrounded with. We poses far greater intelligence and agency than the simulated beings. With that, and with our view from the top, comes great responsibility.

Bringing awareness is great, yet there’s no amount of awareness and activism that would make it possible for you to buy an electric car when you became aware of the negative effects of fossil fuels, if there wasn’t for Elon Musk led revolution in electric vehicles.

I’m very passionate about this and I’m doing something about it. Send me a message or post a comment if you’d like to do something about it too, even if you don’t know what you could do. Or tell me in a comment or a message what you’re doing and I’ll see if I can help!

Now that you’re aware, what are you going to do about it?

ng-conf 2019 takeaways

Salt Lake City is beautiful, mountains are lovely, everything is soooo clean

Being in Salt Lake City for a few days, it would be a shame not to explore the city a bit, especially with the weather servings us so nicely.

Whoever maintains the city deserves a medal. Everything was so clean that you can almost eat from the floor if you could find any food on the floor. Which you couldn’t.

If we were in the tulip bubble right now, Salt Lake City would be the richest city in the world with tulips, like good plated art pieces, all over the place, creating fairytale-looking scenes like this.

Angular team is committed

Being just stable is not good enough. The world is changing, the user expectations are changing, the developer experiences are also changing, we need to keep up. We need to make sure that Angular doesn’t stay behind and becomes stagnant.

Winter Ivy is coming

It’s not here yet, but when it comes it’s gonna be awesome. Maybe. Probably. It’s not going to fix everything, but it might. It’s gonna be awesome fo’ sho’. Maybe next year?

Seriously, tho… It’s going to be great, mostly.

The main, and very appreciated, reason for the delays is backwards compatibility. Nobody needs another AngularJS to Angular transition.

Check this table for more details.

Bazel is a thing

A build tool thing to be exact. Like Make, Maven and Gradle. Not like webpack. Webpack is a module bundler, it doesn’t replace webpack, it works with it. Modern bundlers kinda do things that build tools used to, but with Bazel they don’t have to/shouldn’t.

Among its superpowers are building only what’s necessary and remote execution. Think scaling by adding nodes for parallel actions, consistent execution environment for the whole team and reusing build output between members. These alone bring huge build time reductions for big projects and large development teams where build (and unit and e2e testing) time can go into hours.

Google is using it internally and betting on it big. See the getting started.

You can have your website in space

Eric Simons demoed StackBlitz, a progressive web app that’s a full development environment. If you like VSCode, you’ll love this.

It was the snappiest, smoothest demo of the conference with some quite complex deploy processes, and redirecting a few hundred people to their twitter profile thanks to hot reload. Very smooth, Eric.

But Z, I want to have my website in space!

Eric and his team teamed up with Interorbital Systems to lunch a computer into space and host your code on it. What it lacks in speed it makes up for in… actual speed, being on a rocket and all, and the cool factor.

They made a video, so take a look.

How do you get a website in space?

Click the “Deploy To Space” button on top-right of your StackBlitz project.

StackBlitz Angular project screenshot

Cypress and time travel testing

Cypress is the test tool of ng-conf 2019. Dubbed a test runner built for humans. It’s an open source, front-end testing tool, built for the modern web.

It takes snapshots as your tests run. You can simply hover over commands in the command log to see exactly what happened at each step. That’s how you time travel in your tests.

Other notable features:

  • Debuggability
  • Real time reloads
  • Automatic waiting
  • Spies, stubs and clocks
  • Network traffic control
  • Consistent results
  • Screenshots and videos

More info on cypress.

Google serverless backend testing

When you deploy to a server, you normally have (or can make) available all the tools that you have on your local machine, for seeing what’s happening and debugging live code. When developing serverless, you, well… don’t have a server… and can’t do any of that. So you’re left to guess what went wrong. You can’t ssh into serverless. But if you don’t have a server, you don’t have to pay for its time running.

To get closer to best of both worlds Google serverless now allows you to add breakpoints to your production, running, code and to add conditional logs without having to redeploy anything.

After you trigger that code by accessing the page you want to debug, you can then time travel (kinda) because your logs and stacks are saved for every breakpoint.

Really powerful and very nicely packed stuff that I would like to have even in a server environment.

Render on the server for speed and SEO (Angular universal)

If you deliver JavaScript code that builds your app, fetches the data and then renders it, your user has to wait all that time to see any content. What if search engine doesn’t execute your JavaScript before trying to read your data? Your website content doesn’t get indexed, search engine doesn’t have your content and your website doesn’t appear in search results, sorry!

Angular universal will render the initial page to the user (and to search engine) right away, then load your app code, render it and show in place instead of the initial code.

It fixes some problems and introduces some new ones. Angular team has some interesting potential solutions they are experimenting with. And Ivy, ah Ivy, will help with some of those ideas, maybe…

How to think reactively (RxJS)

RxJS is hot but most people don’t know how to think reactively. It’s a paradigm shift and we have to do it to get most out of it. subscribe is bad (if you can do it without it).

There’s a lot more to this and RxJS popped out all over the place throughout the conference but this was the overall theme that I picked up regarding it.

Schematics and CDK

Very underutilized items in my toolbox. Schematic is a template based code generator that supports complex logic. It’s useful for customizing Angular projects to suit a particular need of your own organization. Angular team thinks they are really powerful and wants you to use them more.

An item on my ToDo list.

Typescript on the backend

NestJS is a framework that embraces TypeScript and the power of Node. You can use it to write backends in a style that feels familiar to writing Angular apps all while embracing MVC architectures you can see in other modern backend frameworks. Since it’s based on Node, you can use all the familiar libraries you’re used to.

Write ones, run everywhere (cross platform development)

In a day to day life of a modern homo sapiens, we use multiple devices to get our information and interact with the digital/distant world. As developers, we want to provide our users with options. We want to give out the message: do it wherever you are, through whatever device you want it, with the best possible experience for the device you’re using.

To do that, it sometimes means the best experience is an app. A mobile app, a desktop app, on any platform. Different platforms require different native code. So how do we not duplicate our efforts?

Notable technologies to help with that, and they cross into each others territories in places:

  • Angular Console
  • Electron
  • Ionic

Angular elements

In short, Angular components packaged as custom elements, a web standard for defining new HTML elements in a framework-agnostic way.

This is great because it allows you to create a web component with the full power of Angular in it. You can then use that outside of Angular context which brings out some very powerful possibilities.

Downsides to that could be (depending what you do) large component sizes (since you’re packing Angular, which can be not very tree-shakeable). Ivy will help with that but it’s not going to make your JavaScript disappear.

There are possible workarounds, not yet promoted by the Angular team, like sharing Angular code on window object, like you used to do with jQuery.

Use it for what it’s good for 😉

Material is now Angular components, new stuff coming

People already call Material, Angular Components. Things around that aren’t going to change much, you’ll still use them the same way you’re used to. Angular team said they have stuff coming, though.

Those are not the only Angular components available (although they are supported by the Angular team), there’s been plenty at the conference.

There are some that weren’t (because the name speaks for itself?)

Shameless plug for free and open-source Carbon Design System and Carbon Components Angular.

Until next time

What else?

What did you find interesting or eye-opening that I didn’t mention here?

When I Think Of Croatia

I think of sea. A peaceful summer morning before people crawl out of their beds. Sound of seagulls in the distance blending in with fade fog raising above the glass-like surface. Early rays of woken-up sun, reminding you it’s gonna be a hot day.

I remember early mornings, lugging sand with my dad, on a small cart, along a narrow, curvy path from far away parking lot, that was the closest place a truck could deliver it, to build a concrete deck so we wouldn’t have to sit in the dirt. That transitioned into being a house and took 12 full summers to build.

And a bumblebee, always passing by just around our second round. He would go his usual round circling the flowers in the same order and then land on my arm. He would stick around long enough to say “Hi!” and “What’s up, my favorite giant?”, and move along to the next patch of flowers.

“It’s all but a memory, never to be repeated again.”, I realize as I sit in our modern, Markham, Ontario, apartment, equipped with gadgets I built to (semi-)automate it. Life is now startups, Fortune 500s, electric cars, Mars shots, and building cool things out of nothing.

Croatia was never the things I remember about it. I’m in touch with everyone who wanted to stay in touch with me. It’s not always easy, but we make it work.

I remember pushing through the bushes with my brother and another friend. “Let’s get to the other side of the island in the straightest line possible”, I said, “it may took as a day but it’s gonna be super interesting”. Around lunchtime, we found ourselves on the top of the island, with a bird-eye view of a tourist-filled sandy beach. Boats floating in mid-air like dreamland, only anchors holding them down from escaping the earth. Standing on a patch of rocks, in the sea of thick green bushes, holding a piece of bread, pancetta and tomato, having lunch with a view.

This year seems exceptionally hard. Everybody, and their brother, is visiting Croatia. I’d like to think we did a great job promoting it. They ask me for tips. “How do I get most of my trip?” “Where should I visit?” “What is ______ like?”
And I answer them, provide them insights, help them have a fun, enjoyable trip and a great vacation. All the while knowing they are missing the point. They are visiting places I’ve never been to, eating food in restaurants I wasn’t able to afford. Croatia is party with a view.

It’s a figment of my imagination, the .1% time, serenity within insanity, never to repeat again, but possible to imitate. Maybe.

So if you visit Croatia this summer, go on a walk before the sun comes up and humans crawl out, along the rocky shore where no-one usually goes, after a non-drunk night, and wait for the sunrise. Look at the glass-like sea. See the mist raising close to the surface. Hear the seagulls in the distance and crickets on the top of the hill. Get drunk on Croatia I remember. And tell me I’m crazy.

Croatian Chicken Paprikash

Hungarians once ruled Slavonia, eastern continental part of Croatia. They must have had a great taste in food because you can still see their influence in Slavonia’s cuisine. Using liberal amounts of paprika and garlic, the cuisine is spicier than anywhere in Croatia. Also, if you want to make this dish really authentic, shop for a good, heavy cauldron and use open fire. It can make a great camping dish. Be responsible with fire.

As an Amazon Associate I earn from qualifying purchases.

Chicken Paprikash is one of the most prepared stews in Croatia, along with two other spicy stews, Fish Paprikash and Čobanac. You should try them all when you get the chance. But first thing first…

Tools you need

  • Chef’s knife to cut all the vegetables
  • Large pot, about three liters or more to fit all the ingredients
  • Cutting board to, yes, cut things on it 🙂
  • Ladle to scoop the paprikash out of the pot and onto the plate once it’s ready
  • Peeler to peel the carrots
  • Measuring spoons if you’re a perfectionist and don’t want to guesstimate the spices 😉


Servings: 4-6 people

  • 1 kg chicken piece (breasts, back… with bones and skin)
  • 2 large onions, finely minced
  • 3 large red peppers
  • 2 medium carrots, peeled
  • 3 tablespoons of oil
  • 3 teaspoons sweet ground paprika (red, dry)
  • 1⁄4 teaspoon chilli or hot paprika
  • 1⁄2 teaspoon salt
  • 1 teaspoon ground black pepper
  • 200 ml white wine
  • 300 ml water or chicken broth
  • Vegeta seasoning to taste (usually from half a teaspoon to a tablespoon or more)
    You’ll find Vegeta seasoning often in Croatian recipes, especially stews and soups. It gives them a distinctive aroma that’s hard to replicate without it. It contains a mix of finely cut dried vegetables and spices. It’s also salty so you may want to put it in and give it a taste before adding salt.

Croatian Chicken Paprikash

There are many variation of this stew in Croatia. In Zagreb area instead of serving it with pasta, people add potatoes or home-made dumplings. But in Slavonia, they make it spicy and serve with noodles.


  1. Heat the oil in a large pot.
  2. Add 2 large onions finely minced and sauté them until they are soft and transparent.
  3. Add chopped red peppers and carrots cut into slices.
  4. Chop the chicken into small pieces. Add chicken pieces and sauté it until the meat is white.
  5. Add wine and sauté it for 5 more minutes.
  6. Spice the stew with sweet and hot paprika, salt and pepper. The spicier, the better!
  7. Add water or chicken broth to cover the chicken.
  8. Cook for 50 minutes or until chicken is soft on low heat.

Serve with noodles or mashed potatoes!
As a salad, we recommend pickled red beet 🙂


Royal Alexandra Interprovincial Bridge

Royal Alexandra Interprovincial Bridge

This very interesting looking bridge is one of the first things I photographed when we came to Ottawa. The light wasn’t very special at the moment but I really liked the symmetry. (It would also be cool if the word symmetry was symmetrical)

Then we crossed it and ended up in Gatineau, Quebec. That’s why it’s locally known as Interprovincial Bridge, as well as Alexandra Bridge. Not sure why it’s not called Royal Bridge as well, but I guess two nicknames along the full name are quite enough.

It’s over 100 years old and used to hold some length records in its time but as it usually goes, someone younger came along and overthrew it. The younger chap was Quebec Bridge. Quebec now doesn’t have to share one side of the record with Ontario, I guess.

Workers had to constantly break the ice on the river when building the bridge. It’s Canada, so why I’m saying this?
Imagine approaching someone at the bar: “I’m an ice-breaker, nice to meet you!”

Again, it’s Canada so it’s 50-50 if they’d laugh at that…

Virtual Reality With Webcam

Couple summers ago I saw a cool hack where a sensor, placed on the TV, detected where the emitter, placed in the glasses, was, and based on that information adjusted viewpoint of the 3D scene displayed on the TV.

Cool, right? And all you needed were these two simple devices and the right software.

Well, why use two if you can use only one? 😀

There is already a sensor mounted on your laptop screen, called a webcam, and if you’ve ever tagged someone on Facebook, you know face recognition is a real thing. That means your computer can literally “see” where you are if you teach it how to look.

It took me a couple of days to bang things up and have a proof that this is possible to achieve. It then collected dust on my hard drive for a year or two until I woke up a couple days ago with an idea how to tweak it to make it representable.

How it works

I used OpenCV library to detect faces and their location in the image webcam sees. Then I picked the closest, the biggest one, and did all the calculations with it. OpenGL is responsible for rendering the 3D image, and Qt (cute) is putty that binds them together, handling all the events and window management.

Several things influence the right viewpoint for the 3D scene:

  1. Size of the scene you’re viewing
  2. Angle you’re viewing the scene from
  3. Distance from the scene

Those things depend on:

  1. Size of the screen
  2. Distance from the screen
  3. Distance from the camera
  4. Your camera lens width
  5. Angle you’re looking the screen at

For real-life application, things can be simplified. With webcam attached to your display/laptop, distance to screen and distance to camera are very similar and oriented in the same direction.

For the demonstration, I simplified things further. Distance from the screen, for the lack of stereo vision, can be estimated.
Since I’m doing this on a laptop screen, on a table, I decided that length of 1 in OpenGL was about 1dm (decimetre), or about the size of a coffee mug. Distance from the camera and from the screen is roughly 6dm.

I had no choice with the webcam lens width and I couldn’t find any info about it online but this was enough to run the prototype and guestimate other parameters.

Position of your eyes in the image defines the x and y axis coordinates of the 3D scene viewpoint and depends on the lens width. Wider lens will have more coverage (left, right, up and down) than the more narrower lens, meaning that your face won’t appear in the same place on both cameras, even though they have the same resolution. Parameters should be adjusted accordingly.

Z axis represents the distance from the scene. You know how when you get closer to your window, the more of outside you can see?
Now imagine your screen being a window into a virtual world. It would have to do the same. That’s possible to adjust with the OpenGL camera angle. I tried to estimate distance from the screen based on the face surface size in the image. Unfortunatly, with my webcam, that proved too volatile for smooth experience. So I just used fixed distance of 6dm. This can be improved with stereo vision in the future.

First scene in the video is with laptop screen tilted to 45° angle and viewed from slightly above. I had to adjust the viewpoint manually since program is not aware of the angle. If gyroscope-like sensor was embedded in it like in most tablets and phones, it could have been done automatically.

Second scene is from the angle you would normally look your screen at.

Third scene is a screen capture of the program output with camera output overlaid on the bottom left. Blue rectangle marks the location where the face was detected. If you watch carefully, you can see how a false positive was briefly detected on my shirt. That’s why it pays to always pick the biggest detected face in the scene. Also, you can play-fight who will the program pick with a person sitting next to you 😀

Possible improvements and future work

Let’s start by saying that face detection can be CPU intensive. Especially when you do it 60 times a second. We can get that load off to GPU, and in fact OpenCV supports that kind of operation. Unfortunately for me, driver for my GPU doesn’t. Proprietary driver does, but doesn’t support extending my screen to second display. Guess which one I prefer 🙂

Another obvious solution is putting more interesting graphics inside that virtual reality window. I know boxes aren’t very interesting to look at. What would you like to see instead?

Since all the code is cross platform, it’s fairly easy feasible to port it to your phone or tablet. Putting that selfie camera to a good use, what would you do with this technology in your phone?

Technology limitations and possible improvements

I already mentioned the lack of depth adjustments to the image. Because we use a single camera, it’s hard to know the distance of the viewpoint. Using a higher resolution webcam might make guestimating smoother. Adding a second camera and calibrating them, it is possible to extract that information from the scene and adjust the viewpoint and virtual camera lens width.

Talking about stereo image, we humans naturally have two eyes, see stereo, and sense depth. It’s hard to fool your mind into thinking this 2D image is 3D unless you cover one eye 😀
That said, 3D video is here and you’ve probably experienced it. It is possible to produce a 3D video for the 3D TVs by rendering the 3D scene twice with a slight tilt of the viewpoint. To go even further, instead of detecting just face, it’s possible to detect eyes and use their individual locations in the stereo image.

That would bring your gaming experience to the next level, plus ducking when things are flying your way would actually make sense. 😀

What would you do with it? How could this technology help you?

How To Jump-Start Phone Battery (No-Budget Hack)

Few days after Jasmina’s Sony Xperia Z charger broke, I had another unpleasant surprise. I woke up to a dead phone and no amount of charging, trying to turn it on, putting the battery in and out, helped…

As an Amazon Associate I earn from qualifying purchases.

How do I revive my phone’s dead battery?

Things to try before you jump start your battery

  1. Turn the phone on by pressing/long-pressing the power button
  2. Take the battery out. Press and hold the power button for at least 30s.
  3. Try a new battery. Borrow from a friend who has the same phone.

Why this can help

First point is self explanatory. If your phone turned off because of a glitch or something, this turns it back on, voila!

Second point might seem a bit weird to most. You obviously won’t turn on the phone while it has no power supply. Good thing this isn’t the point here. This step discharges residue charge from your phone’s electronic components. This also works for laptops and I used it to revive quite a few of them inspiring statements like “It didn’t work before, I swear!”. I know, I believe you 🙂

Third point, tried after second, makes sure it’s a problem with battery and not the phone. You can also try your battery in your friend’s phone.
I didn’t have a spare battery to try with, so I used the cable described later in article and connected the red and black directly to the appropriate pins inside of the phone. My Samsung S3 turned right on, so that ruled out problems with the phone itself.
If you’re in the similar situation be careful, the right pins will depend on the phone you have. My battery’s plus and minus pads were marked so I just followed and saw witch pins in the phone they touch. You can follow the same idea to figure out where your phone’s plus and minus pins are.

Why your battery plays dead

I’m talking about lithium-ion battery (sometimes called Li-ion battery or LIB), which are most common batteries in phones these days.

They can go unstable and “boom” if they get too discharged. To prevent that doodoo, engineers put electronics in place with some smarts in them. If the battery voltage drops below a certain point, to prevent further discharge, they disconnect the cells from the battery pads completely. Thumbs up for safety!

So why can’t you charge it?

Your phone has a battery charger or else you’d have to take your battery out every time to charge it. Convenient!
In order for that charger to work, it needs electricity. It gets its electricity from the battery, which currently puts out 0V.

The Hack (this is what you’re here for)

All you need is a spare USB cable and a charger (or a laptop, play station, smart TV…).

Tools (recommended, yet optional)

While you can probably do with tools you find in you kitchen, some of these tools will help a lot if you have access to them. If you don’t, they are very general tools and you can find many other uses once you get them.

  1. Wire stripper pliers
    • Recommended for cutting and skinning the cable
    • can do both, cut and skin the cable
  2. Regular pliers
    • can cut the cable
    • with a little technique, such as not applying full force, or using the top of the pliers, you can skin the wires as well
  3. Utility knife
    • although you could cut some wires with a utility knife, I wouldn’t recommend it
    • you can use it to skin the wires by applying little force to cut through insulation and then pulling it off with your fingers.
      Threads in the black and red wire are often very thin to make the cable more flexible. Unfortunately, this also makes them very easy to cut with a utility knife once they are exposed, be careful.
  4. Multimeter
    • Checking the battery.
      You can test your battery voltage and polarity and get the idea if battery is the culprit. If the voltage is a lot bellow what you expect (usually 5V), it probably is and this hack might help.
    • Checking wire polarity.
      When you cut and skin the wire, their colors usually indicate what they are used for, like in the picture below.
      Sometimes that’s not the case.
      You can use a multimeter to detect plus and minus polarity of the wires.
      To do that, plug in the cut cable into the power supply (be careful that your bare wires don’t touch), put the multimeter in a voltage measuring setting and try different combinations until you get a positive reading around 5 volts. Wire that’s on COM of multimeter will be minus and the other one will be plus.
  5. USB charging cable
    • In case you don’t have an extra USB charging cable lying around, you will need to get a replacement once you fix your battery to charge your phone the usual way.
  6. USB charger
    • Depending on your access to USB charging ports, you might not need this, however, if you’re planning on using some electronic device such as laptop or TV as a power source, keep in mind you might cause damage to that device if you do something wrong.
    • It’s also a nice to have even if everything goes well and it goes along nicely with the charging cable from the previous point.

Ready to get your hands dirty?


  1. Cut the USB cable.
  2. Skin 5mm (quarter of an inch) of red and black wires.
    USB cable wires
  3. Twist the exposed end of each wire.
  4. Plug the cable into charger.
  5. Place the black wire (-) to the minus of the battery.
  6. Place the red wire (+) to the plus of the battery.
  7. Hold in place manually for a couple of minutes.
  8. Put the battery back into the phone.
  9. Plug the phone into the charger.

Your phone should soon start charging. If it doesn’t, try again, make step 7 longer.

Jump starting a phone battery

Why this works

USB gives 5V which is above the normal Li-ion battery voltage (3.7V or 4.2V). This charges the battery enough to be briefly above the cut-off voltage. That’s just enough to start your phone’s charger and allow it to continue charging the battery until full.

I’ve been using and charging my phone normally since then. I also don’t allow my phone to die from empty battery. Lesson learned 🙂

If all else fails…

…and you are really 100% sure the problem is the battery and not the phone or anything else, you may need to, sigh, get a replacement battery.

Questions from comments

Could a universal charger work instead?

Yes, if it provides 5V of the correct polarity on the battery pads, as explained in “Why this works” section.

I’m struggling to get results, what else can I do?

You can trying boosting it, as described in step 7 of “The Hack” section, longer. Try couple of minutes or more, depending on the state of the battery, or even to a full charge. It needs enough juice to be able to take care of its charging process when you use original charger. You can also try  upping the voltage/current a bit.

What about in-built batteries?

How can I revive built-in batteries? Devices with built-in batteries don’t normally give direct access to battery (why would they) and you access the battery only through the charging system you’re trying to circumvent.

Solution for that would be to open the device to get to the battery. There’s a whole new set of things to watch out there, it depends on the individual device and it’s much riskier since you can break the device. Good news is the same principle applies once you have the battery in your hands.

There are plenty of phone fixing kits available and you can order them online.

If your device is bricked and you can’t take it to the shop, you might as well have a little fun with it and have a chance of fixing it, but be careful and don’t do anything you’re not comfortable with.

What if the wires are not the same colors as here in the picture when I cut the cord?

As mentioned in the Tools section, the best way would be to use a multimeter to determine polarity (to find out where’s the plus and where’s the minus.)
If you don’t have a multimeter, you could use an LED with a resistor in series to determine polarity.

Can the mobile battery explode while jumping it?

It’s highly unlikely, but I can’t rule it out. Likelihood goes up if battery is physically damaged.
Also, remember Galaxy Note 7? So, sure, but I wouldn’t bet on it.

What’s the difference between this reviving phone battery by jump-starting it, and charging it normally?

The goal here is not to replace your phone charger (although you could). The difference is bypassing phone’s charging system which refuses to charge the battery if it’s bellow a certain threshold.
Charging it by wires will briefly boost the voltage (revive the battery) which will enable phone to detect it and continue charging it to full.
You don’t really need to charge the battery all the way on the wires, merely boost it enough to get over the voltage that allows the phone to detect it and charge it.

Have you ever tried this? Do you have any other ways to revive dead batteries?

Found A Treasure Chest!

Found a Treasure Chest

Have you ever found some cool looking peace just lying around the hall? What did you do with it?

I’ve found a chest with my name on it, just lingering in the corner of the hall, in a house half way across the world. Curious, as I usually get, but cautious, as I also usually get, I cleared the furniture, put the chest in the middle and set the camera on timer.

I set down against the wall, contemplating, mentally preparing myself for what can be in it. Some childhood nightmare, hidden away to allow happy memories to thrive? Hidden treasure to enable me happy life once I become of age and venture to the wonderful new world? Something must have struck a chord…

The chest lid sprang open!

A flash of bright green light illuminated the hall. I jumped from my seat and flew toward the chest to close it: “I’m not ready yet!”

Camera timer went off…

What do you think happened next?

Sony Xperia Z – No-Budget Charging Hack

Head in pillowMy day started with Jasmina’s voice. Normally that makes me smile. With my face still in the pillow, and blanket over my head, I was trying to ignore the words:

“Zvonimir, I broke my phone charger!”

Three minutes later, I was on my laptop searching “Sony Xperia Z charging port replacement”. Relatively easy fix, requiring a bit of soldering. With all my tools left in Zagreb, next search was “Ottawa mobile phone repair”. Few phone calls later, we were pressing PRESTO cards in the bus, getting lost on the way to down-town Ottawa.


First shop was willing to fix it for $100, second told it should be about $50 but they need to see the phone first. Upon seeing the phone, they gave up since they don’t want to solder things, but told us we can order magnetic charger for $40 online.

Few hours later, back at my laptop, searching for “wireless charging Sony Xperia Z”._DSC2270

One type of chargers has a dock with two pins in it. You place the phone in the dock, magnets lock the phone in place, pins touch the pads on the phone, and it starts charging.
The other type has a USB cable on one side and pins and a magnet on the other side.

So it’s really simple, getting voltage (5V) on the phone’s charging pads. Let’s finish this tutorial style:

USB cable wires

  1. Cut the USB cable.
  2. Skin 5mm of red and black wires.
  3. Twist the exposed end of each wire.
  4. Plug in the USB cable into charger.
  5. Place red wire on the top pad.
  6. Place black wire on the bottom pad.
  7. Enjoy 🙂


Charging Sony Xperia Z

Notice that the orange charge indication LED on the top-right of the phone is on 🙂

Do you have some no-budget or low-budget hacks of your own?