Skip to content

Instantly share code, notes, and snippets.

View nothingrealhappen's full-sized avatar
🏠
Working from home

NothingRealHappen nothingrealhappen

🏠
Working from home
  • Mars
View GitHub Profile

好的,为你量身定制一个学习 EC2 的计划,以“搭建一个可以自动扩容的 WordPress 网站”为实践目标。这个项目能让你接触到 EC2 的核心概念以及与之配合的关键 AWS 服务。

学习目标:

  • 掌握 EC2 实例的生命周期管理(创建、启动、停止、终止)。
  • 理解 AMI(Amazon 系统映像)、安全组、密钥对的作用。
  • 学会在 EC2 实例上部署 Web 应用(以 WordPress 为例)。
  • 掌握使用 RDS (Relational Database Service) 作为托管数据库。
  • 掌握使用 EFS (Elastic File System) 作为共享文件存储。
@nothingrealhappen
nothingrealhappen / static-ip-for-wsl.md
Last active October 31, 2024 03:24
static ip for wsl

create /etc/init.wsl for below contents

#!/bin/bash
ip addr del $(ip addr show eth0 | grep 'inet ' | awk '{print $2}') dev eth0
ip addr add 192.168.1.xxx/24 dev eth0
# point to your gateway
ip route add default via 192.168.1.xxx dev eth0
@nothingrealhappen
nothingrealhappen / timeDuration.js
Created April 7, 2024 05:41
Calculate duration
"use strict";
const calculateTime = (ranges) => {
const totalTime = ranges.reduce(
(acc, x) => {
const start = x[0];
const end = x[1];
let currentTotal = 0;
// Case E, No overlap
@nothingrealhappen
nothingrealhappen / useLoadingIndicator.tsx
Last active February 7, 2024 06:39
useLoadingIndicator
import { useState } from "react";
type FunctionArgs<T> = T extends (...args: infer Args) => unknown
? Args
: never;
type FunctionReturn<T> = T extends (...args: unknown[]) => infer Return
? Return
: never;
@nothingrealhappen
nothingrealhappen / fp-sample.ts
Created December 22, 2023 04:13
fp-ts sample
import { pipe } from 'fp-ts/function';
import * as O from 'fp-ts/Option';
import * as E from 'fp-ts/Either';
import * as A from 'fp-ts/Array';
import { sequenceT } from 'fp-ts/Apply';
import { flow } from 'fp-ts/function';
import * as t from 'io-ts';
// Example of a complex validator using io-ts
const UserProfile = t.type({
@nothingrealhappen
nothingrealhappen / crop.sh
Created July 19, 2023 15:25
Crop Midjourney Pictures from 4x4 to single image for each item
for file in *.png; do
convert "$file" -crop "2x2@+0+0" -gravity center -repage +0+0 "output_${file%.*}_%d.jpg"
done
@nothingrealhappen
nothingrealhappen / app.tsx
Created July 1, 2022 08:27
auth0-react get token outside of react component
// your app.tsx
const {
getAccessTokenSilently,
loginWithRedirect,
user,
isAuthenticated,
isLoading,
} = useAuth0();
useEffect(() => {
@nothingrealhappen
nothingrealhappen / regionList.json
Created May 19, 2022 03:48
AWS Region list JSON, update time 2022-05-19
[
{
"name": "US East (Ohio)",
"region": "us-east-2"
},
{
"name": "US East (N. Virginia)",
"region": "us-east-1"
},
{
const _ = require("lodash");
const sequential = require("promise-sequential");
/**
* Batch execute promises in chunks
*/
const chunkPromise = (promises, chunkSize = 5) => {
const chunkedPromise = _.chunk(promises, chunkSize).map(
(promiseGroup) => () =>
Promise.all(promiseGroup.map((promiseFn) => promiseFn()))
@nothingrealhappen
nothingrealhappen / aws_mysql_pub.sh
Created December 8, 2021 08:07
mysql-to-cloudwatch
#!/bin/sh
max_connections=$(sh /home/bitnami/monitor/mysqlmon.sh max_connections)
max_used_connections=$(sh /home/bitnami/monitor/mysqlmon.sh max_used_connections)
threads_connected=$(sh /home/bitnami/monitor/mysqlmon.sh threads_connected)
cdate=$(date -u +%Y-%m-%dT%H:%M:00.000Z)