menu

Search By Label

Yesterday I implemented gzip request support in a project and noticed there are no gems for that. There's `Rack::Deflater` but that's for responses, not requests. Apparently, incoming gzipped payloads are uncommon. 🤷‍♀

Maybe an opportunity to write a new gem? 🤔

y - stage this hunk

n - do not stage this hunk

q - quit; do not stage this hunk or any of the remaining ones

a - stage this hunk and all later hunks in the file

d - do not stage this hunk or any of the later hunks in the file

g - select a hunk to go to

/ - search for a hunk matching the given regex

j - leave this hunk undecided, see next undecided hunk

J - leave this hunk undecided, see next hunk

k - leave this hunk undecided, see previous undecided hunk

K - leave this hunk undecided, see previous hunk

s - split the current hunk into smaller hunks

e - manually edit the current hunk

? - print help

By default, Rails ships with three environments: "development," "test," and "production." To navigate between each environment, you can use the following command: 
 
 
bin/rails db:environment:set RAILS_ENV="YOUR_ENVIRONMENT" 
In Ruby, the .empty? method is used to check whether a data structure, such as a string, array, or hash, is empty. It returns true if the object it is called on contains no elements or characters, and false otherwise. 

Example:

# Strings 
empty_string = "" 
non_empty_string = "Hello, world!"empty_string.empty? # => true 
non_empty_string.empty? # => false# Arrays 
empty_array = [] 
non_empty_array = [1, 2, 3]empty_array.empty? # => true 
non_empty_array.empty? # => false# Hashes 
empty_hash = {} 
non_empty_hash = { name: "John", age: 30 }empty_hash.empty? # => true 
non_empty_hash.empty? # => false

 In PostgreSQL, the AVG function is used to calculate the average (arithmetic mean) of a set of numeric values within a specified column of a table. It's a convenient way to find the average value of a dataset in a SQL query. 

Syntax:

AVG(column_name) 
In PostgreSQL, the ROUND function is used to round a numeric value to a specified number of decimal places. It is a very useful function when you need to control the precision of numeric values in your database queries or calculations. 

Syntax:

ROUND(numeric_expression, number_of_decimal_places) 
Is a JavaScript method used for displaying an interactive list of the properties of a specified JavaScript object. It is particularly useful for examining the structure and contents of complex objects, such as DOM elements or custom JavaScript objects. 

Here's how `console.dir()` works with an example:

const person = { 
 firstName: "John", 
 lastName: "Doe", 
 age: 30, 
 address: { 
 street: "123 Main St", 
 city: "Anytown", 
 state: "CA", 
 zip: "12345", 
 }, 
};console.dir(person);/* output: 
Object 
 age: 30 
 address: Object 
 city: "Anytown" 
 state: "CA" 
 street: "123 Main St" 
 zip: "12345" 
 firstName: "John" 
 lastName: "Doe" 
*/ 

If you are using the devise gem the initial redirection will be to '/' even though you have another enable route '/welcome'.
So the solution can be achieved with this: 

  • app/controllers/application_controller.rb:

def after_sign_in_path_for(resource) 
 welcome_path 
end 
The PostgreSQL ANY operator compares a value to a set of values returned by a subquery. 
 
The following illustrates the syntax of the ANY operator.

expresion operator ANY(subquery) 
 
Examples of use:

SELECT 3 = ANY (ARRAY[1, 2, 3, 4]); -- Returns TRUE 
SELECT 42 = ANY (SELECT column FROM some_table); -- Returns TRUE if 42 exists in the column 
SELECT 'apple' = ANY (VALUES ('banana'), ('apple'), ('cherry')); -- Returns TRUE

 In PostgreSQL, the COALESCE function is used to return the first non-null expression in a list of expressions. It is a very useful function for handling cases where you want to obtain the first non-null value from a set of possible values.
 
Example:

SELECT COALESCE(null, 42, 'Hello'); -- Returns 42 
The Heroku CLI offers numerous benefits, including the ability to directly check how many apps are in your account using this command:
heroku apps

If you want to verify the most critical information about a specific app, you can use this command: 
heroku apps:info --app example

FYI is important that you log login before.

In PostgreSQL, the REPLACE() function is used to replace all occurrences of a specified substring within a given string with another substring. This function is useful for modifying or cleaning up string data in SQL queries.

Example:
REPLACE(original_string, search_string, replacement_string) 
or 
SELECT REPLACE('Hello, World!', 'World', 'Universe'); -- Returns 'Hello, Universe!' 
In PostgreSQL, the CEIL() function, or CEILING() function, is used to round a numeric value up to the nearest integer that is greater than or equal to the original value. It effectively rounds up the number to the next higher integer. 

Example:

SELECT CEIL(5.2); -- Returns 6 
SELECT CEIL(-3.8); -- Returns -3 
SELECT CEIL(10); -- Returns 10 (no change as it's already an integer)

In PostgreSQL, the FLOOR() function is used to round a numeric value down to the nearest integer that is less than or equal to the original value. It effectively truncates the decimal part of the number, leaving only the integer part.

Example:

SELECT FLOOR(5.7); -- Returns 5 
SELECT FLOOR(-3.2); -- Returns -4 
SELECT FLOOR(10); -- Returns 10 (no change as it's already an integer)
In PostgreSQL, you can use the CASE expression with the WHEN, THEN, and END keywords within a SELECT statement to perform conditional logic and return different values based on specific conditions. The CASE expression allows you to create conditional branching within your SQL queries. 

Example:
 
Suppose you have a table "employees" with a column salary, and you want to categorize employees into salary ranges

SELECT 
 employee_name, 
 salary, 
 CASE 
 WHEN salary < 30000 THEN 'Low Income' 
 WHEN salary >= 30000 AND salary < 60000 THEN 'Medium Income' 
 WHEN salary >= 60000 THEN 'High Income' 
 ELSE 'Unknown' 
 END AS income_category 
FROM 
 employees;