Monday, August 29, 2022

Hack library

f返回值是Awaitable, 就要用xxx_aync的函数

f返回值是Awaitable<bool>, 就要用if (await f)



self::functionA

return await EntAbc::queryFromReq($req)->queryMi->gen() |> vec ($$)

return await EntAbc::queryFromReq($req)->queryMi->gen() |> Vec\filter_nulls ($$)


Data Structure (Hack)

Vec: $a = vec[1, 2]

Dict: $b = dict["foot" => 2]

keyset: $c = keyset[1, 2]

const string USER_NAME = "we are";

static::USER_NAME 

Str\joinjoin成一个字符串$a = Str\join(Vec\reverse($vec), ',');
Str\format组成一个字符串$a = Str\format('%d is num', 2);
C\countVec的个数$a = C\count($requirements)
C\is_emptyVec是否为空C\is_empty($requirement)
C\fb\any_async
C\any
Vec中任意一个对应lambda返回true就return true$has_deprecated_req = C\fb\any($requirements, async $requirement ==> {return true},);
Vec\mapVec中每个对应lambda组成的新vec$a = await Vec\map_async($requirements, async $requirement ==> {return await static::func(1)},);
Vec\filterVec中filter对应lambda组成的新vec$a = Vec\filter($requirements, aysnc $requirement ==> 1 === 1,);
int->str类型转换$a = (string) $c
Vec\concat合并两个vec变成一个$c = Vec\concat($a, $b)
Vec\diff合并两个vec变成一个$c = Vec\diff($a, $b)
Vec\intersect求交集$c =Vec\intersect($a, $b)
C\countVec的个数$a = C\count($requirements)

返回null或者属性 Shapes::ids($student, 'id')
shape('id' => 23)

->whereInstanceOf(Abc::class)
->where(P::asyncLambda(async $commit ==> await $commit ->...->genExistence),)


Ent
EntTag::genForceFromName($vc, 'pending')->getID()

Update
EntAction: EntCommitmentMutator::updateForObject($vc, $commitment,)->setLegal('abc')->genSaveX();


EntAction: 
EntCommitmentMutator::updateForObject($vc, $commitment,)->actionUpdateStatus(Status::ABC)
->addTagIds(vec[$id])->genSaveX()
1. 自定义函数方法也就是contructor,否则需要每个都要setName('n')->setId(2)
2. 一连串动作

自动生成代码
1. Spec: EntFiled定义
2. Query: where语句
3. (controller): get方法, 
4. TGraphQL~Fields: GraphQL fields, 需要再EntSchema config exposeAccessors
5. TEnt~Action: Trait内部文件,只要加入action就会产生,用于Ent~Mutator::updateForObject($vc, $ent)->addTags($data)->genSaveWithoutReload();

Create
EntCommitmentMutator::create($vc)->setName('abc')->genChangeset() // used for Ent triggers Ent
genSave, genSaveX //return null vs exception when save and load a updated Ent

EntQuery
get
gen
genOnlyValue <==> first()->gen()
queryAll: static function. Example: EntTag::queryAll($vc)
queryX: toEdge (Return edge object). Example: queryTag()->genOnlyValue()
queryFromX: fromEdge (Return self object)


得到一个Entity
1. $tag = EntTag::genForce($vc, $f-bid)
2. $tag = EntTag::qeuryAll($vc)->whereID(P::equals($f-bid))->gen()


nonnull
如果返回值为?EntTag, 用此法去掉问号$a as nonnull



GraphQL

<<GraphQLObject>>, <<GraphQLStrongObject>> 加到class中
<<GraphQLField>> 加到方法中
<<GraphQLRootField>> 加到getAllPets方法中定义GraphQL id为all_pets, 
   对应的GraphiQL:
    {
           all_pets {
               id
           }
    }

<<GraphQLMutationRootField>>
在对应的Hack函数如GraphQL~MutationCall中定义,函数输入参数包括GraphQLInputObject
   对应的GraphiQL:
    mutation {
           create_pet {
               id,
               ower
           }
    }

<<GraphQLEnum>>
<<GraphQLInputObject>> 自定义graphql类型如lat, lng
<<GraphQLInterface>>
<<GraphQLUnino>> generic返回类型

Relay

const data = usePreloadedQuery(
   graphql`
      query all_pets
   `,
   queryRef
);

