Health checking on your websites

Posted on 1 year ago by Ping Cheng

If you are running one or a few your websites, you definitely would like to avoid any access issue to your site. However, you cannot stop it happens. When your website does have some access issues, you need to know at the first place before any of your visitors, and then you can have some time to fix it.

A straightforward way to monitor your website is writing a small script that can send a request to your site and check if the response is what we are expected. If you cannot hear a response or the response is something you are not acceptable, then an issue can be identified and send a notification to your preferred channel.

This is a very simple python script that we can use


import urllib
import json
import urllib2
import time

def notify_slack(options):
    wekbhook_url = 'my-slack-webhook-url'
    data = json.dumps(options)
    request = urllib2.Request(wekbhook_url, data)
    urllib2.urlopen(request)

def check_url(url, expected_status = 200):
    try:

...

[ Read More ]


Clean branches that already had been merged into master

Posted on 1 year ago by Ping Cheng

When you are working in a development team for a project, there are heaps of branches on the remote git repository for PR or whatever reasons. Usually the branch would be automatically delete after that PR got merged into master on the repository hosting platform. And then you might notice your local has heaps of branches that were "abandoned".

This bash script can check what branches had been merged and try to delete them. Script gist: https://gist.github.com/pingcheng/136f404e86761491f7b813a5632b4720


#!/bin/sh

# get all merged branch
branches=$(git branch --merged master | grep -v '^[ *]*master$')

# define colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
LIGHT_GRAY='\e[90m'
NC='\033[0m'

# if no branches are need to clear, just exit
if [ -z "$branches" ]
then
        echo "${GREEN}No merged branches to remove${NC}"
        exit 0
fi

# delete each merged branch
for branch in $branches
do
        echo "${LIGHT_GRAY}Deleting merged branch - ${YELLOW}$

...

[ Read More ]


Use Tailwind in Laravel

Posted on 1 year ago by Ping Cheng

Tailwind a very low-level CSS framework that only includes classes but does not contain any pre-defined components. This means you can define your own component styles without override the styles come with the CSS framework.

To have a better understanding of Tailwind, please read the official website: https://tailwindcss.com

Here are the steps that integrates the tailwind into your Laravel project:

Install

First, let's install the tailwind itself

# Using npm
npm install tailwindcss

# Using Yarn
yarn add tailwindcss

Then, let's install the PurgeCSS to cut off classes that we did not use to save our final css file size

# Using npm
npm install laravel-mix-purgecss --save-dev

# Using Yarn
yarn add laravel-mix-purgecss --dev

Create a configuration file

npx tailwind init

After ran the above command, you will find tailwind.config.js was generated on your project root directory.

Import Tailwind

Afte

...

[ Read More ]

Search
Hand crafted with by Ping Cheng