Skip to content

Instantly share code, notes, and snippets.

Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)
@buithaibinh
buithaibinh / ScopePermissions.json
Created January 20, 2022 06:45
Use permissions boundaries to limit the scope of IAM users and roles and prevent privilege escalation?
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAdminAccess",
"Effect": "Allow",
"Action": "*",
"Resource": "*"
},
{
@buithaibinh
buithaibinh / s3_stream_file.js
Last active May 6, 2022 03:06
stream s3 file to browser
const streamS3File = async (request, response) => {
const data = JSON.parse(request.body);
const params = {
Bucket: data.bucket,
Key: data.key,
}
// fetch file meta. it's not propagated from the S3 SDK
const meta = await s3.headObject(params).promise();
@buithaibinh
buithaibinh / install_mongo_on_aws_linux2.MD
Last active August 23, 2021 03:11
How to install mongo tool on AWS linux 2

Create file mongodb-org-3.6.repo

use vi create a blank file.

sudo vi /etc/yum.repos.d/mongodb-org-3.6.repo

Paste below content

@buithaibinh
buithaibinh / csv.util.js
Last active July 23, 2021 08:03
merge all properties of objects in array
const mergeObjects = (contents) => {
// Create an object with all the keys in it
// This will return one object containing all keys the items
let result = {};
// Create an object with all keys set to the default value ('')
contents.forEach((item) => {
result = _.merge(result, item);
});
@buithaibinh
buithaibinh / encode.util.ts
Last active July 23, 2021 07:17
find all character which is non-SJIS
import Encoding from 'encoding-japanese';
// https://0g0.org/category/2E80-2EFF/1/
export const findNonSJISCharacters = (data: string) => {
// get current encoding of input.
const detectedOrg = Encoding.detect(data);
return [...(data || '')].filter((char) => {
const ucd = char.charCodeAt(0);
// convert current code to SJIS
@buithaibinh
buithaibinh / ip_look_up.js
Created March 12, 2021 10:46
How To Detect The Location of Your Website’s Visitors Using JavaScript
function ipLookUp () {
$.ajax('http://ip-api.com/json')
.then(
function success(response) {
console.log('User\'s Location Data is ', response);
console.log('User\'s Country', response.country);
getAdress(response.lat, response.lon)
},
function fail(data, status) {
@buithaibinh
buithaibinh / aws-amplify-build-settings-cache-static-files.yml
Created March 9, 2021 11:43 — forked from mrcoles/aws-amplify-build-settings-cache-static-files.yml
Sample file caching custom headers to add to an AWS Amplify build-settings.yml file
frontend:
customHeaders:
# cache static assets! (can I just use a glob for this, e.g., '**/*.{js,css,gif,ico,jpg,png,svg,mp4,webm}' ?)
# js
- pattern: '**/*.js'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
# css
- pattern: '**/*.css'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
# images
# Update the installed packages and package cache on your instance.
sudo yum update -y
# Install the most recent Docker Engine package
## Amazon Linux 2
sudo amazon-linux-extras install docker
## Amazon Linux
# sudo yum install docker
# Start the Docker service.
@buithaibinh
buithaibinh / regex-japanese.txt
Created February 12, 2020 03:23 — forked from terrancesnyder/regex-japanese.txt
Regex for Japanese
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)