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.
Published
Author
Giritharan
System Analyst
Difference between any and unkown type in ts any: - The any type is a dynamic type, variables of type any can hold values of any data type, and TypeScript type checking is effectively turned off for them. - While any provides flexibility, it bypasses TypeScript's type checking entirely, which can lead to loss of type safety and potentially introduce bugs.
unknown: - The unknown type is a type-safe counterpart of any. It represents values of an unknown type. - Variables of type unknown can hold values of any type, but you cannot perform operations on them without first narrowing their type or asserting a more specific type.
Both any and unknown provide flexibility in handling values of unknown types, any completely disables type checking, while unknown enforces type safety by requiring you to explicitly narrow the type before performing operations on the value. It's generally recommended to prefer unknown over any when dealing with values of unknown types, as it helps maintain type safety in your TypeScript code.
#typescipt #javascipt
Published
Author
Giritharan
System Analyst
Classes And Functions in Ts. Classes: • Ts add helps to add type annotations for the classes.
Code
class User { constructor(public name: string, public age: number) {}}const ue = new User("github", 24);
• In Ts we don't need to initialize the properties and values inside the constructor if we are using access modifiers in the params. TypeScript will automatically initialise and assign values to class properties. Getters / Setters: • Classes can also have accessors • For the getter function we can able to set return value type but for setter function we can't. • setter functions are always expected props. • If a getter exists but no setter the property is automatically readonly • If the type of the setter parameter is not specified, it is inferred from the return type of the getter • For class props always try to use _ name convention for better maintainbility.
Code
class User { private _currentCount: number = 0; constructor(public name: string, public age: number) {} get fetch_name(): string { return this._name; } get fetchCount(): number { return this._currentCount; } set increaseCount(prop: number) { this._currentCount = prop + this._currentCount; this.logData(); } private logData(): void { console.log("Count Increased"); }}const fetchUser = new User("github", 24);
Abstract: • If classes or method are marked as abstract those are only for readonly purposes, means they can be only used as base class/sub class. • So that reason we can't create object on the class who are marked as abstract.
Code
abstract class Photo { constructor(public isCameraOn: boolean, public isFlashOn: boolean) {}}class Phone extends Photo {}const ph = new Phone(true, true);
#typescript #javascript
Published
Author
Giritharan
System Analyst
Typescript Learning
Variable definition: In Typescript we can specify the type string, number and boolean like
Code
let myName: string = "Vijay"; let age: number = 20; let isActive: boolean = false;
Moreover, if we don't specify the type typescript automatically detects the type by itself. But end of the defining the type was a good convention.
Function Definition: • For defining a function we can specify the function parameters type. Along with that we can able to set the default value. And also the return value.
Code
function sum(a: number, b: number = 2): number { return a + b; }
• For Arrow function:
Code
let sum = (a: number, b: number = 2): number => a + b;
Why don't use any : • Using any in TypeScript bypasses type checking but undermines TypeScript's static typing advantages. It's better to specify types explicitly for safer and more maintainable code. Array: With the help of the array, we can store number, string and boolean values separately and mixed.
Code
For String let users: string[] = ["a", "b", "c", "d]For Number let count: number[] = [1, 2, 3, 4]For booleanlet isActive: boolean[] = [true, false]For Mixed array let allDate: (string | number)[] = ["a", "b", "c", 1] Here Array contains only integers and strings
Void And Never: • void is a type that represents the absence of returning value. It's often used as the return type of function that doesn't return any value.
Code
function logError(msg: string): void { console.log(msg);}
• never represents the type of values that never occur:. It's typically used as the return type of functions that never return (i.e., always throw an error).
Code
function throwError(message: string): never { throw new Error(message);}
Object Type: • Object Types is used to pass the object as a parameter in the functions.
Code
function fetchData(pt: { x: number; y: number }) { return pt;}fetchData({ x: 3, y: 7 });
• If we want mentioned as an optional prop we can do that with the help of ? operator
Code
function fetchData(pt: { x: number; y?: number }) { return pt;}fetchData({ x: 3 });
Union Types: • It means type can be formed in two or more types, which means values can be anything from the union value.
Code
function sum(a: string | number) { return a; }Here you can see value can be anything string or number
Type Aliases • When can use both object type and union type but if we want use more than once we can use Type Aliases or Interface .
Code
type User = { name: string; age: number;}function displayUser(prop: User) { console.log(prop.name); console.log(prop.age);}displayUser({name: 'John', age: 22})
• Moreover on the type, we can able to do extend the values.
Code
type User = { name: string; age: number;}type Role = { role: string}type UserDeatils = User & Role & { address: string;}
• From above you can see that the userDetails inherits the user and role props without adding extra value. So that helps to keep DRY over time. Interface: • Interface is also similar in concept to type._ it's another way to name an object type.
interface User { name: string; age: number;}interface Role { role: string}interface userDetails extends User, Role { address: string;}
• The Only difference is type not available for re-opening for adding new properties. Readonly and Optional: • with the help of that, we can mark the value as read-only or optional.
Code
type User = { readonly id: string; name: string; phone: number; isActive: boolean; email?: string;};
• If we try to access id typescript will throw an exception. Also, email is not present on obj it does not make exceptions. Tuples: • Tuples are a data structure that allows you to store a fixed-size, ordered collection of elements. • Each element in a tuple may have a different data type. They are similar to arrays, but their size and types are fixed once they are defined.
Code
let myTuple: [string, number, boolean];myTuple = ['hello', 10, true];
• In typles we can modify elements of the tuple using array method with different types. It doesn't show any warning we always need to be aware of it. Enums: • Enums in TypeScript are usually _used to represent a determined number of options for a given value. • TypeScript provides both numeric and string-based enums • Numeric enums: ▪︎ By default enum value starts from 0 until we explicitly mention something:
Code
const enum UserType { ADMIN, USER, GUEST,}
• We can explicitly change the enum value
Code
const enum UserType { ADMIN = 10, USER, GUEST,}
• so from now value goes like 11, 12 in upstream • String enums: ◦ String enums are similar to numbers, But here we can specify string instead of numeric
• Heterogeneous enums: ◦ We can mix up string and numeric on enum. But After string, if numeric get started we need to mention the numeric value for the first one.
• Remaining value can typescript will handles. #typescript #javascript
Published
Author
Syed
In Rails, a partial is a reusable view template that allows you to encapsulate a portion of a view into a separate file. Partials are useful for organising and reusing code, especially when certain components or elements are repeated across multiple views within an application.
We can create a partial by creating a new file with a name that begins with an underscore (_). For example, _sidebar.html.erb or _header.html.erb.
And to render a partial within another view, use the render method with the name of the partial file (without the underscore) as an argument. For example, <%= render 'sidebar' %> will render the _sidebar.html.erb partial within the current view.
#rails
Published
Author
Syed
The rails routes command generates a comprehensive list of all routes defined in our Rails application, displaying the HTTP method, URL pattern, controller, and action associated with each route.
#rails
Published
Author
Satya
find your rails code smells by using a gem called flog . Flog finds the most tortured code in your codebase.
Code
gem install flog
then run
Code
flog app lib
it will print the flog score for the all files that has score more than or equal to 10. Generally we should make sure flog score should be less than 10. Note: The more the flog score , the more pain the code is in. #rails #code-smells #flog
Published
Author
Syed
In Ruby, instance variables are variables that belong to a specific instance of a class. They are prefixed with the @ symbol and are accessible within the instance methods of that class. Instance variables allow objects to maintain state and store information unique to each instance. Example:
Ruby
class Person def initialize(name, age) @name = name @age = age end def say_intro puts "Hello, my name is #{@name} and I am #{@age} years old" endend# Create a new instance of Personperson1 = Person.new("John", 18)# Call the say_intro methodperson1.say_intro
In this example, @name is an instance variable of the Person class, representing the name of each Person object created. The initialize method is a constructor that sets the value of @name when a new Person object is created. The say_intro method uses the instance variable @name to give the intro of the person with their name and age when called.
#ruby
Published
Author
Nisanth
The docker stats command is a powerful tool provided by Docker to monitor the resource usage of running containers. It provides a real-time stream of various metrics such as CPU usage, memory usage, network I/O, block I/O, and the number of processes (PIDs) running inside each container. This command is particularly useful for performance analysis and ensuring that containers are running within their resource limits. Example Explanation
Code
docker stats db370fc6b784CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDSdb370fc6b784 minikube 43.70% 1.243GiB / 2.148GiB 57.87% 35.4MB / 414MB
#devops #docker
Published
Author
Vaibhav Yadav
Senior System Analyst
We can check the default value for a given column using postgres query like this:
active_record_doctor performs variety of health checks to identify and rectify common database issues like missing foreign key constraints, missing NON NULL constraints, missing presence validations, incorrect presence validations on boolean columns and many more. Ref: https://github.com/gregnavis/active_record_doctor #rails #database
Published
Author
Codemancers
while integrating sentry with gitlab ip whitelisting needs to be done on gitlab server (self-hosted) #devops #sentry#gitlab
Published
Author
Soniya Rayabagi
The kubectl cordon NODE_NAME command is used in Kubernetes to mark a node as unschedulable, meaning no new pods will be scheduled onto that node. Existing pods on the node will continue to run unless explicitly terminated or moved. #devops #kubernetes
Published
Author
Nisanth
Debugging Kubernetes pod on helm helm upgrade unleash-app-toggle . --debug Adding --debug can provide more insight if the error persists, showing exactly what values are being passed to each template. #devops #kubernetes #helm
Published
Author
Nisanth
Avoid Using Double Quotes for Environment Variables When configuring the PostgreSQL user and database names in a Helm values.yaml file, I initially wrapped the values in double quotes. This led to a frustrating issue where I couldn’t connect to the database, receiving errors that the role did not exist. The double quotes were being interpreted literally, causing mismatches in authentication. Solution: I removed the double quotes around the environment variables in my Helm chart and reapplied the configuration. This corrected the problem, and I was then able to connect successfully to the database. #devops #postgres #env
Published
Author
Codemancers
create the redis cluster from existing backup we can use snapshot_name = <name of your backyp > #devops #redis #Terraform
Published
Author
Nisanth
To find the number of pods that exist in the “dev” environment (env), you can use the kubectl get pods --selector=env=dev #devops #kubernetes
Published
Author
Sachin
#nextJs #TypeScript useEffect is a hook that allows you to perform side effects in function components.
TypeScript
import React, { useState, useEffect } from 'react';function MyComponent() { const [count, setCount] = useState(0); // This effect will run only when the count state changes useEffect(() => { document.title = `You clicked ${count} times`; }, [count]); // Only re-runs when count changes return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}> Click me </button> </div> );}export default MyComponent;
In the above example: • We have a component MyComponent with a state variable count and a button to increment it. • Inside the component, we use the useEffect hook to update the document title with the current count after each render. • We pass [count] as the second argument to useEffect, which means the effect will only run when the count state changes. This is because we want to update the document title only when the count changes, not on every render.
Published
Author
Sachin
#nextJs #TypeScript Function Argument Deconstructing: Deconstructing function arguments can make your code cleaner and more readable.
Code
// Before deconstruction const BlogPost = (props) => { const { title, content, author } = props; // Render blog post using props return ( <div> <h1>{props.title}</h1> <p>{props.content}</p> <p>Written by: {props.author}</p> </div> );}; // After deconstruction const BlogPost = ({ title, content, author }) => { // Render blog post with title, content, and author return ( <div> <h1>{title}</h1> <p>{content}</p> <p>Written by: {author}</p> </div> );};
Published
Author
Soniya Rayabagi
CMD-SHIFT-L is a great productivity booster for VS Code. Lets you select all instances of the current selection and edit with multiple cursors. #VSCodetip #ProductivityHack
Published
Author
Mahesh Bhosle
DevOps Engineer
Terraform alias is a feature that allows you to manage resources across multiple regions more efficiently. It enables you to define different configurations for resources in various regions while using the same Terraform codebase. Here's a simple example to illustrate how to use Terraform alias for multiple regions:
Code
provider "aws" { alias = "us_east" region = "us-east-1"}provider "aws" { alias = "us_west" region = "us-west-1"}resource "aws_instance" "example" { provider = aws.us_east ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro"}resource "aws_instance" "example_west" { provider = aws.us_west ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro"}
In this example, we define two different AWS providers with aliases us_east and us_west, representing the US East and US West regions, respectively. Then, we create instances using these providers, specifying the region-specific provider for each instance. This allows Terraform to manage resources in different regions using the same configuration file. #terraform #iac
Showing page 13 of 42
Your competitors are already using AI. The question is how fast you want to unlock the value.
Don't know where to start?
AI is everywhere but it's unclear which investments will actually move your metrics and which are expensive experiments.
Your data isn't ready
Most AI projects fail at the data layer. Pipelines, quality, access all need work before LLMs can deliver value.
Internal teams are stretched
Your engineers are shipping product. They don't have capacity to also become AI specialists with production-grade experience.
Legacy systems block everything
Aging, undocumented codebases make AI integration slow, risky, and expensive. They need to move first.