google sheets – Formula to output the date for next Friday once it has passed 20:00 on Friday

Alsors, try this:

=ArrayFormula(IF((WEEKDAY(TODAY())=6)*(NOW()-TODAY()>=TIMEVALUE("8:00 PM")),TODAY()+7,FILTER(SEQUENCE(7,1,TODAY()),WEEKDAY(SEQUENCE(7,1,TODAY()))=6)))

HOW IT WORKS

The formula assumes Sunday is counted as weekday 1 and, therefore, that Friday is counted as 6.

The first part of the IF checks to see if two conditions are true: That today is Friday and that the current time is greater than or equal to 8:00 PM. If those are both TRUE, then the date is set to seven days in the future (i.e., next Friday).

If this small window of time is not the case, then the second half of the IF statement takes effect. A SEQUENCE is formed of seven dates starting with today’s date. FILTER filters in only those days whose weekday is 6 (i.e., Friday). And since there will only be one Friday within any seven-day SEQUENCE of dates, it will pull whatever the “next Friday” is.

(Note: If today is Friday before 8:00 PM, then the “next Friday” in the SEQUENCE is today, so it stays showing today’s date until after 8:00 PM.)

Interesting query string – referrer (google.com) being passed in query string

I have recently started seeing a query string in Google Analytics that I’m trying to figure out why it’s showing up. It looks like:

https://example.com/my_uri/?back=https://www.google.com/search?client=safari&as_qdr=all&as_occt=any&safe=active&as_q=the+users+search+query&channel=aplab&source=a-app1&hl=en

The web clients are always Safari, and the back parameter is always google.com.

It’s only showed up in the last couple of months. I’m guessing that it’s some kind of web application, but curious as to what it really is from.

ANNOUNCEMENT – Thank You BMFers! We PASSED 100,000 MEMBERS! | NewProxyLists

Dear BMFers, Thank you so much for all the support we just passed 100.000 registered members, thank you for joining previous contests, first $1225 contest, 2nd $1500 contest, prizes sent on Livestream, no b/s, video call via skype for full transparency. Proofs of payments from each forum…


www.beermoneyforum.com

apache 2.4 – Cookie not being passed to HTTP_COOKIE environment variable

A cookie that is clearly set in the browser, is not being passed to the back end by Apache in the HTTP_COOKIE environment variable. I can see other cookies that are being passed. I have logged cookies through Apache in the access logs with the "%{Cookie}i" directive and verified that Apache is able to see them. The database backend is somehow able to see it sometimes if I wait a minute and refresh the page. The cookies are not set to expire within a certain time. Not sure if it’s important but this server is behind a reverse proxy.

reverse proxy – NGINX/GemInABox – static links aren’t properly passed

NGINX location config:

location /geminabox/ {
  client_body_buffer_size    128K;
  client_max_body_size       16M;

  rewrite ^/geminabox/(.*) /$1 break;
  proxy_set_header Host $http_host/geminabox/;
  proxy_pass http://127.0.0.1:8205/;
}

I’m trying to run GemInABox behind nginx. The service itself works fine, however on the web display it doesn’t pass static files properly, showing blank html.
From the console, the mistake seems to be that instead of calling example.com/geminabox/master.css, it calls example.com/master.css.
Yet it shows properly if i call 127.0.0.1:8205 in my web browser.

NGINX’s error log:
(error) 5813#0: *272 open() "/usr/share/nginx/html/master.js" failed (2: No such file or directory), client: 123.123.123.10, server: 123.123.123.12, request: "GET /master.js HTTP/1.1", host: "123.123.123.12", referrer: "http://123.123.123.12/geminabox/"
(ips changed)

I’ve looked into some suggestions adding a trailing slash or adding more header options, but none of those worked so far. So i hope it’s something small and obvious that I’m just overlooking.

As requested my whole nginx block

user nobody;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user ($time_local) "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
   tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       (::):80;
        server_name  137.226.172.42;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

My location file sits in /default.d/

Argument 2 passed to DrupalConsoleCommandTestRunCommand::__construct() must be an instance of DrupalsimpletestTestDiscovery

I’m trying to install drupal console with Drupal 9.0.5, so I ran this command:

composer require drupal/console:~1.0

However when I try run the drupal command with any arguments I get this error:

