Skip to content

Instantly share code, notes, and snippets.

View kenyipp's full-sized avatar

Ken Yip kenyipp

View GitHub Profile
@kenyipp
kenyipp / react-native-svg-animations.d.ts
Created January 21, 2024 20:16
Definition file for react-native-svg-animations
declare module 'react-native-svg-animations' {
interface AnimatedSVGPathProps {
d: string;
strokeColor?: string;
strokeWidth?: number;
strokeLinecap?: string;
easing?: any;
duration?: number;
width?: number;
@kenyipp
kenyipp / release.yml
Last active December 9, 2023 23:13
Automated GitHub Release Workflow
name: Create Release
on:
push:
branches:
- master
jobs:
release:
runs-on: ubuntu-latest
@kenyipp
kenyipp / Amazon Bedrock - Node.js SDK Example.ts
Last active October 7, 2023 04:53
An example that uses Amazon Bedrock to generate data and transform the response into JSON
import {
BedrockRuntimeClient,
InvokeModelCommand
} from "@aws-sdk/client-bedrock-runtime";
const client = new BedrockRuntimeClient({ region: "us-east-1" });
const textDecoder = new TextDecoder("utf-8");
const command = new InvokeModelCommand({
modelId: "ai21.j2-mid-v1",
@kenyipp
kenyipp / Rust - Decode JWT Header
Created December 27, 2022 17:46
Decoding the json web token header using the base64 and serde_json modules
#[derive(Deserialize, Debug)]
struct Header {
pub alg: String,
}
let header = base64
::decode_engine(
"JWT Header",
&FastPortable::from(&alphabet::STANDARD, fast_portable::NO_PAD)
)
@kenyipp
kenyipp / Rust Error Handling.rs
Created December 17, 2022 21:45
Handle the rust errors using the anyhow and thiserror crates
use anyhow;
use anyhow::Result;
use thiserror::Error;
#[tokio::main]
async fn main() -> Result<()> {
match always_error() {
Ok(()) => println!("Success!"),
Err(err) => println!("The error message is: {}", err),
}
@kenyipp
kenyipp / Rust - Vector.rs
Last active December 17, 2022 18:50
Sample script to demonstrate how to use vector in rust
fn main() {
// let a = [1, 2, 3];
// let mut v1: Vec<i32> = Vec::new();
// let v2 = vec![1, 2, 3];
let mut v = vec![1, 2, 3, 4, 5];
match v.get(2) {
Some(third) => println!("The third element is {}", third),
None => println!("There is no third element"),
@kenyipp
kenyipp / Rust - Async Request & Response.rs
Created December 17, 2022 18:47
Using the "reqwest" and "serde" crates to fetch and Serialize/ Deserialize the data from typicode.com
use serde::{ Serialize, Deserialize };
// Allowed the main function to be async, specifies our async code will be executed by the tokio runtime
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
// print!("{:#?}", add_todos().await);
Ok(())
}
async fn add_todos() -> Result<Todo, reqwest::Error> {
@kenyipp
kenyipp / Rust - sleep.rs
Last active December 17, 2022 18:39
Future that sleep for certain milliseconds and return a string
use std::thread::sleep;
use std::time::Duration;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
sleep_and_run_and_return_string(1000).await;
println!("I have been waiting for 1 seconds");
Ok(())
}
@kenyipp
kenyipp / environment.d.ts
Created October 30, 2022 23:58
Type annotation on process.env
declare global {
namespace NodeJS {
interface ProcessEnv {
YOU_ENV: string
}
}
}
// If this file has no import/export statements (i.e. is a script)
// convert it into a module by adding an empty export statement.