-
-
Notifications
You must be signed in to change notification settings - Fork 268
Determine EFI virtual disk size automatically (take 2) #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@jsmeix your rework of function efiboot_img_size() was implemented (for me a bit harder to read, but it does its job well after all ;-)). |
|
@gozora Can you describe why my code is harder to read for you. I like to provide code that is well understandable by others. Background information: I am very interested in comprehensibility of source code. For me the primary purpose of source code is This way others who read the author's code For me it is only a secondary condition that code If code fulfills its primary purpose (telling others In contrast if code only fulfills the secondary condition |
|
Don't take my self as some reference for coding style, I'm rather hobby programmer than professional developer, so I certainly lack routine in reading other peoples code and more importantly I often have trouble to understand other people intentions in code. So if something is hard to read for ME, it doesn't mean author did something wrong, it means that I need to work on my skills ;-). Please take all this as my personal opinion, maybe you could discuss this with more experienced programmers or maybe some who actually teaches programming, because such discussion certainly needs someone with academical/teaching skills. |
|
@jsmeix hope the pull request is OK now ;-) |
|
Just for the fun of it: Lucky you! - when you only "often have trouble to understand Poor me! - because I almost always have trouble to understand Usually I do understand what code does E.g. what is the intention behind: #! /bin/bash j=0 for i in $( seq 1 2 $(( 2 * $1 - 1 )) ) do (( j += i )) done echo $j |
and move of size detection code to main part of the script.
|
Well I guess you encounter much more alien code daily as I do... |
|
Pull requested was updated. |
|
With great pleasure I merge your pull request. |
|
:-) |
|
This pull request should fix #810 |
|
@gozora |
|
It sums odd numbers, nice! |
|
That it sums odd numbers is the low level implementation detail |
|
No idea ... (except that it is homework ;-)) |
|
I did not use it before. I made it new from scratch here while I wrote #816 (comment) |
|
A hint why one should sum odd numbers: 1 A 1 + 3 B B A B 1 + 3 + 5 C C C B B C A B C 1 + 3 + 5 + 7 D D D D C C C D B B C D A B C D |
|
brute force password cracker? |
|
:-) I can see the pattern, but I can't figure out what is it good for ... |
|
or is this some strange way how to calculate power of some number? |
|
Yes! The purpose is calculating the square number of its input "$1": # cat -n ./sq.sh
1 #! /bin/bash
2 j=0
3 for i in $( seq 1 2 $(( 2 * $1 - 1 )) )
4 do (( j += i ))
5 done
6 echo $j
# ./sq.sh 1
1
# ./sq.sh 2
4
# ./sq.sh 3
9
# ./sq.sh 123
15129
|
|
I didn't know about this property, it is really interesting. |
|
You are welcome! And finally here same functionality implemented # cat -n ./square_number.sh
1 #! /bin/bash
2 # calculate the square number N^2 of its input N
3 # by summing up the first N odd numbers 1 3 ... 2*N-1
4 # where each nth partial sum is the nth square number
5 # see https://en.wikipedia.org/wiki/Square_number#Properties
6 N=$1
7 if ! [[ $N =~ ^[0-9]+$ ]]
8 then echo "Input must be non-negative integer." 1>&2
9 exit 1
10 fi
11 square_number=0
12 for odd_number in $( seq 1 2 $(( 2 * N - 1 )) )
13 do (( square_number += odd_number ))
14 done
15 echo "$N^2 = $square_number"
# ./square_number.sh
Input must be non-negative integer.
# ./square_number.sh 0
0^2 = 0
# ./square_number.sh 1
1^2 = 1
# ./square_number.sh 2
2^2 = 4
# ./square_number.sh 3
3^2 = 9
# ./square_number.sh 123
123^2 = 15129
# ./square_number.sh -123
Input must be non-negative integer.
|
Fix for manual detection of EFI virtual image (efiboot.img) size.