giritharan
Mon Jul 01 2024
overscroll-behavior in CSS
The overscroll-behavior
CSS property controls what happens when you reach the boundary of a scrollable area. It's useful for managing scroll chaining and preventing unwanted browser behaviors like the "bounce" effect or "pull to refresh."
Usage
- Default (auto): Normal scroll behavior.
- Contain: Stops scroll chaining; keeps default behavior within the element.
- None: Prevents both scroll chaining and the default overflow behavior.
Examples Prevent underlying content from scrolling:
.scroll-container { height: 220px; overflow: auto; overscroll-behavior-y: contain; }
Disable overscroll effects:
html { margin: 0; overscroll-behavior: none; }
#css #alignment-issue #frontend
ashwanikumarjha
Tue Jun 25 2024
Beacon API
Reliable way to send asynchronous data to a server, especially during page unload events. The Beacon API lets us send small amounts of data asynchronously and non-blockingly to a server. Unlike traditional solution like fetch
, the Beacon API ensures that the data is sent before the page unloads and runs to completion. The browser ensures that the request is initiated before the page is completely unloaded. This includes scenarios where the user closes the tab, navigates to another page, or reloads the page. The primary goal is to deliver the data reliably. The browser ensures that the data transfer completes before the document is discarded.
window.addEventListener('beforeunload', () => {
const data = JSON.stringify({ userId: '12345' });
navigator.sendBeacon('/logout', data);
});
adithya.hebbar
Tue Jun 25 2024
In JavaScript, console.time
is a method that helps you measure the time it takes for a specific block of code to execute. It's like a stopwatch for your code.
// Start the timer
console.time('myTimer');
for (let i = 0; i < 1000000; i++) {
// Some code here
}
// Stop the timer
console.timeEnd('myTimer');
So, when you run this code, you'll see something like: "myTimer: 1.358ms"
#javascript
ashwanikumarjha
Tue Jun 25 2024
Performance API
Seems super useful for tracking web performance, it let us measure various performance metrics of web pages, like how long specific operations take.
- performance.now() ◦ Provides the current time in milliseconds with high precision, can be useful for measuring how long specific tasks take.
- PerformanceEntry
◦ Object representing a metric. It includes:
▪︎
navigation
: Information about page loads. ▪︎resource
: Data on loaded resources like scripts and images. ▪︎mark
: User-defined timestamps. ▪︎measure
: Duration between two marks. - PerformanceNavigationTiming
◦ Specific type of PerformanceEntry for page navigation metrics.
◦ Tells us if a page load is due to a navigation, reload, or history action.
◦ eg properties:
domComplete
,domContentLoadedEventEnd
,type
. Probable use Cases: • Can help us analyze how long different parts of the page load take. • Can help us check how long it takes to load each resource. • Can help us determine if a page is reloaded or newly navigated. #performance #browser
ashwanikumarjha
Thu Jun 20 2024
EJS, the templating engine for JavaScript, allows us to generate HTML markup with plain JavaScript.
By default, EJS escapes any HTML entities in the output to prevent issues such as cross-site scripting. This is done by replacing characters like <
, >
, &
, and "
with their respective HTML entity codes.
For example:
- `&` is replaced with `&`
- `<` is replaced with `<`
- `>` is replaced with `>`
- `"` or `'` (double or single quote) is replaced with `&quot;` or `&#39;` respectively.
Unescape HTML entities with <%- %>
If we want EJS to output our data without escaping HTML entities, replace <%= %>
with <%- %>
. This instructs EJS to render the data as unescaped.
giritharan
Thu Jun 20 2024
My Rails application is named xyz
. When I tried to create a scaffold with the same name as the application, it caused a below error.
The name 'Xyz' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative or use --skip-collision-check or --force to skip this check and run this generator again.
To fix this, I changed the module name in application.rb
to abc
. After making this change, everything worked. It's always best to avoid using the same name for both the model and the application.
#rails-naming-convention #rails
giritharan
Wed Jun 19 2024
After pushing my changes to the Fly, I noticed that my Application JS controller wasn't being found. The problem was due to an incorrect line in app/javascript/controllers/application.js
. It originally had:
import { application } from "./application";
To fix it, I changed it to:
import { application } from "controllers/application";
These changes ensured that the request was directed to the correct location, and the Stimulus JS controller started working.
#stimulus #assert-not-loading #rails
ayushsrivastava
Wed Jun 19 2024
Common procedure to monitor data in Devops Environment
First we need a source of metrics that can be Applications, Databases, Containers etc
After that we need Exporters
Exporters are components that collect and export metrics from various systems, applications, and services, making them available to monitoring tools
Then we need Datasource
Datasource aggregates, stores, and allows querying of the metrics collected from Exporters, making it the data source for visualization tools and alerting mechanisms.
Collected data is stored in Time Series database
A time series database (TSDB) is a special type of database designed to store and manage data that is recorded over time. Each piece of data has a timestamp, which helps keep track of when it was collected.
Then comes the visualisation part
We can use tools like Grafana that make use of the data that is stored in Time Series Database like prometheus to visualise data
#monitoring #devops
adithya.hebbar
Tue Jun 18 2024
util.inspect
use-case:
• Without util.inspect
const obj = {
name: "Adi",
age: 24,
details: { details1: { details2: { hobbies: "travelling" } } },
};
console.log(obj);
//Output: { name: 'Alice', age: 30, details: { details1: { details2: [Object] } } }
• With util.inspect
import util from "util";
const obj = {
name: "Adi",
age: 24,
details: { details1: { details2: { hobbies: "travelling" } } },
};
console.log(util.inspect(obj, { depth: null, colors: true }));
//Output: { name: 'Adi', age: 24, details: { details1: { details2: { hobbies: 'travelling' } } } }
console.log
doesn't show all details of complex objects, especially nested ones or hidden properties. util.inspect
gives a complete and customizable view for better debugging and understanding.
#javascript
adithya.hebbar
Tue Jun 18 2024
To kill a process running on a specific port in mac:
lsof -i :<port_number>
- Note the PID of the process from the output.
kill -9 <pid>
#killprocess
Showing 3 to 5 of 65 results