Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
calm

Ken Ng kenng

💭
calm
View GitHub Profile
@kenng
kenng / .htaccess
Created Aug 23, 2021
.htaccess with username password
View .htaccess
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/to/.htpasswd
Require valid-user
@kenng
kenng / bash.sh
Last active Aug 5, 2021
linux productive command line
View bash.sh
#!/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 Jul 29, 2021
laravel database helper bash function - to dump and login into mysql shell
View laravel-db.sh
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 Jul 19, 2021
sample laravel .env.testing
View .env
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 Jul 19, 2021
dockerized laravel unit testing with github action
View testing.yml
name: Laravel testing
on:
push:
branches:
- release
jobs:
phpunit:
runs-on: ubuntu-20.04
View index-full-file.html
<html>
<title>Firebase Messaging Demo</title>
<style>
div {
margin-bottom: 15px;
}
</style>
<body>
<div id="token"></div>
<div id="msg"></div>
View firebase-messaging-sw.js
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
View index-firescript.html
<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 Apr 26, 2021
web push 01
View index.html
<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 Jul 12, 2020
golang HTTPS server
View main.go
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
)