$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$becomes $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$ Tex/LaTex however has a bit of learning curve. There are tutorials out there. But now there is WYSIWYG editor too: https://latexeditor.lagrida.com/ You an also use Jupyter Notebook to type equations in similar ways and also run Python right on it too. So if you have math things to tell, now it is easier to display your equations and data charts etc.
/*
*Comments
*/
Monday, November 11, 2024
MathJax
HTML is nice but hard to type math stuff like fractions and equations... how can math things be shown on a webpage? Sure people can use powerful equation editors nowadays to generate PDFs. Traditionally math text are typeset by Tex/LaTex. And with MathJax you can now turn that into webpage:
Thursday, October 31, 2024
Angular revisited
I haven't looked at Angular in a long time... it is still complex. Requires getting node.js and downloading its CLI to generate skeletons first. Then jam your html into your template section of your components, while making sure you import the right things. If you just look at code, it is hard to tell what is generated and what is to be inserted by hand. Dude, this is too complex to be effective. Even React is a little simpler.
Official tutorials are followable... but not step-by-step from scratch. You start with some existing things or play on the browser in these tutorials.
Typescript: If you do want types, why don't you go to Java/C++ and and instead compile into javascript? The "beauty" of javascript is lack of types, less to worry about. It was intended to be quick-and-dirty.
Whole Angular is too complex if you ask me, as need to generate so many things. This isn't straight forward enough. It isn't so elegant to integrate javascript and html... HTML entirely within backquotes inside components.
It is almost impossible to use Angular without Visual Studio Code and its plugings. Someone should make an IDE, with a good editor. New->Component, boom, call that "ng generate component" behind the scene. No one needs to learn another CLI.
https://angular.dev/tutorials/learn-angular
https://angular.dev/tutorials/first-app
Good luck if you must use it.
https://angular.dev/tutorials/first-app
Good luck if you must use it.
Wednesday, September 18, 2024
Java ScheduledExecutorService
import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class ConcurrentStuff { public static void main(String[] args) { System.out.println("begin"); ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); System.out.println("scheduling a task to run after 2 seconds"); // Schedule a task to run after a delay of 2 seconds executor.schedule(new MyTask(), 2, TimeUnit.SECONDS); System.out.println("scheduling a task to delay 3 seconds then repeat every 5 seconds"); // Schedule a task to run after a delay of 3 seconds and repeat every 5 seconds executor.scheduleAtFixedRate(new MyTask(), 3, 5, TimeUnit.SECONDS); // Wait for scheduled tasks to complete try { System.out.println("sleeping to demo scheduling at work"); Thread.sleep(15000); } catch (InterruptedException e) { e.printStackTrace(); } // Shutdown the executor executor.shutdown(); System.out.println("end"); } static class MyTask implements Runnable { @Override public void run() { System.out.println("Task executed at: " + new java.util.Date()); } } }
Sunday, September 15, 2024
Determinant of a matrix
This little program calculates the determinant of an matrix.. using recursion. You don't even need ad - bc for a 2x2 [[a b][c d]]
https://en.wikipedia.org/wiki/Determinant
public class CodeWar { public static int[][] buildSubmatrix(int[][] matrix, int r, int c) { int size = matrix.length - 1; int result[][] = new int[size][size]; int a = 0, b = 0; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix.length; j++) { if (i != 0 && j != c) { result[a][b] = matrix[i][j]; b++; } } if (i != r) { a++; b = 0; } } return result; } public static int determinant(int[][] matrix) { if (matrix.length == 1) return matrix[0][0]; int sign = 1; int sum = 0; for (int i = 0; i < matrix[0].length; i++) { int n = matrix[0][i]; int submatrix[][] = buildSubmatrix(matrix, 0,i); sum += sign * n * determinant(submatrix); sign = sign * -1; } return sum; } public static void main(String arg[]) { int[][] matrix = { { -2, -1,2 }, { 2,1,4 }, { -3,3,1 } }; System.out.println(determinant(matrix)); } }
Tuesday, August 20, 2024
Java: of list and set
There are multiple ways to construct a list in java. (easier in python and other languages).
To eliminate duplicates, you can use the stream distinct, or put it in a set (HashSet or LinkedHashSet to retain order) then make it back to a list.
public static void main(String arg[]) { String a[] = new String[] { "A", "B", "C", "D", "A", "C", "E" }; List<String> list = Arrays.asList(a); // constructed one way List<String> list2 = List.of(a); // constructed another way (java 9+) List<String> list3 = List.of( "A", "B", "C", "D", "A", "C", "E" ); // yet another way // using stream distinct one way List<String> noDups = list.stream().distinct().collect(Collectors.toList()); // using stream distinct another way List<String> noDups2 = list2.stream().distinct().toList(); // put on a set and make a iist out of it Set<String> set = new LinkedHashSet<>(); set.addAll(list3); List<String> noDups3 = new ArrayList<>(set); System.out.println(noDups); System.out.println(noDups2); System.out.println(noDups3); }
Subscribe to:
Posts (Atom)