PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label limit. Show all posts
Showing posts with label limit. Show all posts

Monday, December 12, 2022

[FIXED] What is the maximum amount of columns in Google Sheets?

 December 12, 2022     formula, google-sheets, limit, multiple-columns, syntax     No comments   

Issue

Could you please say what is the maximum amount of columns in Google Sheets? I heard that maximum is the 256 columns but I was able to add more? Is it only limited by the sum of cells (400000)?


Solution

the maximum number of cells per spreadsheet is 2000000 so if you have a one column you could have 2M rows. for column the max is 18278 which is ZZZ and can be tested with COLUMN formula:

0



Answered By - player0
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, November 14, 2022

[FIXED] What is the largest possible decimal value in VBA?

 November 14, 2022     error-handling, excel, exception, limit, vba     No comments   

Issue

I've been trying to create something similar to a DEC_MAX constant in vba.


Issue is, it is a bit tricky, because there is no Decimaldata-type!
The closest you can get to a functioning decimal is the CDec() function which is defined:

Return the Decimal data value that is the result of Expression being Let-coerced to Decimal

So naturally, I thought that any potentially overfowing value would be co-erced to the maximum achievable Decimal. I tried inserting the max Decimal vb.net value from MSDN Documentation

This is however note true, as attempting to do so will result in an Overflow:

enter image description here

So how would one go about calculating the closest possible approximation of Decimal maximum here? I tried this "computer-bricking" ugly loop of a code:

Private Sub brick_my_Excel()
  On Error Resume Next
  x = 79228162514264337593543950335 'let's let it auto-coerce i guess
  Do 
     Debug.Print(x)
     x = x - 1
  Loop
End Sub

This however supresses the overflow altogether, printing the x in almost string-like fashion without paying much attention to the calculation.

So,

  1. How would one go about calculating it?
  2. What is the largest possible expression we can pass to the CDec() function?

Solution

The only way I can figure out how to do this is to completely bypass VBA and "build" the maximum value in memory. The DECIMAL structure is 16 bytes and is defined as:

typedef struct tagDEC {
  USHORT    wReserved;
  BYTE      scale;
  BYTE      sign;
  ULONG     Hi32;
  ULONGLONG Lo64;
} DECIMAL;

Since you can't explicitly declare a Decimal in VBA, CDec(0) will give you one to play around with that has the correct Variant type. The sign and scale are independent of the 12 byte value, so just setting all the bits in that area of memory will give you the max value (the max will have a scale of 0):

#If VBA7 Then
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias _
        "RtlMoveMemory" (Destination As LongPtr, Source As Any, _
        ByVal length As Long)
#Else
    Private Declare Sub CopyMemory Lib "kernel32" Alias _
        "RtlMoveMemory" (Destination As Long, Source As Any, _
        ByVal length As Long)
#End If

Private Const VT_DECIMAL As Integer = &HE
Private Const BIT_MASK As Long = &HFFFFFFFF
Private Const DATA_OFFSET = 4
Private Const SIZEOF_LONG = 4

Public Function MaxDecimal() As Variant
    'Get a decimal to work with.
    Dim dec As Variant
    dec = CDec(0)

    Dim vtype As Integer
    'First 2 bytes are the VARENUM.
    CopyMemory ByVal VarPtr(vtype), ByVal VarPtr(dec), LenB(vtype)

    'Make sure the VARENUM is a VT_DECIMAL.
    If vtype = VT_DECIMAL Then
        'Fill the top 12 bytes of it's data area with truthy bits
        CopyMemory ByVal VarPtr(dec) + DATA_OFFSET, BIT_MASK, SIZEOF_LONG
        CopyMemory ByVal VarPtr(dec) + DATA_OFFSET + SIZEOF_LONG, BIT_MASK, SIZEOF_LONG
        CopyMemory ByVal VarPtr(dec) + DATA_OFFSET + SIZEOF_LONG * 2, BIT_MASK, SIZEOF_LONG
    End If

    MaxDecimal = dec
End Function

Note that this is not obviously not going to get it into a Const for you, but it does get you the correct maximum value:

Public Sub Test()
    MsgBox MaxDecimal
End Sub

Maximum Decimal Value



Answered By - Comintern
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, October 18, 2022

[FIXED] How to get containter memory limit in Python?

 October 18, 2022     docker, get, limit, memory, python     No comments   

Issue

I'm trying to retrieve the real memory limit set to a Docker container within it using Python:

