Skip to content

Instantly share code, notes, and snippets.

@delasign
delasign / contentfulNextJSSamplePageWithQuery.tsx
Created April 18, 2024 18:45
Sample NextJS page with a contentful query.
// MARK: NPM Modules
import Image from "components/common/image";
// MARK: Types
import HomeEntry from "types/contentful/pages/home";
// MARK: Functionality
import getHomePage from "utils/contentful/queries/home";
// MARK: React Component
export default async () => {
const entry: HomeEntry = await getHomePage()
const { metaTitle, metaDescription, seoImage } = entry.fields
@delasign
delasign / contentfulEntryQuery.tsx
Created April 18, 2024 18:44
Sample Contentful Entry Query
// MARK: Functionality
import ContentfulClient from "utils/contentful/client";
// MARK: Function
export default async (): Promise<any> => {
const response = await ContentfulClient.getEntry("AN_ENTRY_ID");
console.log("response: ", response)
return response
}
@delasign
delasign / contentfulClient.tsx
Created April 18, 2024 18:43
Sample Contentful Client
// MARK: NPM Modules
import { createClient } from "contentful";
// MARK: React Component
const ContentfulClient = createClient({
space: process.env.CONTENTFUL_SPACE_ID as string,
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN as string
});
export default ContentfulClient
@delasign
delasign / next.config.mjs
Created April 18, 2024 17:52
Example nextConfig to work with contentful.
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [{
protocol: "https",
hostname: "images.ctfassets.net",
port: "",
pathname: "/**"
}]
}
@delasign
delasign / tsconfig.json
Created April 17, 2024 16:51
Sample TSConfig with Aliases for NextJSON
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
@delasign
delasign / clamping-value-limiting.ino
Created March 30, 2024 14:54
Sample Algorithm for clamping or limiting values.
float prevValue = 0.0; // Previous filtered value
float filteredValue;
float maxChange = 10.0; // Maximum allowed change in value between readings
void loop() {
float rawValue = analogRead(A0); // Read the raw analog input
// Calculate the change in value from the previous reading
float valueChange = abs(rawValue - prevValue);
@delasign
delasign / high-pass-filter.ino
Created March 30, 2024 14:44
Sample High Pass Filter in Arduino
float alpha = 0.1; // Filter constant, lower value means more filtering
float prevValue = 0.0; // Previous filtered value
float filteredValue;
void setup() {
Serial.begin(9600);
}
void loop() {
float rawValue = analogRead(A0); // Read the raw analog input
@delasign
delasign / low-pass-filter.ino
Created March 30, 2024 14:36
Sample Low Pass Filter Code
float alpha = 0.95; // Filter constant, higher value means more filtering
float prevValue = 0.0; // Previous filtered value
float filteredValue;
void setup() {
Serial.begin(9600);
}
void loop() {
float rawValue = analogRead(A0); // Read the raw analog input
@delasign
delasign / SampleNamespaceEnumInLoop.ino
Created March 28, 2024 18:54
Sample use of a enum that has a namespace within a loop.
void loop()
{
// Print the Enum
Serial.print("DifferentEnum Value 1: ");
Serial.println(EnumTwo::DifferentEnum::Value_1);
Serial.print("DifferentEnum Value 2: ");
Serial.println(EnumTwo::Value_2);
}
@delasign
delasign / SampleNamespaceEnum.ino
Created March 28, 2024 18:52
Sample Enum declared within a namespace
namespace EnumTwo {
enum DifferentEnum {
Value_1, // 0
Value_2 // 1
};
};