root@6dc17ce2d4bf:/opt/drupal# drupal --version
TypeError: Argument 2 passed to DrupalConsoleCommandTestRunCommand::__construct() must be an instance of DrupalsimpletestTestDiscovery, null given in /opt/drupal/vendor/drupal/console/src/Command/Test/RunCommand.php on line 58 #0 (internal function): DrupalConsoleCommandTestRunCommand->__construct('/opt/drupal/web', NULL, Object(DrupalCoreExtensionModuleHandler), Object(DrupalCoreDatetimeDateFormatter))
#1 /opt/drupal/vendor/symfony/dependency-injection/ContainerBuilder.php(1144): ReflectionClass->newInstanceArgs(Array)
#2 /opt/drupal/vendor/symfony/dependency-injection/ContainerBuilder.php(618): SymfonyComponentDependencyInjectionContainerBuilder->createService(Object(SymfonyComponentDependencyInjectionDefinition), Array, true, 'console.test_ru...')
#3 /opt/drupal/vendor/symfony/dependency-injection/ContainerBuilder.php(558): SymfonyComponentDependencyInjectionContainerBuilder->doGet('console.test_ru...', 1)
#4 /opt/drupal/vendor/drupal/console-core/src/Application.php(468): SymfonyComponentDependencyInjectionContainerBuilder->get('console.test_ru...')
#5 /opt/drupal/vendor/drupal/console-core/src/Application.php(214): DrupalConsoleCoreApplication->registerCommands()
#6 /opt/drupal/vendor/drupal/console-core/src/Application.php(119): DrupalConsoleCoreApplication->loadCommands()
#7 /opt/drupal/vendor/drupal/console/src/Application.php(64): DrupalConsoleCoreApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#8 /opt/drupal/vendor/symfony/console/Application.php(147): DrupalConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#9 /opt/drupal/vendor/drupal/console/bin/drupal.php(89): SymfonyComponentConsoleApplication->run()
#10 /opt/drupal/vendor/drupal/console/bin/drupal(4): require('/opt/drupal/ven...')
#11 {main}
TypeError: Argument 2 passed to DrupalConsoleCommandTestRunCommand::__construct() must be an instance of DrupalsimpletestTestDiscovery, null given in DrupalConsoleCommandTestRunCommand->__construct() (line 58 of /opt/drupal/vendor/drupal/console/src/Command/Test/RunCommand.php).

I don’t really understand this error. Any ideas what might cause this?

worksheet function – In excel, how do I add X multiples Y years to a specific date once that date has passed?

You can use this formula:

=XLOOKUP(TODAY(),DATE(YEAR($A$2)+SEQUENCE(10,1,$B$2,$B$2),MONTH($A$2),DAY($A$2)),DATE(YEAR($A$2)+SEQUENCE(10,1,$B$2,$B$2),MONTH($A$2),DAY($A$2)),"",1,1)

There are two inputs here – the policy start date and the term.

enter image description here

The SEQUENCE creates a list of policy renewal dates. I have created 10, but you could put whatever integer you want in the first parameter of SEQUENCE if you need a longer lookup list. XLOOKUP then finds the item from the list that is the same or next largest from TODAY() and returns it in the yellow cell.

You don’t actually need the data formula and data shown in column D – it’s just there to illustrate the sequence of dates.

8 – Pretty-printing JSON as preformatted text in translatable string passed as argument to method?

LENGTHY PREAMBLE:

In a Service class, I’d like to display onscreen debug info for users with a specific permission.

In my_custom_module.permissions.yml:

'view debug info':
  title: 'View debug info'
  description: 'Allow user to view DataPartner API debugging messages.'
  restrict access: true

In src/Api/DataPartner.php:

<?php

namespace Drupalmy_custom_moduleApi;

/**
 * @file
 * Contains Drupalmy_custom_moduleApiDataPartner.
 */

use DrupalCoreSessionAccountInterface;
use DrupalCoreMessengerMessengerInterface;
use DrupalCoreStringTranslationStringTranslationTrait;

/**
 * Provides API integration methods.
 */
class DataPartner {

  use StringTranslationTrait;

  /**
   * Private function to determine whether displaying debug info is permitted.
   *
   * @return bool
   *   TRUE if debugging is permitted for current user in current environment.
   */
  private function hasDebugPermission() {
    return MY_CUSTOM_MODULE_DEBUG_FLAG && $this->account->hasPermission('view debug info');
  }

There’s a bit more to it.

I have left out the dependency injection stuff in *.services.yml and in the Service class, which I’m using to provide methods to deal with checking user account permission, writing Drupal messages to the screen, and other stuff. (I included just enough to show what services I’m injecting, and to show that I’m using the StringTranslationTrait in the Service class rather than injecting that dependency, in case that is relevant to my question.)

I have also defined the constant MY_CUSTOM_MODULE_DEBUG_FLAG to disable the debugging in the production environment and toggle it based on a checkbox in a ConfigForm, but that won’t have any effect on my actual question.

Anyway, now I can display the API debugging messages like this:

if ($this->hasDebugPermission()) {
  $this->messenger->addMessage($this->t('Step 2: $response = <br><pre>@value</pre>', (
    '@value' => print_r(json_encode($this->response_decode, JSON_PRETTY_PRINT), TRUE),
  )));
}

This is fine, as far as it goes, but I wanted better encapsulation. I tried this:

  /**
   * Private function to display debug info if permitted.
   *
   * @param string $message
   *   Translatable message string to be displayed, if permitted.
   * @param array $variables
   *   Values for substitution in translatable string.
   */
  private function displayDebugInfo(string $message, array $variables = ()) {
    if ($this->account->hasPermission('view debug info')) {
      $this->messenger->addMessage($this->t($message, $variables));
    }
  }

However, this violates Drupal coding standards because:

WARNING | Only string literals should be passed to t() where possible

There’s an interesting discussion of this here.

The linked issue queue mentions that you can mark the string for translation before passing it as an argument to your method, so I tried that:

  /**
   * Private function to display debug info if permitted.
   *
   * @param string $message
   *   Translatable message string to be displayed, if permitted.
   */
  private function displayDebugInfo(string $message, array $variables = ()) {
    if ($this->account->hasPermission('view debug info')) {
      $this->messenger->addMessage($message));
    }
  }

If I do that, I need to display the API debugging messages like this:

this->displayDebugInfo($this->t('Step 2: $response = <br><pre>@value</pre>', (
  '@value' => print_r(json_encode($this->response_decode, JSON_PRETTY_PRINT), TRUE),
)));

This lengthy preamble brings me to my question.

ACTUAL QUESTION:

Passing the translatable string to the method in this way causes the HTML markup to be printed to the screen, so that instead of seeing pretty-printed JSON as preformatted text, the user sees a brick of ugly text and markup.

When I examine the markup in the DOM inspector of the browser’s Dev Tools, it looks like regular markup, not escaped HTML entities like &lt;pre&gt;.

  • Why is the markup not being interpreted by the browser? (I’m assuming there is a security reason.)
  • If I want to have my cake (preformatted pretty-printed JSON in $this->messenger->addMessage()) and eat it too (with better object-oriented encapsulation), is there any way for me to get what I want?

java – Split amount into inputs passed

Use proper indentation, after a curly brace use a tab or 4 spaces.

Add a message with your exceptions. It’s a terrible practice to just throw a regular exception and no message. You’d have to look at the line numbers in the stack trace in order to know where the exception message came from. It’s better to have a user-friendly message describing the issue that occurred.

Do not mix ! with > or <. It’s confusing to read.

Try to use negative or positive validation. For example, be consistent either checking if the inputs are wrong, or always check that their right. In other words have your error messages all at the top or bottom.

OutputResponse Is not a good name. It’s meaningless. Assuming this is a class you made, consider changing the name. Also consider using an ArrayList rather than separate fields, that way you don’t need to refactor to include a 4+ separations.

public OutputResponse splitAmount(BigDecimal totalAmount, int divideInto) {
    if ((1 > divideInto || 3 < divideInto)) {
        throw new Exception("Divide into must be between 1-3");
    }
    
    if (totalAmount == null || totalAmount.compareTo(BigDecimal.ZERO <= 0) {
        throw new Exception("Total amount must be a number greater than 0!");
    }
    
    BigDecimal recurringAmounts = null;
    BigDecimal firstAmount = totalAmount;
    if (divideInto > 1) {
        recurringAmounts = totalAmount.divide(BigDecimal.valueOf(divideInto), 2, RoundingMode.FLOOR);
        firstAmount = totalAmount.subtract(recurringAmounts.multiply(new BigDecimal(divideInto - 1)));
    }

    OutputResponse outputResponse = OutputResponse.builder()
            .firstAmt(firstAmount)
            .secondPmtAmt(recurringAmounts)
            .build();

    if (divideInto > 2) {
        outputResponse.setThirdPmtAmt(recurringAmounts);
    }
}