docker run --rm -it --memory="2g" python:3.8 python -c "import os; print((os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES'))/(1024.**3))"

but it returns all available memory from the host machine.

I know I could use Docker package for Python and bind-mount /var/run/docker.sock to get that info from inspecting container configuration, but I need to know if there is another way because I can't use that method.


Solution

Container's memory limit is controlled by linux cgroups, so you could fetch the value of /sys/fs/cgroup/memory/memory.limit_in_bytes in container to caculate the limit memory within container:

root@pie:~# docker run --rm -it --memory="2g" python:3.8 /bin/bash
root@e22c4275f26c:/# python3
Python 3.8.15 (default, Oct 14 2022, 00:19:58)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> limit_in_bytes=subprocess.check_output(["cat", "/sys/fs/cgroup/memory/memory.limit_in_bytes"]).decode("utf-8")
>>> print(int(limit_in_bytes)/(1024**3))
2.0
>>>


Answered By - atline
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, August 16, 2022

[FIXED] How to increase the ipython qtconsole scrollback buffer limit

 August 16, 2022     buffer, ipython, limit, output, qtconsole     No comments   

Issue

When I load ipython with any one of:

ipython qtconsole
ipython qtconsole --pylab
ipython qtconsole --pylab inline

The output buffer only holds the last 500 lines. To see this run:

for x in range(0, 501):
   ...:     print x

Is there a configuration option for this? I've tried adjusting --cache-size but this does not seem to make a difference.


Solution

Quickly:

ipython qtconsole --IPythonWidget.buffer_size=1000

Or you can set it permanently by adding:

c.IPythonWidget.buffer_size=1000

in your ipython config file.

For discovering this sort of thing, a helpful trick is:

ipython qtconsole --help-all | grep PATTERN

For instance, you already had 'buffer', so:

$> ipython qtconsole --help-all | grep -C 3 buffer
...
--IPythonWidget.buffer_size=<Integer>
    Default: 500
    The maximum number of lines of text before truncation. Specifying a non-
    positive number disables text truncation (not recommended).

If IPython used a different name than you expect and that first search turned up nothing, then you could use 500, since you knew what the value was that you wanted to change, which would also find the relevant config.



Answered By - minrk
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, August 7, 2022

[FIXED] How to set maximum amount of decimals in react

 August 07, 2022     decimal, limit, reactjs     No comments   

Issue

I created a calculator in react, but when I do some division where the result will be a repeating decimal, this result is exceeding the calculator display.

Example: 1 / 3 = 0.333333333333 Calculator

Could someone help me to make the result not pass the display?

I tried to use maxLength and toFixed methods, but neither worked

Here is my code:

export default function Calculator() {
  const [num, setNum] = useState(0);
  const [oldnum, setOldNum] = useState(0);
  const [operator, setOperator] = useState();
  const [waitingForNumber, setWaitingForNumber] = useState(false);
  const [shouldClearNumber, setShouldClearNumber] = useState(false);

  function inputNum(event) {
    const input = event.target.value;
    const number = (Number(num) + Number(input))
    if (number > 999999999 && !waitingForNumber) {
      return;
    }

    if (waitingForNumber || num === 0 || shouldClearNumber) {
      setNum(input);
    } else {
      setNum(num + input);
    }
    setWaitingForNumber(false);
    setShouldClearNumber(false);
  }
  function calcular() {
    if (operator === "/") {
      setNum(parseFloat(oldnum) / parseFloat(num));
    }
    if (operator === "X") {
      setNum(parseFloat(oldnum) * parseFloat(num));
    }
    if (operator === "-") {
      setNum(parseFloat(oldnum) - parseFloat(num));
    }
    if (operator === "+") {
      setNum(parseFloat(oldnum) + parseFloat(num));
    }
    setShouldClearNumber(true);
    console.log("calculou!!!!");
  }
}

Solution

The accepted answer isn't a good general solution, it doesn't limit the number of decimal points, it just cuts off characters that may or may not be after the decimal.

The correct answer is using toFixed, like Mel Carlo Iguis's answer. You could call toFixed everytime before setting state:

setNum(Number(newValue.toFixed(1))) // 1 for 1 decimal place, adjust as needed

Although that method loses information-- if you want to keep num high-precision for future calculations, you can instead just use toFixed during the actual render step. This is the pattern I'd recommend:

<div> {num.toFixed(1)} </div>


