Monday, December 18, 2023
Surface Area of a Cone
What's the circumference of the big circle that the paper cup is part of? 2 π L.
What's its area? π L 2.
But we are interested in the section, the paper cup. Geez I'll need the angle but I don't know.
But I do know its rim's length. That would be the circumference of the bottom of the cone: π r2.
Then the paper cup's area is a fraction of the big circle's area π L 2.
The fraction is rim over entire circumference, which is π r2 over 2 π L. Multiply it out, many things cancel, and then you will get π r L. See, if the cone is entirely flat, then r=L it is just π r2. Armed with this lateral cone area formula π r L, there is still a bit of calculation to find surface area of a frustum, which is top and bottom circle area. Plus the difference of lateral area of bigger cone and smaller cone. First I'll need the height of the cone which takes a bit of work with similar triangles to find out. But the point is this: Do not ever just tell kids to use formulas, derive them! Deriving formula is learning math. Using the formula is applying math. Plugging in numbers in a formula which you don't know where it came is lowest form of math.
Wednesday, April 19, 2023
"Teen Takeover"
Wednesday, April 5, 2023
Chicago's new mayor
Tuesday, April 4, 2023
Javascript gotchas
let car = { model: 'Corolla', make: 'Toyota' }; let car2 = car; car2.model = 'Camry'; console.log(car); console.log(car2); console.log(car==car2);The output is
{ model: 'Camry', make: 'Toyota' } { model: 'Camry', make: 'Toyota' } trueYou changed the original car by modifying the copy and they are same object! This works like a pointer in C++. Now how do you actually make a distinct copy of an object? There are few ways to do this and there is shallow copy and deep copy. See this excellent tutorial: https://www.javascripttutorial.net/object/3-ways-to-copy-objects-in-javascript/ Let, var, const In the beginning there was "var" and the "function", probably derived from Pascal as it faded into oblivion. Now there is this "let" and "const". "const" is a bit more straight forward, which is constant like other languages, to make you feel more secure that your variables aren't changing.
const a=1 a =2; // boom error trying to modify constantBut wait, redifining variable is not allowed but you can still change things within the variable
const mycar = { model: 'Corolla', make: 'Toyota' }; mycar.model = 'RAV4' // valid to change things inside the const myvar console.log(mycar) mycar = { // error: assignment to constant variable model:'Focus', make:'Ford' }What's difference between "let" and "var"? "let" is local scope and "var" is global scope. "var" can be redeclared but "let" does not.
var a = 1 let b = 2 var a = "John" // ok let b = "Mary" // not okNumber type coersion
// adding is concat, if you have a string adding number both are like strings console.log("10"+5); //105 console.log(10+"5"); //105 // but this only apply to add, other math operations treat it as number console.log(10 - '5'); //5 console.log(10 * '5'); //50 console.log(10 / '5'); //2 console.log(10 % '5'); //0 //convert string to number var a = '10'; var b = 5 var c = a-'0' + 5 // to convert string to number so you can do a add, one way is minus '0' console.log(c) // 15 var d = Number(a)+b // or be explicit about it, or do parseInt console.log(d) // 15 //boolean is coverted to 1 for true, 0 for false console.log(true + 2); // 3 console.log(false + 2); // 2 // string and number are considered double equal, but not triple equal console.log(10 == '10') // true console.log(10 === '10') // false
Friday, March 24, 2023
Estimate π by counting random numbers
public double estimatePi() { int count=0; int MAX=100000; for (int i=0; i < MAX; i++) { double x = Math.random(); double y = Math.random(); if (Math.sqrt(x*x+y*y)<1) { count++; } } return count*4/(MAX*1.0); }It gets pretty close to 3.14. Although computers nowadays are pretty fast, but it is expensive (as in time consuming) operation to do square root, and lots of it to get a fair estimate. Math.PI gives you a lot of digits, millions of digits of π are now known there is no more need to estimate it. But nevertheless it is good little math and computer exercise. I lived in darkness because never heard of this method before.
Tuesday, March 14, 2023
One more Java Streams example for Pat Sajak
String str = "This maybe helpful for Pat Sajak"; // Turn the string into a list of characters, upper case it // then recollect it with a groupby MapOutput:result = str .chars() .mapToObj(e -> (char)e) .map(c-> Character.toUpperCase(c)) .collect( Collectors.groupingBy( Function.identity(), Collectors.counting() ) ); System.out.println(result);
{ =5, A=4, B=1, E=2, F=2, H=2, I=1, J=1, K=1, L=2, M=1, O=1, P=2, R=1, S=2, T=2, U=1, Y=1}
Friday, March 10, 2023
Privacy Policy for Solvedoku
Joseph Mak built the Solvedoku app as a Free app. This SERVICE is provided by Joseph Mak at no cost and is intended for use as is.
This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.
If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.
The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which are accessible at Solvedoku unless otherwise defined in this Privacy Policy.
Information Collection and Use
For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retained on your device and is not collected by me in any way.
The app does use third-party services that may collect information used to identify you.
Link to the privacy policy of third-party service providers used by the app
Log Data
I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third-party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.
Cookies
Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.
This Service does not use these “cookies” explicitly. However, the app may use third-party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.
Service Providers
I may employ third-party companies and individuals due to the following reasons:
- To facilitate our Service;
- To provide the Service on our behalf;
- To perform Service-related services; or
- To assist us in analyzing how our Service is used.
I want to inform users of this Service that these third parties have access to their Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.
Security
I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.
Links to Other Sites
This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.
Children’s Privacy
These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13 years of age. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do the necessary actions.
Changes to This Privacy Policy
I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page.
This policy is effective as of 2023-03-10
Contact Us
If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me at josephmak0865@gmail.com.
This privacy policy page was created at privacypolicytemplate.net and modified/generated by App Privacy Policy Generator
Wednesday, March 8, 2023
Privacy Policy for Art of War
Joseph Mak built the Art of War app as a Free app. This SERVICE is provided by Joseph Mak at no cost and is intended for use as is.
This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.
If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.
The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which are accessible at Art of War unless otherwise defined in this Privacy Policy.
Information Collection and Use
For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retained on your device and is not collected by me in any way.
The app does use third-party services that may collect information used to identify you.
Link to the privacy policy of third-party service providers used by the app
Log Data
I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third-party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.
Cookies
Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.
This Service does not use these “cookies” explicitly. However, the app may use third-party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.
Service Providers
I may employ third-party companies and individuals due to the following reasons:
- To facilitate our Service;
- To provide the Service on our behalf;
- To perform Service-related services; or
- To assist us in analyzing how our Service is used.
I want to inform users of this Service that these third parties have access to their Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.
Security
I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.
Links to Other Sites
This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.
Children’s Privacy
These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13 years of age. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do the necessary actions.
Changes to This Privacy Policy
I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page.
This policy is effective as of 2023-03-08
Contact Us
If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me at josephmak0865@gmail.com.
This privacy policy page was created at privacypolicytemplate.net and modified/generated by App Privacy Policy Generator
Privacy Policy for 300 Tang Poems
Joseph Mak built the 300 Tang Poem app as a Free app. This SERVICE is provided by Joseph Mak at no cost and is intended for use as is.
This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.
If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.
The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which are accessible at 300 Tang Poem unless otherwise defined in this Privacy Policy.
Information Collection and Use
For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retained on your device and is not collected by me in any way.
The app does use third-party services that may collect information used to identify you.
Link to the privacy policy of third-party service providers used by the app
Log Data
I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third-party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.
Cookies
Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.
This Service does not use these “cookies” explicitly. However, the app may use third-party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.
Service Providers
I may employ third-party companies and individuals due to the following reasons:
- To facilitate our Service;
- To provide the Service on our behalf;
- To perform Service-related services; or
- To assist us in analyzing how our Service is used.
I want to inform users of this Service that these third parties have access to their Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.
Security
I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.
Links to Other Sites
This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.
Children’s Privacy
These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13 years of age. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do the necessary actions.
Changes to This Privacy Policy
I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page.
This policy is effective as of 2023-03-08
Contact Us
If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me at josephmak0865@gmail.com.
This privacy policy page was created at privacypolicytemplate.net and modified/generated by App Privacy Policy Generator
Monday, February 27, 2023
More Java 8 revisited: lambda and java.util.function things
import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Consumer; import java.util.Arrays; import java.util.List; import java.util.Optional; public class Test2 { // provide 1 abstract method, (the follow annotation is optional) @FunctionalInterface interface MyFunctionalInterface { String doSomeWork(String str); } // Optional public static void myMethodWithOptionalParam(OptionalOutputparam) { if (!param.isPresent()) System.out.println("You didn't give me a parameter"); System.out.println("Hey the length is: " + param.orElse("").length()); } public static void main(String arg[]) { // Functional Interface MyFunctionalInterface myFunctionalInterface = (s -> "hey my friend:" + s); System.out.println(myFunctionalInterface.doSomeWork("Johnny")); // Function andThen and compose Function myFunction = s -> "take an s and return {" + s + "}"; Function myFunction2 = s -> "take another s and return (" + s + ")"; myFunction = myFunction.andThen(myFunction2); System.out.println(myFunction.apply("foo")); // f(x) = x/2 // g(x) = 3x // f o g (x) = 3*x/2 Function f = x -> x / 2.0; Function g = x -> 3 * x; Function fog = f.compose(g); System.out.println(fog.apply(5.0)); // f(g(5))=15/2=7.5 // func is a function R2 -> R BiFunction < Double, Double, Double > hyp = (x, y) -> Math.sqrt(x * x + y * y); System.out.println("hypontenuse: " + hyp.apply(3d, 4d)); // Predicate List < String > names = Arrays.asList( "Ryu", "Ken", "Blanka", "Bison", "Balrog"); Predicate p = (s) -> s.startsWith("B"); // has a test operation // Iterate through the list for (String st: names) { // call the test method if (p.test(st)) System.out.println(st); } // Consumer has "accept" and can be combined with "andThen" Consumer sayHi = (x) -> System.out.println("Hello there: " + x.toLowerCase()); Consumer sayBye = (x) -> System.out.println("bye now: " + x.toLowerCase()); sayHi.andThen(sayBye).accept("my friend"); myMethodWithOptionalParam(Optional.ofNullable("hello world")); myMethodWithOptionalParam(Optional.ofNullable(null)); // myMethodWithOptionalParam(null); won't compile } }
hey my friend:Johnny take another s and return (take an s and return {foo}) 7.5 hypontenuse: 5.0 Blanka Bison Balrog Hello there: my friend bye now: my friend Hey the length is: 11 You didn't give me a parameter Hey the length is: 0
Java 8 Streams revisited
List <Integer> myList = Arrays.asList(4,56,1,55,12,46); System.out.println("original list: "+myList); List myListFiltered = myList.stream().filter( n -> n%2 ==0).collect(Collectors.toList()); System.out.println("even filter: "+myListFiltered); long countEven = myList.stream().filter(n -> n %2 ==0).count(); System.out.println("count of even: "+countEven); System.out.println("max: "+ myList.stream().max(Integer::compare).get()); System.out.println("avg: "+ myList.stream().mapToInt(Integer::intValue).average().getAsDouble()); System.out.println("sum: "+ myList.stream().mapToInt(i->i).sum()); System.out.println("sorted: "+myList.stream().sorted().collect(Collectors.toList())); List<String> names = Arrays.asList("ryu","ken", "guile", "chun li", "ryu", "ken"); System.out.println("some names: "+names); List<String> upper = names.stream().map(String::toUpperCase).distinct().sorted().collect(Collectors.toList()); System.out.println("Sorted and upper and distinct: "+upper);Output
original list: [4, 56, 1, 55, 12, 46] even filter: [4, 56, 12, 46] count of even: 4 max: 56 avg: 29.0 sum: 174 sorted: [1, 4, 12, 46, 55, 56] some names: [ryu, ken, guile, chun li, ryu, ken] Sorted and upper and distinct: [CHUN LI, GUILE, KEN, RYU]