Skip to content

Instantly share code, notes, and snippets.

View kenng's full-sized avatar
💭
calm

Ken Ng kenng

💭
calm
View GitHub Profile
@kenng
kenng / .htaccess
Created August 23, 2021 07:02
.htaccess with username password
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/to/.htpasswd
Require valid-user
@kenng
kenng / bash.sh
Last active August 5, 2021 04:39
linux productive command line
#!/bin/bash
##### find the last modified file (exclude folder)
# show files sorted by modification time in reverse order
alias lsr="ls -ctrla"
lsrexec(){ find . -maxdepth 1 -type f -exec ls -ctrA1 "{}" +; }
lsrlast(){ lsaexec | tail -n1; }
# example to find the last modified file with 'tar' in its name: lsagrep tar
lsrgrep(){ lsaexec | grep $1 | tail -n1; }
@kenng
kenng / laravel-db.sh
Last active July 29, 2021 08:30
laravel database helper bash function - to dump and login into mysql shell
function laraveldbinfo() {
HOST=`perl -lne 's/(?<!^#)DB_HOST=(.*)/\1/ or next; print' .env`
NAME=`perl -lne 's/(?<!^#)DB_DATABASE=(.*)/\1/ or next; print' .env`
USERNAME=`perl -lne 's/(?<!^#)DB_USERNAME=(.*)/\1/ or next; print' .env`
PASSWORD=`perl -lne 's/(?<!^#)DB_PASSWORD=(.*)/\1/ or next; print' .env`
BACKUP_NAME="$NAME-$(date +%Y%m%d-%s).sql"
echo "password is $PASSWORD"
}
function laraveldblogin() {
@kenng
kenng / .env
Created July 19, 2021 05:03
sample laravel .env.testing
APP_NAME="My Sample Laravel App"
APP_ENV=testing
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=db-tests
@kenng
kenng / testing.yml
Last active July 19, 2021 04:51
dockerized laravel unit testing with github action
name: Laravel testing
on:
push:
branches:
- release
jobs:
phpunit:
runs-on: ubuntu-20.04
@kenng
kenng / index-full-file.html
Created April 26, 2021 16:00
web push 04
<html>
<title>Firebase Messaging Demo</title>
<style>
div {
margin-bottom: 15px;
}
</style>
<body>
<div id="token"></div>
<div id="msg"></div>
importScripts("https://www.gstatic.com/firebasejs/7.16.1/firebase-app.js");
importScripts(
"https://www.gstatic.com/firebasejs/7.16.1/firebase-messaging.js",
);
// For an optimal experience using Cloud Messaging, also add the Firebase SDK for Analytics.
importScripts(
"https://www.gstatic.com/firebasejs/7.16.1/firebase-analytics.js",
);
// Initialize the Firebase app in the service worker by passing in the
@kenng
kenng / index-firescript.html
Last active April 26, 2021 15:39
web push 02
<script>
var config = {
messagingSenderId: "YOUR-SENDER-ID",
apiKey: "YOUR_API_KEY",
projectId: "YOUR_PROJECT_ID",
appId: "YOUR_APP_ID"
};
firebase.initializeApp(config);
</script>
@kenng
kenng / index.html
Last active April 26, 2021 15:37
web push 01
<html>
<title>Firebase Messaging Demo</title>
<style>
div {
margin-bottom: 15px;
}
</style>
<body>
<div id="token"></div>
<div id="msg"></div>
@kenng
kenng / main.go
Last active July 12, 2020 16:04
golang HTTPS server
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
)