queryRef = loadQuery(...)
const {node} = useLazyLoadQuery
如果只是读,不涉及写,一般只要加入到现成的GraphQL中即可。

data.post, node.sg in React

Fragment: 一部分query的alias,另其可复用
const data = useFragment(

const [addComment] = useMutation(
这是定义在叫Hook的JS文件中,包括写入到后端和onError,onComleted类似于Ajax的call

React

useState

export default function AbcComponent({
    objectID,
    showHeader = true,
}: Props): React.MixedElement {
      const [counter, setCounter] = useState<number>(10); //10是初始值
      return (
         <div>{counter}</div>
       <Another component 
           defaultProp = {counter}
       />
        <Button
            onPress={() => setCounter(counter - 1)}
        />
     );

}

绑定后端数据到State
const [counter, setCounter] = useState(data[0].pet_name);

Flow

typed javascript: number, boolean, string, Map<string, Array<string>>

只用当变量用于component property时候采用花括号,如果在JS中不需要。
<Component
  name={name}
/>

Tuesday, February 1, 2022

Video on Demand设计

 https://aws.amazon.com/solutions/implementations/video-on-demand-on-aws/









Audio on demean并没有具体教程,不过mediaConvert也可以覆盖。可以根据这个操作

https://docs.aws.amazon.com/mediaconvert/latest/ug/setting-up-audio-only.html

1. Input, remove the video selector

2. Add output groups, choose APPLE HLS

3. in the encoding setting in the output setting, remove video

4. in the Apple HLS, choose Container for Audio-only output, choose MPEG-2 Transport Stream (关键步骤)

Friday, July 2, 2021

AWS Data Pipeline

 AWS Data Pipeline用于ETL,一个use case是prod accout上的DDB数据clone到alpha account上DDB。先用Data Pipeline复制到alpha上的S3(CloudWatch 定时event),然后再用lambda将数据加载到DDB(CloudWatch 定时event)。缺点是如果这两个步骤是独立的。

Glue有ApplyMapping等,如果需要对数据进行编辑,就应该用Glue

Sunday, June 27, 2021

AWS Secrets Manager简介

用于存RDS,documentDB等密码

如果lambda在VPC的话,不能直接访问Secrets Manager,要开放VPC endpoint才可以
https://docs.aws.amazon.com/secretsmanager/latest/userguide/vpc-endpoint-overview.html

Saturday, June 26, 2021

Google Search 技巧

 


"vtasters"Exact Match, "use * card"
site:stackoverflow.com how to install java 在某个网站查找



Nasdaq news after:2020时间范围查询
Nasdaq news before:2020-03-01
Nasdaq news on:2020-04-15
fngu download filetype:pdf文件格式

intitle:cloudwatch只搜title
allintitle:cloudwatch dashboard所有关键字都在title
related:amazon.com相似网站



Ref


Thursday, June 10, 2021

AWS Glue中PySpark和Spark SQL

 Glue封装了PySpark和Spark SQL


PySpark Select columns


DataSource0.count()

DataSource0.printSchema()

df = DataSource0.toDF()

找到value column中含数字字母的

df.filter(df['value'].rlike('\w+')).show()

找到value column中只含数字字母的

df.filter(df['value'].rlike('^a-zA-Z\d\s:') == False).show()



Sunday, June 6, 2021

AWS CDK简介

 CDK是用多种语言实现的打包工具。


下面介绍是type script (类似于Node.js)

按这几个步骤初试


Step Function

Glue

可以用json来实现state,而不是用new tasks.GlueStartJobRun. 这是因为有些功能并不支持如GlueStartJobRun.sync. 


const stateJson = {

  Type: 'Task',

  Resource: 'arn:aws:states:::dynamodb:putItem',

  Parameters: {

    TableName: table.tableName,

    Item: {

      id: {

        S: 'MyEntry',

      },

    },

  },

  ResultPath: null,

};


Lambda

CDK中step function中的lambda支持payload参数

new tasks.LambdaInvoke(this, 'Invoke with payload field in the state input', {

     lambdaFunction: fn,

      payload: sfn.TaskInput.fromObject({

            "execution.$": "$$.Excution.Id",

            "catalogId": sfn.JsonPath.stringAt('$.catalogId'),

      }),


});


API gateway

https://docs.aws.amazon.com/cdk/api/latest/docs/aws-apigateway-readme.html#integration-targets