Fueling Curiosity, One Insight at a Time
At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.
Jun 1, 2024
Recently I came across an interesting use case of combining CSS variables with environment variables. The challenge was to change a CSS property, particularly a color, based on an environment variable. Since CSS doesn't support environment variables directly, here's the approach I took:
The global css file:
Then, in our React application:
#css #cssvariables #react
The global css file:
:root {
/* ----- fallback value ----- */
--primary-color: #3498db;
}
h1 {
color: var(--primary-color);
}
Then, in our React application:
const App = () => {
const primaryColor = process.env.NAME === 'a' ? '#fff' : '#000';
return (
<div style={{ '--primary-color': primaryColor }}>
<h1>Hello, World!</h1>
</div>
);
};
#css #cssvariables #react
Vaibhav Yadav
Senior System Analyst
May 31, 2024
Using
Choice input in Github actions can be used to provide a predefined list of options for workflow dispatch events. This makes it easier for users to select from a set of valid options when triggering workflows manually.
Example:
#githubactions #devops #automation #dropdown
choice
Input in GitHub ActionsChoice input in Github actions can be used to provide a predefined list of options for workflow dispatch events. This makes it easier for users to select from a set of valid options when triggering workflows manually.
Example:
name: Example Workflow
on:
workflow_dispatch:
inputs:
environment:
description: 'Select the environment'
required: true
default: 'sandbox'
type: choice
options:
- sandbox
- uat
- production
jobs:
example_job:
runs-on: ubuntu-latest
steps:
- name: Display Inputs
run: |
echo "Environment: ${{ github.event.inputs.environment }}"
#githubactions #devops #automation #dropdown
Vaibhav Yadav
Senior System Analyst
May 29, 2024
To generate an Entity-Relationship Diagram (ERD) using Prisma-erd-generator, follow these steps :
• Install the following package
• Add this to your
• Run the generator
#javascript #erd
• Install the following package
npm i -D prisma-erd-generator @mermaid-js/mermaid-cli
# or
yarn add -D prisma-erd-generator @mermaid-js/mermaid-cli
• Add this to your
schema.prisma
generator erd {
provider = "prisma-erd-generator"
}
• Run the generator
npx prisma generate
#javascript #erd
Adithya Hebbar
System Analyst
May 27, 2024
To use Client Components, states,
#javascript #nextjs
useState
, useEffect
, onClick
, and other client-side features, add "use client"
at the top of your file. This ensures the component runs on the client side.#javascript #nextjs
Adithya Hebbar
System Analyst
May 27, 2024
Key difference between App router and Page router :
App Router:
• File-based routing: Uses nested folders to define routes.
• Components: Server Components by default.
• Data fetching: Uses
• Layouts: Can be nested and dynamic.
• Dynamic routes: Supported, but syntax differs.
• Client-side navigation: Supported with
• Priority: Takes precedence over Page Router.
Page Router:
• File-based routing: Files directly represent routes.
• Components: Client Components by default.
• Data fetching: Uses
• Layouts: Static.
• Dynamic routes: Supported.
• Client-side navigation: Supported with
• Priority: Fallback if no matching route in App Router.
#javascript #nextjs
App Router:
• File-based routing: Uses nested folders to define routes.
• Components: Server Components by default.
• Data fetching: Uses
fetch
function.• Layouts: Can be nested and dynamic.
• Dynamic routes: Supported, but syntax differs.
• Client-side navigation: Supported with
router.push
.• Priority: Takes precedence over Page Router.
Page Router:
• File-based routing: Files directly represent routes.
• Components: Client Components by default.
• Data fetching: Uses
getServerSideProps
, getStaticProps
, getInitialProps
.• Layouts: Static.
• Dynamic routes: Supported.
• Client-side navigation: Supported with
Link
component.• Priority: Fallback if no matching route in App Router.
#javascript #nextjs
Adithya Hebbar
System Analyst
May 24, 2024
How to schedule tasks using cron expressions in GitHub Actions:
By defining a cron schedule in the workflow YAML file, we can automate the execution of tasks at specific intervals.
For instance, setting
Monitoring workflow runs in the "Actions" tab of the GitHub repository allows to verify that the scheduled tasks are executing as intended.
#cronjobs #workflowautomation
By defining a cron schedule in the workflow YAML file, we can automate the execution of tasks at specific intervals.
For instance, setting
*/5 * * * *
in the cron expression triggers the workflow every 5 minutes.Monitoring workflow runs in the "Actions" tab of the GitHub repository allows to verify that the scheduled tasks are executing as intended.
#cronjobs #workflowautomation
soniya.rayabagi
May 24, 2024
When terraform state file is locked and you are unable to acquire a state lock, you can use
#terrafrom
terraform force-unlock <LOCK_ID>
to forcefully remove the lock.#terrafrom
Mahesh Bhosle
DevOps Engineer
May 23, 2024
Use
#git #gitReset #github
git reset --mixed HEAD~1
command to undo your last commit without losing the changes made in your last commit.#git #gitReset #github
Vaibhav Yadav
Senior System Analyst
May 23, 2024
In TypeScript interfaces,
#javascript #typescript
?:
denotes optional properties. Here's an example:
interface User {
name: string;
age?: number; // Optional
}
const user1: User = { name: "Joe Mama" }; // Age is optional
const user2: User = { name: "Tony", age: 30 };
console.log(user1); // Output: { name: "Joe Mama" }
console.log(user2); // Output: { name: "Tony", age: 30 }
#javascript #typescript
Adithya Hebbar
System Analyst
May 23, 2024
Utility Types:
TypeScript's Utility Types simplify complex type manipulations. For instance,
#javascript #typescript
TypeScript's Utility Types simplify complex type manipulations. For instance,
Partial<T>
makes all properties of type T optional
interface User {
id: number;
name: string;
email: string;
}
function displayUser(user: Partial<User>) {
console.log(user);
}
displayuser({ name: "Joe Mama" }); // Partial<T> will make the properties optional hence this is valid
#javascript #typescript
Adithya Hebbar
System Analyst
Showing 17 to 19 of 77 results
Ready to Build Something Amazing?
Codemancers can bring your vision to life and help you achieve your goals
- Address
2nd Floor, Zee Plaza,
No. 1678, 27th Main Rd,
Sector 2, HSR Layout,
Bengaluru, Karnataka 560102 - Contact
hello@codemancers.com
+91-9731601276