Categories
Programming Web Technology

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.

Categories
Programming Server Admin Tech Tips and Tricks Web Technology

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,

Categories
Programming Server Admin Tech Tips and Tricks

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!

Categories
OSX Programming Server Admin

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.

Categories
Linux Programming Server Admin Web Technology

Docker named volume explained

Named volume is a new feature since Docker 1.9, it allows you to manage persistent data more easily, and also the volume can be provided by other storage drivers such as Glusterfs instead of “just a directory on the host”. This new feature is particularly useful in production environment. (On the Dev side, I think we still need mounted volume)

Categories
Programming

PHP Traits – why is it useful

I know I’m late into the game but I recently found that Traits in PHP is really useful. PHP Traits come in handy if you have some part of a class you wish to re-use in the future in another class, but you don’t want strict inheritance relationship.

What is Traits

PHP Trait defines a code segment that is simply copy-n-pasted into a class at compile time. It can contains variables, constants, methods,

Categories
Programming

Changing the author info of previous commits in Git

The problem is that you forgot to change the email to your work email before you commit your code, so you’re exposing your personal email. How to change it?

Categories
Linux Programming Server Admin Web Technology

Using Envoy to deploy website on the remote server

Envoy is a simple tool developed by the Laravel team. It is designed to perform task like deploying a website on a remote server, e.g. your VPS.

How does it work?

Categories
Programming Web Technology

Customize your own version of Bootstrap

Bootstrap is a great starter framework, I use it almost everyday. However sometimes you want to customize it to your needs. While you can use the Customize tool on the official website which is very handy, but you may want to automate the build and integrate with your workflow, this is the tutorial for you.

Categories
Programming

WordPress command line interface (WP-CLI) guide

WP-CLI is a tool for managing your WordPress website via the command line. This may come in handy if you want to manage your WP instance without going through the web interface, or automate certain operations (change of Settings, perform backup etc.)

For example, here is a sequence of commands for installing a fresh copy of wordpress: