scope – Code to Show Groovy is a Statically Scoped Language

I want to double check that I understand this code correctly as it relates to Groovy and static scoping.

Because int b = 5 is declared outside of the int foo( ) method, x.foo( ) will return 10.

Since int bar( ) returns int foo( ), x.bar( ) will return 10.

If on the other hand, Groovy were dynamically scoped, x.bar( ) would output 7 because b is not defined in foo( ).

As a result, the compiler would look to the value of b as it is defined in bar( ) and return 7.

The part I’m not certain of is whether x.foo( ) would also return 7, or would it still return 10 under dynamic scoping rules?

I think I understand this, I just want to make sure my explanation is correct.

Any input and/or constructive criticism is welcomed and appreciated.

Thanks!

class ScopeExample {
    int b = 5
    int foo() {
        int a = b + 5
        a
    }
    int bar() {
        int b = 2
        foo()
    }
    static void main(String ... args) {
        def x = new ScopeExample()
        println x.foo() //returns 10
        println x.bar() //returns 10
    }
}

mysql – Why my code only return 1 row? Leetcode#626

You are using an agregate function which causes the result to collapse to single row.
Possible solution:

SELECT 
(CASE WHEN mod(s.id,2)=0 THEN s.id-1
WHEN mod(s.id,2)=1 AND s.id != maxid.maxid THEN s.id+1
END) AS id,
s.student
FROM seat s
join (select max(s.id) as maxId from seat) as maxId on 1=1
ORDER BY id

You are using it in the SELECT, not CONDITIONAL (WHERE).
Now, the question you ask is a good one and i would have to refresh my knowledge of inner workings of SQL.

I think its because the moment it hits MAX, its collapses the result set, as it doesnt “see” a need to return all rows.

Simply said, the query processor doesnt care if its a condition in case statement or value to be returned. It’s there and thats that.

Aggregation function without group by is a mysql thing, and not SQL standard, so the behaviour is specific to MySQL.

applescript – My Apple Script Editor code doesn’t work gives “Syntax Error Expected end of line but found identifier.”

The problem is Evernote is not AppleScript scriptable.

When trying to add Evernote to the Library in Script Editor, in order to review its AppleScript dictionary, it errs with: Add Item Unable to add the item because it is not scriptable.

Additionally, when running the following command in Script Editor:

tell application "System Events" to ¬
    get has scripting terminology of application process "Evernote"

Its result is: false

data structures – Reverse An Array whats wrong with this type of code?

data structures – Reverse An Array whats wrong with this type of code? – Computer Science Stack Exchange

forms – PHP Code Not Generating Results

I wanted to create a calculator on my WordPress website.

But, my code is not generating results on the page after the form Submission.

Please help,
Thank you

MY CODE:

<form method="post" >
<label for="fname">Value</label>
<input id="value" name="inp1" type="number" value="" />
<label for="lname">Result</label>
<input type="submit" name="button1" value="Calculate" />

<?php

if(isset($_POST('inp1')))
        
    {
            $x=$_POST('inp1');
            
            function fact($x)
                {   
                                $fact=1;
                                for ($i=$x; $i>0; $i--)
                                    {
                                    $fact=$fact*($x);
                                    $x=$x-1;
                                    }
                                echo "Factorial of the number is $fact";

                }
        fact($x);
        
        
    }
        
        
    else 
            {echo "Enter the number";}
    
    
?>

mysql – Could anyone explain this code to me?Leetcode #180

select distinct Num as ConsecutiveNums
from (
  select Num, 
    case 
      when @prev = Num then @count := @count + 1
      when (@prev := Num) is not null then @count := 1
    end as CNT
  from Logs, (select @prev := null,@count := null) as t
) as temp
where temp.CNT >= 3

I found this in
https://leetcode-cn.com/problems/consecutive-numbers/comments/

It is really difficult to understand, especially this sentence

(select @prev := null,@count := null) as t

Why can variable declaration be put there?

javascript – How to divide the following code correctly into functions? Calculator /JS

javascript – How to divide the following code correctly into functions? Calculator /JS – Code Review Stack Exchange

random – This code is a non-static C# class for rolling a number of dice

Fellow human beings, today I present to you my dice rolling script! Behold, in my amateurish attempt at some raw C# code. Perhaps this will remain here regardless of the dozens of other dice rolling scripts out there.

Contains a ‘for’ loop, a ‘switch’, and a method that returns a value.

I have indeed read through other, similar iterations of this class, and I have found them to be lacking in what I might learn from, usually due to over-complication for my tiny brain, or because it invoked the use of libraries I have yet to hear of.

I did my best to make it easy to read for whichever intrigued person stumbles upon this. I deeply respect and appreciate any who may take the time to offer any criticism on my code. What did I do right? What did I do wrong? I don’t have anyone or anywhere else to share it with.

using System;

namespace C_
{
    class RollDice : Program
    {


        //Variables

        int numOfDice;
        int numOfSides;

        int maxDice = 100;
        int minDice = 1;
        int maxSides = 100;
        int minSides = 1;
        int totalRolled;

        //Start method for number of Dice to throw - take the player input in InputMethod() which returns an int. If returning 0, then restart. Clamp the value between min/max. Continue to next function.

        public void GetDice()
        {
            Console.WriteLine("Welcome to Roll Dice!");
            Console.WriteLine("How many dice do you want to throw?");
            numOfDice = InputMethod();
            if(numOfDice == 0)
            {
                GetDice();
            }
            if (numOfDice > maxDice || numOfDice < minDice)
            {
                numOfDice = Math.Clamp(numOfDice, minDice, maxDice);
                Console.WriteLine($"Number of Dice set to {numOfDice}");
            }

            GetSides();
        }

        // Get the sides of each dice by using a similar process. Roll() for each dice, then sum the totals in RollTotal().

        public void GetSides()
        {
            Console.WriteLine("How many sides does each dice have?");
            numOfSides = InputMethod();
            if(numOfSides == 0)
            {
                GetSides();
            }
            if (numOfSides > maxSides || numOfSides < minSides)
            {
                numOfSides = Math.Clamp(numOfSides, minSides, maxSides);
                Console.WriteLine($"Number of Sides set to {numOfSides}");
            }

            for (int x = 1; x <= numOfDice; x++)
            {
                Roll();
            }

            RollTotal();
        }


        // Create a new Random() instance for the number of sides and add it to the totalRolled variable.

         public void Roll()
        {
            Console.WriteLine(".....");
            Console.WriteLine("Rolling");
            Random r = new Random();
            var result = r.Next(1, numOfSides + 1);
            Console.WriteLine($"You rolled {result}");
            totalRolled += result;
        }
        
        // Output the total and prompt to roll again or quit. Reset the total..

        public void RollTotal()
        {
            Console.WriteLine($"Total sum rolled is {totalRolled}");
            Console.WriteLine(" ");
            Console.WriteLine("Enter 1 to re-roll or 2 to quit.");
            var answer = InputMethod();

            switch (answer)
            {
                case 0:
                RollTotal();
                break; 
            
                case 1:
                totalRolled = 0;
                GetDice();
                break;           
            
                case 2:
                totalRolled = 0;
                Environment.Exit(0);
                break;
            
                default:
                Environment.Exit(0);
                break;
            }
        }

        //Convert the input to an integer if valid and return the value. Else return 0.

        public int InputMethod()
        {
            var input = Console.ReadLine();
            if(!Int32.TryParse(input, out int convertedStringToInt))

            {
                Console.WriteLine("You need to enter a valid number!");
                return 0;
            }
            
            else 
            
            {
                return Convert.ToInt32(input);
            }

        }

    }
}

entities – Enable Layout Builder via code

I figured it out. You can enable Layout Builder by running the following code in a custom module:

$entity_type = 'node';
$content_type = 'article';
$view_type = 'default';

Drupallayout_builderEntityLayoutBuilderEntityViewDisplay::load("{$entity_type}.{$content_type}.{$view_type}")
  ->enableLayoutBuilder()
  ->setOverridable()
  ->save();

Hopefully this helps someone else. Having to do it via the UI is painful if you have a lot of content types. I’m actually surprised this isn’t a Drush command yet. Oh well.

Source: https://www.drupal.org/project/drupal/issues/3158916

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123