Simple script to keep MySQL running

Sometimes MySQL crash for various reasons (out of memory), there is a simple hack to make sure MySQL running.

Save this to dbcheck.sh

Make it executable by chmod +x dbcheck.sh , and setup a cronjob as root for it to run periodically (e.g. every minute)

Note that this is not considered a good practice, you should find out what is crashing the DB/service, but it is a simple hack to save your some time.

Convert jQuery ajax function into promise (in ES6)

If you happens to want to convert jQuery’s ajax function into promise style using ES6 promise. Here is an example for you:

utils.js

Then you can use ajaxPostPromise in this way:

app.js

That’s it!

You can apply the same principle in converting other callback-style library into promise!

p.s. If you are looking for native and promise way to call your API, you may also check out fetch.

Use Slack as notification service in your workflow

This article intend to give some pointers to developers new to Slack on how to integrate their services / workflow with it. You can add a message to Slack and get notified as simple as a command like this:

My Use case

So my main purpose of using Slack it to get notified with certain events happen and implement it with minimum effort. For example, Continue reading “Use Slack as notification service in your workflow”

10 common usage of lodash

lodash is a excellent tool library for every javascript developer. It is similar to underscore, but smaller. It is always come in handy to keep it in your toolchain.

map

This should be quite familiar for most JS developers. It iterate through a collection and perform a 1-to-1 mapping.

mapValues

mapValues is just like map but instead of the key being iterate Continue reading “10 common usage of lodash”

5 Docker tricks make your life easier – Part 1

1. Logs and monitoring

You can view logs of a container by

And you can monitor output from a container by

2. Open a shell in the container

If you want to quickly dive into the container, Continue reading “5 Docker tricks make your life easier – Part 1”

Android Emulator crash/error when downloading file

When you use Android Emulator with “Marshmellow” (6.0) SDK, and want to download a file with the Browser app. You may get the following situation:

  1. “an sd card is required to download”
  2. Force close

After some struggle, I have found that it is because your browser app has no permission to access the Storage. Adding Storage permission in the Settings will solve the problem.

Cannot start Android Emulator (initial hax sync failed)

If you see something like this when booting Android Emulator:

It is likely that one of the following app is running:

  1. Virtualbox
  2. Docker
  3. Other virtual machine applications

Stop all of them, and try again.

Simple command to monitor directory changes on Mac

Sometimes you want to know if a certain App/code/IDE changed something on the disk, this little script / command may come in handy.

Install fswatch

install fswatch as a global command

The script

Only fswatch is not enough, here is the script that does the trick

Save as a script e.g. monitor.sh, then give it executable permission

Now run the script and supply the path as parameter, and you will start monitoring the directory

Enjoy!

Migrating to “Docker for Mac” from Toolbox

As Docker for Mac becomes available, it’s about time to ditch Docker Toolbox which requires a VM running in background. The migration is surprisingly easy. The Official doc recommend you to read this article “Docker for Mac vs. Docker Toolbox“, while I think it’s a pretty good read, I will simply tell you the steps to migrate if you just need the info. Continue reading “Migrating to “Docker for Mac” from Toolbox”

Using SoundPool in Android

If your app/game need to play a sound when user click certain object, you will quickly found out that using MediaPlayer is a bad idea. This is what SoundPool is for, however, its API is still a bit unfriendly. This is some notes on how to use it and my suggested usage pattern.

Obtaining a SoundPool object

It is recommended to use the Builder, but lower SDK device does not support that, so this Continue reading “Using SoundPool in Android”