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
Satya
When two models are associated—for example, a Chat that has many Messages—you can create a message using @chat.messages.build instead of instantiating Message.new. This automatically sets the chat_id on the message, so it’s never niland the association is correctly maintained
#ActiveRecord #Rails
Published
Author
Syed Sibtain
System Analyst
What is Framing in WebSockets? Framing is how WebSocket data is split, structured, and transmitted over the wire. Framing is protocol-level, not app-level
WebSockets do not send raw strings or JSON directly. Instead, every message is wrapped inside WebSocket frames.
Each WebSocket frame contains: • FIN bit – is this the final frame? • Opcode – what type of data? • Payload length • Masking key (client → server) • Payload data Frame Types Data frames • Text frame → UTF-8 text (JSON, strings) • Binary frame → raw bytes (files, protobuf) Control frames • PING → check if connection is alive • PONG → response to ping • CLOSE → graceful shutdown #websockets #client #server
Published
Author
Swasthik K
Cron in GitHub Actions In GitHub Actions, you can schedule workflows using cron syntax inside the on.schedule field. It uses UTC time format. Example:
Code
on:schedule:# Runs at 5:30 AM and 5:30 PM UTC every day - cron:'30 5,17 * * *'# Runs every 15 minutes - cron:'*/15 * * * *'# Runs every Monday at 9:00 AM UTC - cron:'0 9 * * 1'
Syntax Highlighting & Language Detection with Highlight.js
It's a lightweight JS library that automatically highlights and detects code syntax on web pages — no need for manual markup.
Installing Highlight.js
Code
pnpm add highlight.js
Detect Language & Highlight
Code
import hljs from'highlight.js';import'highlight.js/styles/atom-one-dark.css';constcode=`function sum(a, b) { return a + b; }`;const { value,language } =hljs.highlightAuto(code);console.log(language); // e.g. "javascript"console.log(value); // highlighted HTML
• You can pass value to your React component and render it inside a code element with the hljs class for styling. Highlight.js automatically detects the language and highlights it — perfect when your app handles multiple code types dynamically.
#JavaScript #Frontend #HighlightJS
Published
Author
Vaibhav Yadav
Senior System Analyst
Clean up merged Git branches easily
You can quickly delete all local branches that have already been merged into your current branch (like master or main) using a single command:
This command lists all merged branches, filters out the current and main branches, and deletes the rest safely. Perfect for keeping your local repo tidy after merging multiple feature branches.
#git #github #vcs
Published
Author
Puneeth kumar
System Analyst
Understanding the Difference Between Regular Imports and .forRoot() in NestJS
In NestJS, modules can be imported in two main ways — but they behave differently:
1 Regular Imports • Example imports: [ProjectsModule, UserModule] • These are simple — they bring in the module’s exports (like services or guards). • They don’t need any setup or configuration. 2.1 forRoot()Imports • Example imports: [SlackModule.forRoot(dbClient) • These are special. They let a module set itself up with configuration or dependencies (like a DB client, API key, etc.). • They create a global instance that’s initialized once across the app. 2.2 forRootAsync() • Used when setup depends on async config — like environment variables. • Example :
Conclusion • Regular imports are sufficient when we just need access to a module’s services or exports. • forRoot() is useful when a module requires initial configuration or dependencies. • forRootAsync() is ideal when configuration depends on asynchronous operations, such as reading environment variables or fetching secrets. #NestJS #import_module
Published
Author
Syed Sibtain
System Analyst
getBoundingClientRect() A crucial DOM method that gives us an element's position and size relative to the viewport, not the document.
Example:
Code
constrect=container.getBoundingClientRect();
What getBoundingClientRect() returns?
Code
{top:100,// Distance from viewport top to element topleft:200,// Distance from viewport left to element leftright:400,// Distance from viewport left to element rightbottom:300,// Distance from viewport top to element bottomwidth:200,// Element widthheight:200,// Element heightx:200,// Same as left (for compatibility)y:100 // Same as top (for compatibility)}
Real Usage Example: Image Comparison Slider:
Code
// User drags the slider to compare two imageshandleDrag(event) {constcontainer=this.getContainer(); // The image containerconstrect=container.getBoundingClientRect();// Convert global mouse position to slider positionconstx=event.clientX -rect.left; // Mouse X relative to containerconstpercentage=this.calculatePercentage(x,rect.width);// Update slider position (0-100%)this.sliderPosition = percentage;this.updateSliderPosition(percentage);}
Step-by-Step Breakdown: 1. User drags mouse → event.clientX = 350 (global position) 2. Get container bounds → rect.left = 200 (container starts at 200px from viewport left) 3. Calculate relative position → 350 - 200 = 150px (mouse is 150px from container's left edge) 4. Convert to percentage → 150 / 400 = 37.5% (150px out of 400px container width) 5. Update slider → Move slider to 37.5% position getBoundingClientRect() is the bridge between global coordinates and element-relative coordinates.
#CCT1JMA0Z #stimulus
Published
Author
Syed Sibtain
System Analyst
When we rewrite git history (like squashing commits, interactive rebase), our local branch diverges from the remote branch. A regular git push will be rejected because the histories don't match. The first option is git push --force, which overwrites the remote branch with our local version.
The Usual Approach: git push --force
Code
# DANGEROUS- can overwrite other people's work# We do it everyday thoughgit push --force origin <feature-branch>
The Safer Alternative: git push --force-with-lease
Code
# SAFER- includes safety checksgit push --force-with-lease origin feature-branch
How --force-with-lease works: • Checks if the remote branch has moved since we last fetched it. • Only overwrites if the remote is exactly where we expect it to be. • Fails safely if someone else has pushed commits we don't have locally. • Prevents accidental overwrites of other people's work. PS: Might sound simple, but helps a lot when working with bigger teams.
#git #github
Published
Author
Nived Hari
System Analyst
If a port (say 3000) is already in use, you can check what’s running on it with:
Code
lsof -i :3000
Here, lsof stands for “List Open Files” — and in Unix/Linux, everything is a file, including network sockets.
So this command lists all processes that have files (or ports) open. Example output:
Now you can see the PID (Process ID) of the program using the port.
To stop it, run:
Code
kill 1234
The kill command sends a signal to a process — by default, it’s SIGTERM (Signal Terminate), which politely asks the process to shut down. If the process refuses to die, you can forcefully stop it with:
Code
kill -91234
Here, -9 represents the SIGKILL (Signal Kill) — which immediately ends the process without cleanup.
#unix
Published
Author
Mohammad hussain
System Analyst
The JavaScript console isn’t just console.log. It provides specialized methods for different scenarios: • console.error() → logs errors in red. • console.warn() → highlights warnings. • console.table() → formats arrays or objects as tables. • console.group() / console.groupEnd() → groups related logs for better organization. 💡 Using these methods makes debugging clearer and more structured than relying only on console.log. #Javascript
Showing 1 to 5 of 82 results
Ready to Build Something Amazing?
Codemancers can bring your vision to life and help you achieve your goals