Comments (8)
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.
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.
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.
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.
@powder96 good idea. i implemented the string stuff. would you like to add the automatic abbreviations of "k"?
from tinycon.
@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.
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.
Yuck. That aside, keep two things in mind:
- My code is designed to be very general.
- 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)
- Favicon not working correctly in Chrome
- tinycon
- Do not expose "Tinycon" object to "window" for AMD HOT 1
- Rename "colour" to "color" HOT 2
- Having png icons seems to break getCurrentFavicon HOT 1
- Relying on window.devicePixelRatio causing issues when browser is zoomed
- publish this to bower and npm? HOT 5
- Support Edge Browser HOT 1
- In Chrome, Favicon not showing HOT 1
- Favicon tag is not matched case insenstively
- Doesnt fall back to title update in IE11
- Publish new version to npm HOT 1
- Request: Add bower.json to the repo HOT 4
- Ugly icon rendering HOT 3
- Take control of npm repository HOT 1
- Favicon location. HOT 1
- Regexp/Delete too aggressive? HOT 1
- Do not assume <link> tags are all in <head> HOT 3
- setBubble sometimes not working in Chrome HOT 4
- Favicon indicator is not working correctly in Chrome on Mac HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinycon.