chiwormjava 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.js +60 -0
  2. package/java.json +6 -0
  3. package/package.json +19 -0
  4. package/readme.md +72 -0
package/index.js ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ const express = require('express');
3
+ const open = require('open');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ const app = express();
8
+ const PORT = 3000;
9
+
10
+ // Load JSON
11
+ const dataPath = path.join(__dirname, 'java.json');
12
+ const data = JSON.parse(fs.readFileSync(dataPath, 'utf-8'));
13
+
14
+ app.get('/', (req, res) => {
15
+ res.send(`
16
+ <html>
17
+ <body style="background:#1e1e1e;color:white;font-family:sans-serif;padding:20px">
18
+
19
+ <h2>Java Code Library</h2>
20
+
21
+ ${Object.keys(data).map(key => `
22
+ <button onclick="showCode('${key}')">${data[key].title}</button>
23
+ `).join("")}
24
+
25
+ <br/><br/>
26
+
27
+ <button onclick="copyCode()">Copy</button>
28
+
29
+ <pre id="code" style="background:#111;padding:10px;border-radius:6px;white-space:pre-wrap;"></pre>
30
+
31
+ <script>
32
+ const data = ${JSON.stringify(data)};
33
+ let current = "";
34
+
35
+ function format(code){
36
+ return code
37
+ .replace(/\\\\n/g, '\\n')
38
+ .replace(/\\\\t/g, '\\t');
39
+ }
40
+
41
+ function showCode(key){
42
+ current = data[key].code;
43
+ document.getElementById('code').textContent = format(current);
44
+ }
45
+
46
+ function copyCode(){
47
+ navigator.clipboard.writeText(format(current));
48
+ alert("Copied!");
49
+ }
50
+ </script>
51
+
52
+ </body>
53
+ </html>
54
+ `);
55
+ });
56
+
57
+ app.listen(PORT, () => {
58
+ console.log("Running on http://localhost:" + PORT);
59
+ open.openApp("http://localhost:" + PORT);
60
+ });
package/java.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "linkedlist": {
3
+ "title": "Linked List",
4
+ "code": "class Outer{\\n\\tclass LinkedList{\\n\\t\\tclass Node{\\n\\t\\t\\tint data;\\n\\t\\t\\tNode next;\\n\\n\\t\\t\\tNode(int data){\\n\\t\\t\\t\\tthis.data = data;\\n\\t\\t\\t}\\n\\t\\t}\\n\\n\\t\\tNode head = null;\\n\\n\\t\\tvoid add(int data){\\n\\t\\t\\tNode n = new Node(data);\\n\\n\\t\\t\\tif(head == null){\\n\\t\\t\\t\\thead = n;\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\n\\t\\t\\tNode temp = head;\\n\\t\\t\\twhile(temp.next != null){\\n\\t\\t\\t\\ttemp = temp.next;\\n\\t\\t\\t}\\n\\n\\t\\t\\ttemp.next = n;\\n\\t\\t}\\n\\n\\t\\tvoid remove(int data){\\n\\t\\t\\tif(head == null) return;\\n\\n\\t\\t\\tif(head.data == data){\\n\\t\\t\\t\\thead = head.next;\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\n\\t\\t\\tNode temp = head;\\n\\t\\t\\twhile (temp.next != null){\\n\\t\\t\\t\\tif(temp.next.data == data){\\n\\t\\t\\t\\t\\ttemp.next = temp.next.next;\\n\\t\\t\\t\\t\\treturn;\\n\\t\\t\\t\\t}\\n\\t\\t\\t\\ttemp = temp.next;\\n\\t\\t\\t}\\n\\t\\t}\\n\\n\\t\\tvoid display(){\\n\\t\\t\\tNode temp = head;\\n\\t\\t\\twhile(temp != null){\\n\\t\\t\\t\\tSystem.out.println(temp.data + \\\" \\\" );\\n\\t\\t\\t\\ttemp = temp.next;\\n\\t\\t\\t}\\n\\t\\t\\tSystem.out.println();\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static void main(String []args){\\n\\t\\tOuter o = new Outer();\\n\\t\\tLinkedList list = o.new LinkedList();\\n\\n\\t\\tlist.add(1);\\n\\t\\tlist.add(2);\\n\\t\\tlist.add(3);\\n\\n\\t\\tlist.display();\\n\\n\\t\\tlist.remove(2);\\n\\n\\t\\tlist.display();\\n\\t}\\n}"
5
+ }
6
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "chiwormjava",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "bin": {
9
+ "javacodewatch": "index.js"
10
+ },
11
+ "keywords": [],
12
+ "author": "",
13
+ "license": "ISC",
14
+ "description": "",
15
+ "dependencies": {
16
+ "express": "^5.2.1",
17
+ "open": "^11.0.0"
18
+ }
19
+ }
package/readme.md ADDED
@@ -0,0 +1,72 @@
1
+ class Outer{
2
+ class LinkedList{
3
+ class Node{
4
+ int data;
5
+ Node next;
6
+
7
+ Node(int data){
8
+ this.data = data;
9
+ }
10
+ }
11
+
12
+ Node head = null;
13
+
14
+ void add(int data){
15
+ Node n = new Node(data);
16
+
17
+ if(head == null){
18
+ head = n;
19
+ return;
20
+ }
21
+
22
+ Node temp = head;
23
+ while(temp.next != null){
24
+ temp = temp.next;
25
+ }
26
+
27
+ temp.next = n;
28
+ }
29
+
30
+ void remove(int data){
31
+ if(head == null) return;
32
+
33
+ if(head.data == data){
34
+ head = head.next;
35
+ return;
36
+ }
37
+
38
+ Node temp = head;
39
+ while (temp.next != null){
40
+ if(temp.next.data == data){
41
+ temp.next = temp.next.next;
42
+ return;
43
+ }
44
+ temp = temp.next;
45
+ }
46
+ }
47
+
48
+ void display(){
49
+ Node temp = head;
50
+ while(temp != null){
51
+ System.out.println(temp.data + \" \" );
52
+ temp = temp.next;
53
+ }
54
+ System.out.println();
55
+ }
56
+ }
57
+
58
+ public static void main(String []args){
59
+ Outer o = new Outer();
60
+ LinkedList list = o.new LinkedList();
61
+
62
+ list.add(1);
63
+ list.add(2);
64
+ list.add(3);
65
+
66
+ list.display();
67
+
68
+ list.remove(2);
69
+
70
+ list.display();
71
+ }
72
+ }