Giter VIP home page Giter VIP logo

Comments (8)

tomByrer avatar tomByrer commented on July 2, 2024

https://github.com/makeable/Notificon allows 2 characters. Remember that favicons are only 16px wide; might be better to switch out the entire favicon.

from tinycon.

tommoor avatar tommoor commented on July 2, 2024

Thanks for bringing this up, I feel it is better handled by the library itself... so if you pass in 12000 the library would automatically show 12K.

What do you think?

from tinycon.

ssokolow avatar ssokolow commented on July 2, 2024

I think both should be supported.

Automatic abbreviation in the icon so developers don't have to worry about it and the title fallback can still show the full-precision number (among other things, ensuring that Firefox App Tab glows work reliably when I patch it to show both).

Support for arbitrary characters in the bubble so I can indicate that the connection to the server was lost in a WebSockets-based app with something like ? or *.

from tinycon.

johannesnagl avatar johannesnagl commented on July 2, 2024

i would love to have a feature to display text. i would like to integrate this in our time tracking tool, and therefore the automatic conversion to "12k" would be wrong. - i would love to have "1h" instead of "60" min.

from tinycon.

johannesnagl avatar johannesnagl commented on July 2, 2024

@powder96 good idea. i implemented the string stuff. would you like to add the automatic abbreviations of "k"?

from tinycon.

ssokolow avatar ssokolow commented on July 2, 2024

@powder96 Probably a good idea to spend the extra few seconds to support at least "m" (mega/million) and "g" (giga/billion)... just in case.

I can imagine a few plausible uses cases for TinyCon which would benefit from those. (eg. displaying progress for a long-running file upload so you can switch away but still keep an eye on it)

from tinycon.

ssokolow avatar ssokolow commented on July 2, 2024

Interesting approach but a bit inelegant. Here's what I did for one of my to-be-released Python projects:

def formatFileSize(size, unit='', precision=0):
    """Take a size in bits or bytes and return it all prettied
    up and rounded to whichever unit gives the smallest number.

    A fixed unit can be specified. Possible units are B, KB,
    MB, GB, TB, and PB so far. Case-insensitive.

    Works on both negative and positive numbers. In the event
    that the given value is in bits, the user will have to
    use result = result[:-1] + 'b' to make it appear correct.

    Will calculate using integers unless precision is != 0.
    Will display using integers unless precision is > 0.

    TODO: Add support for decimals. (eg 50GB and 1.3GB)"""
    # Each unit's position in the list is crucial.
    # units[2] = 'MB' and size / 1024**2 = size in MB
    # units[3] = 'GB' and size / 1024**3 = size in GB
    units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']

    if precision:
        size = float(size)
    # Did the calling function specify a valid unit of measurement?
    if unit and unit.upper() in units:         # If so, find the unit index by searching.
        unit_idx = units.index(unit)
        size /= (1024**unit_idx)
    else:                                      # If not, find the unit index by iteration.
        unit_idx = 0
        while abs(size) > 1024 and unit_idx < (len(units) - 1):
            size /= 1024
            unit_idx += 1

    return '%.*f%s' % (precision, size, units[unit_idx])

(It's old code. When I get back to working on it, I'll fix it up so it uses proper abbreviations like "KiB" for 1024-rounded increments.)

from tinycon.

ssokolow avatar ssokolow commented on July 2, 2024

Yuck. That aside, keep two things in mind:

  1. My code is designed to be very general.
  2. My code is at least half a decade old (The project is something that was shelved for a very long time) and was written when I was just getting out of high school.

Here's your filesizeFromBytes as I'd write it in Python now that I'm more skilled:

import math

def filesizeFromBytes(size, precision=2):
    units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']
    increment = 1024.0 # increment must be float in Py 2.x to avoid floor division

    index = min(int(math.log(abs(size), increment)), len(units) - 1)
    size /= increment ** index

    return '%.*f%s' % (precision, size, units[index])

Edit: Added a guard to prevent a big integer from running off the end of the units list and an abs() call to allow negative values. (Python supports arbitrarily large integers as long as your system has the memory)

>>> filesizeFromBytes(-90159567984)
'-83.97GiB'
>>> filesizeFromBytes(-901595679846759834276598324675983425457304895734095730498673049867)
'-800777826134755167080156522430030733324798230790144.00PiB'

from tinycon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.