icza / gox Goto Github PK
View Code? Open in Web Editor NEWMinimalistic extension to Go. It means to be a complement to the standard library.
License: Apache License 2.0
Minimalistic extension to Go. It means to be a complement to the standard library.
License: Apache License 2.0
func OpenDefault(fileOrURL string) error cuts the link on &
sign on windows with chrome browser
the original link: https://twitter.com/i/oauth2/authorize?response_type=code&client_id=emJHZMUdHM9QRlRIdk45QjY6MTpjaQ&redirect_uri=https://blush.app/api/auth&scope=tweet.read%20tweet.write%20users.read%20users.read%20follows.read%20follows.write%20offline.access&state=op-oLJWRfa8d84GkoLjE_euBQB_naZfisK3JSjcuWHtMk9O_IdSBhr2ZVQkfmXsAvO_HDIIXCTl3kHYGwpDbTGZ33u3t2OG6Zlkb-kh0ITcZh_nsC7IecKPWzl0Rf1dKwh5LmtMqhp5xkZCPAMMPpgHSDUzADVO2oGA==&code_challenge=gkzQm0D3IAGMY3CHDfafxGYnqofW4pfNB6yah0&code_challenge_method=S256
the opened link: https://twitter.com/i/oauth2/authorize?response_type=code
p.s. It works fine on linux
I've ran into some difficulties when tried to find a way to round float64 values to 2 decimal places. Maybe smn can explain am I wrong or suggest a solution, if exists.
P.S. I know about IEEE-754 floating point standard
I've found 2 values that rounds in a way I don't expect - 1.275
and 4.935
.
1.275
is expected to become 1.28
(but I get 1.27
)
4.935
is expected to become 4.94
(but I get 4.93
)
Example code (Go version 1.19):
package main
import (
"fmt"
"github.com/icza/gox/mathx"
)
func main() {
print(2.345, 0.01, 2.35) // ok
print(1.275, 0.01, 1.28) // fail #1
print(4.935, 0.01, 4.94) // fail #2
}
func print(f, unit, exp float64) {
rounded := mathx.Round(f, unit)
fmt.Printf("input: %.3f | got: %.3f | expected: %.3f\n", f, rounded, exp)
}
Output:
input: 2.345 | got: 2.350 | expected: 2.350
input: 1.275 | got: 1.270 | expected: 1.280
input: 4.935 | got: 4.930 | expected: 4.940
Are my expectations wrong?
Managed to workaround it in the next code, but I'm not sure if it will fix everything and not break smth else:
func round2(f float64) float64 {
// return math.Floor(f*100+0.5) / 100.0 // same rounding issue as mathx.Round(f, 0.01)
// return math.Floor(f*100+0.5+1e-14) / 100.0 // fixes 1.275, but not 4.935
return math.Floor(f*100+0.5+1e-13) / 100.0 // 1e-13 helps with both 1.275 and 4.935
}
// problem is when I multiply by 100 and then rounding breaks
// 1) 1.275 * 100 = 127.49999999999999 (instead of 127.5)
// 2) 4.935 * 100 = 493.49999999999994
According to the Apache 2.0 license:
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
I want to attribute the work in this repo, but I could not find any such copyright notices in any of the source files. To me it is unclear how the Apache 2.0 License works without copyright notice. Is this something you could fix @icza?
Extra information
The "Redistribution" of the Apache 2.0 Licence applies to the "Work", which (as stated above) is indicated by a copyright notice.
Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
I have a test where I set exact expiry date and then test if the format is printed correctly. My tests started failing today (28th of February), because I am missing 2 days. This is output from my test:
expected: "3 years 2 months 7 days 5 hours 25 minutes"
actual : "3 years 2 months 5 days 5 hours 25 minutes"
All I am doing in the test is creating a future time:
func getTime(years, months, days, hours, minutes int) time.Time {
return time.Now().AddDate(years, months, days).
Add(time.Hour*time.Duration(hours) + time.Minute*time.Duration(minutes))
}
And then comparing time that is formatted by (where t
is the time generated by getTime
function):
year, month, day, hour, minute, _ := timex.Diff(time.Now(), t)
First of all, thanks for this awesome library.
Result running in playground is 1
But result of same code running in my laptop is 2
BTW, I am not exactly know when to use RandomIntWeight func
Hi,
In building this for Debian I discovered that the math tests fail to run on 32-bit architectures, specifically
Line 17 in cd40a3f
-math.MinInt32
is one too big and causes an overflow. I'm happy to submit a PR to fix this, but I'm not sure how you'd prefer this be fixed. The easiest would be to either remove the test or to add 1 to MinInt32. What would you prefer be done to fix this?gox
does not contain a NOTICE
file or any other obvious way of handling attribution to comply with the Apache 2.0 license.
Would you consider creating a NOTICE
file or stating in the README
how you would prefer attribution be handled?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.