Answered By - Nathan
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, July 26, 2022

[FIXED] How do i limit characters echoed from database?

 July 26, 2022     character, dreamweaver, limit, mysql, php     No comments   

Issue

I've made a "news" section on my website, and I'm trying to make a little box on my template to the right which echos latest news (title, text and author). My problem is that I only wish to echo about 20 characters from "text" in the little box.

I'm using dreamweaver, and i'm horrible at php. Here's the code. It's the "tekst" field i wan't to limit to 20 characters.

<?php do { ?>
<h1><?php echo $row_posts['tittel']; ?></h1>
<p class="posttekst">&nbsp;<?php echo $row_posts['tekst']; ?></p>
<p><em><?php echo $row_posts['forfatter']; ?> <?php echo $row_posts['dato']; ?></em></p>
<hr />
<?php } while ($row_posts = mysql_fetch_assoc($posts)); ?>

It's in norwegian - tittel : title, tekst: text, forfatter: author, dato:date.

Thanks for any help.


Solution

PHP's substr() is what you're looking for: http://www.php.net/manual/en/function.substr.php

<?php echo substr($row_posts['tekst'], 0, 20); ?>



Answered By - davey
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, July 17, 2022

[FIXED] How to use suggestion or pop up to suggest while entering text input in kivy?

 July 17, 2022     kivy, limit, popup, textinput, warnings     No comments   

Issue

Is it possible to use small pop up message or any suggestion to user that while entering please enter numbers between 40-70. I have designed a sample code in which I want user to enter only values between some range. So can someone please help me out so that I can know whether we can do it or not. Thank You.


Solution

You can use MDTextField widget from the material design inspired kivy library kivy-md. This widget has the attribute helper_text, which you can set to “Please enter numbers between 0 and 70”. You can additionally set an input_filter: “int” to only allow integer values for this widget. Remember that you still haveto validate the values to be in the desired interval. Below is an example of it.

MDTextField:
        hint_text: "Helper text on focus"
        helper_text: "This will disappear when you click off"
        helper_text_mode: "on_focus"
        input_filter: “int”


Answered By - MrYouMath
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, July 13, 2022

[FIXED] How to limit height of JSF <h:messages> component

 July 13, 2022     facescontext, jsf, limit, messages, numbers     No comments   

Issue

I have the wrapped into my own faces component. Right now we found that when adding several messages the are of the expands moving the actual page components to the very far bottom of the page.

It's not viable to change the 300 pages we have on this system. Tried to find way to limit the height of the <h:messages> by CSS with no success.

The bright side is that when adding messsages to the current faces context is required that caller uses a method from the super class. I was able to limit the messages, but my control variables are not reseting when the page is reloaded.

My question, is there any other way to limit the messages from faces context?

(using javaEE5, JSF 1.1, tomcat5)


Solution

Here is what I did to workaround the problem. As I said on my original post the component I use is wrapped. I overwrote the encodeBegin and encodeEnd to wrap the original h:messages with a div element:

import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlMessages;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.el.ValueBinding;

public class UIMessages extends HtmlMessages implements LayoutComponent {

  public void encodeBegin(FacesContext context) throws IOException{
    ResponseWriter writer = context.getResponseWriter();
    layout.startRow(writer);
    layout.startData(writer);
    writer.startElement("div", this);
    writer.writeAttribute("style", "overflow:auto; border:0px solid; max-height:100px;", null);
    super.encodeBegin(context);
  }

  public void encodeEnd(FacesContext context) throws IOException{
      ResponseWriter writer = context.getResponseWriter();
      super.encodeEnd(context);
      writer.endElement("div");
      layout.endData(writer);
      layout.endRow(writer);
  }
}


Answered By - ChRoNoN
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, July 8, 2022

[FIXED] How can I set the limit number of the posts of a specify category into a page of that category?

 July 08, 2022     categories, limit, posts, wordpress     No comments   

Issue

I would to know how can I set the limit number of the posts visible into a page of a specify category.


Solution

Put this in your functions.php

function main_query_mods( $query ) {
    if(!$query->is_main_query()) {
        return;
    }
    // show 15 posts per page if category has id 7
    // check http://codex.wordpress.org/Conditional_Tags#A_Category_Page
    if ( is_category('7')) {
        $query->set('posts_per_page',15);
    }
}
add_action( 'pre_get_posts', 'main_query_mods' );


Answered By - offroff
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing