diff --git a/.gitignore b/.gitignore index 3ff1efa..3268041 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,6 @@ crawler/common # for other */winn/* +*/goland/bin/ +*/goland/pkg/ +*/goland/src/github.com/ diff --git a/goland/bin/image_conver b/goland/bin/image_conver new file mode 100755 index 0000000..de1a3fb Binary files /dev/null and b/goland/bin/image_conver differ diff --git a/goland/install_ic b/goland/install_ic new file mode 100755 index 0000000..3f8a698 --- /dev/null +++ b/goland/install_ic @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# export GOPATH=`pwd` +export GOPATH=/Users/wxnacy/PycharmProjects/study/goland +SOURCE_DIR=image_conver +# BIN=lu + +# CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install $SOURCE_DIR +# CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go install $SOURCE_DIR +# CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go install $SOURCE_DIR +go install $SOURCE_DIR + +# test -d bin || mkdir bin +# test -d bin/linux_amd64 || mkdir bin/linux_amd64 +# test -d bin/windows_amd64 || mkdir bin/windows_amd64 +# test -d bin/darwin_amd64 || mkdir bin/darwin_amd64 + +# cp ${GOPATH}/bin/linux_amd64/$BIN bin/linux_amd64 +# cp ${GOPATH}/bin/windows_amd64/$BIN.exe bin/windows_amd64 +# cp ${GOPATH}/bin/$BIN bin/darwin_amd64 + +echo 'Install Finshed' diff --git a/goland/pkg/darwin_amd64/github.com/nfnt/resize.a b/goland/pkg/darwin_amd64/github.com/nfnt/resize.a new file mode 100644 index 0000000..4df0b1d Binary files /dev/null and b/goland/pkg/darwin_amd64/github.com/nfnt/resize.a differ diff --git a/goland/pkg/darwin_amd64/image_conver.a b/goland/pkg/darwin_amd64/image_conver.a new file mode 100644 index 0000000..48a9c80 Binary files /dev/null and b/goland/pkg/darwin_amd64/image_conver.a differ diff --git a/goland/src/github.com/nfnt/resize b/goland/src/github.com/nfnt/resize new file mode 160000 index 0000000..83c6a99 --- /dev/null +++ b/goland/src/github.com/nfnt/resize @@ -0,0 +1 @@ +Subproject commit 83c6a9932646f83e3267f353373d47347b6036b2 diff --git a/goland/src/image_conver/main.go b/goland/src/image_conver/main.go new file mode 100644 index 0000000..314524d --- /dev/null +++ b/goland/src/image_conver/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello World") +} diff --git a/java/SpringBoot-HelloWorld/tree.txt b/java/SpringBoot-HelloWorld/tree.txt new file mode 100644 index 0000000..55aac0b --- /dev/null +++ b/java/SpringBoot-HelloWorld/tree.txt @@ -0,0 +1,32 @@ +com.wxnacy.spring:SpringBoot-HelloWorld:jar:1.0-SNAPSHOT +\- org.springframework.boot:spring-boot-starter-web:jar:1.5.9.RELEASE:compile + +- org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:compile + | +- org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:compile + | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.9.RELEASE:compile + | +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.9.RELEASE:compile + | | +- ch.qos.logback:logback-classic:jar:1.1.11:compile + | | | +- ch.qos.logback:logback-core:jar:1.1.11:compile + | | | \- org.slf4j:slf4j-api:jar:1.7.25:compile + | | +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile + | | +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile + | | \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile + | +- org.springframework:spring-core:jar:4.3.13.RELEASE:compile + | \- org.yaml:snakeyaml:jar:1.17:runtime + +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.9.RELEASE:compile + | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:compile + | | \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.23:compile + | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:compile + | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.23:compile + +- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile + | +- javax.validation:validation-api:jar:1.1.0.Final:compile + | +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile + | \- com.fasterxml:classmate:jar:1.3.4:compile + +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile + | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile + | \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile + +- org.springframework:spring-web:jar:4.3.13.RELEASE:compile + | +- org.springframework:spring-aop:jar:4.3.13.RELEASE:compile + | +- org.springframework:spring-beans:jar:4.3.13.RELEASE:compile + | \- org.springframework:spring-context:jar:4.3.13.RELEASE:compile + \- org.springframework:spring-webmvc:jar:4.3.13.RELEASE:compile + \- org.springframework:spring-expression:jar:4.3.13.RELEASE:compile diff --git a/java/modification/README.md b/java/modification/README.md index 5a76743..7a11960 100644 --- a/java/modification/README.md +++ b/java/modification/README.md @@ -31,3 +31,5 @@ $ ./run.sh 子类 √ × √ √ 外部类 √ × × × ``` + +更多文章:https://wxnacy.com/ diff --git a/java/simple/ArrayLoop.java b/java/simple/ArrayLoop.java new file mode 100644 index 0000000..40122df --- /dev/null +++ b/java/simple/ArrayLoop.java @@ -0,0 +1,24 @@ +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +public class ArrayLoop { + + public static void main(String[] args){ + + List list = Arrays.asList("wxnacy", "wxn", "wen", "li"); + for(String l : list){ + System.out.println(l); + } + + for(int i = 0; i < list.size(); i++){ + System.out.println(list.get(i)); + } + + Iterator iter = list.iterator(); + while(iter.hasNext()) { + System.out.println(iter.next()); + } + + } +} diff --git a/java/simple/ClassList.java b/java/simple/ClassList.java new file mode 100644 index 0000000..0507e96 --- /dev/null +++ b/java/simple/ClassList.java @@ -0,0 +1,41 @@ +import java.util.List; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +/** + * Created by wxnacy + */ +public class ClassList { + + public static void main(String args[]) { + + ClassList cl = new ClassList(); + String path = "/Users/wxnacy/.m2/repository/com/alibaba/fastjson/1.1.34/fastjson-1.1.34.jar"; + List classList = cl.getClassList(path); + } + + public List getClassList(String path) { + List list = new ArrayList(); + try { + JarFile jarFile = new JarFile(path); + Enumeration enu = jarFile.entries(); + while (enu.hasMoreElements()) { + JarEntry jarEntry = (JarEntry) enu.nextElement(); + String name = jarEntry.getName(); + if (name.endsWith(".class") && name.indexOf("$") == -1 ) { + name = name.substring(0, name.indexOf(".class")); + name = name.replaceAll("/", "."); + System.out.println(name); + list.add(name); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } + +} diff --git a/java/simple/HelloWorld.java b/java/simple/HelloWorld.java index 73f3821..6a75987 100644 --- a/java/simple/HelloWorld.java +++ b/java/simple/HelloWorld.java @@ -1,4 +1,3 @@ -package simple; public class HelloWorld{ public static void main(String args[]){ System.out.println("Hello World"); diff --git a/java/simple/HttpClients.java b/java/simple/HttpClients.java new file mode 100644 index 0000000..38c3089 --- /dev/null +++ b/java/simple/HttpClients.java @@ -0,0 +1,21 @@ +import java.net.http.*; + +public class HttpClient{ + public static String URL = "http://ip-api.com/json"; + public static void main(String args[]){ + System.out.println("Hello World"); + get(); + } + + public static void get() { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(URL)) + .build(); + client.sendAsync(request, BodyHandlers.ofString()) + .thenApply(HttpResponse::body) + .thenAccept(System.out::println) + .join(); + + } +} diff --git a/java/simple/Java8Lambda.java b/java/simple/Java8Lambda.java index c60ce67..17502d8 100644 --- a/java/simple/Java8Lambda.java +++ b/java/simple/Java8Lambda.java @@ -1,4 +1,3 @@ -package simple; public class Java8Lambda { public static void main(String args[]){ Java8Lambda jl = new Java8Lambda(); diff --git a/java/simple/JsonBean.java b/java/simple/JsonBean.java new file mode 100644 index 0000000..7bae304 --- /dev/null +++ b/java/simple/JsonBean.java @@ -0,0 +1,5 @@ +public class Json{ + public static void main(String[] args){ + System.out.println("Hello World"); + } +} diff --git a/java/simple/PomParser.java b/java/simple/PomParser.java new file mode 100644 index 0000000..db7a9c1 --- /dev/null +++ b/java/simple/PomParser.java @@ -0,0 +1,179 @@ +import java.io.File; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class PomParser { + + private String path; + private Document doc; + private String name; + private String packageing; + private String modelVersion; + private String groupId; + private String artifactId; + private String version; + private String url; + private Model parent; + + private PomParser(String path) { + this.path = path; + } + + public static PomParser parse(String path) { + PomParser pp = new PomParser(path); + pp.init(); + return pp; + } + + private void initDoc() { + try { + + File stocks = new File(this.path); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(stocks); + doc.getDocumentElement().normalize(); + this.doc = doc; + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private String getValueByDoc(String tag) { + String val = null; + NodeList nodes = this.doc.getElementsByTagName(tag); + if( nodes.getLength() > 0 ){ + NodeList cns = nodes.item(0).getChildNodes(); + if( cns.getLength() > 0 ){ + val = cns.item(0).getNodeValue(); + } + } + return val; + } + + private String getValueByEle(Element ele, String tag) { + String val = null; + NodeList nodes = ele.getElementsByTagName(tag); + if( nodes.getLength() > 0 ){ + NodeList cns = nodes.item(0).getChildNodes(); + if( cns.getLength() > 0 ){ + val = cns.item(0).getNodeValue(); + } + } + return val; + } + + private String getValueByTag(String parentTag, String tag) { + String val = null; + NodeList parentNodes = this.doc.getElementsByTagName(parentTag); + if( parentNodes.getLength() > 0 ){ + Element parentEle = (Element) parentNodes.item(0); + System.out.println(this.getValueByEle(parentEle, tag)); + } + return val; + } + + private void init() { + this.initDoc(); + + this.name = this.getValueByDoc("name"); + this.packageing = this.getValueByDoc("packageing"); + this.modelVersion = this.getValueByDoc("modelVersion"); + this.groupId = this.getValueByDoc("groupId"); + this.artifactId = this.getValueByDoc("artifactId"); + this.version = this.getValueByDoc("version"); + this.url = this.getValueByDoc("url"); + + NodeList parentNodes = this.doc.getElementsByTagName("parent"); + if( parentNodes.getLength() > 0 ){ + Element parentEle = (Element) parentNodes.item(0); + System.out.println(this.getValueByEle(parentEle, "groupId")); + } + + String parentGroupId = this.getValueByTag("parent", "groupId"); + String parentArtifactId = this.getValueByTag("parent", "artifactId"); + String parentVersion = this.getValueByTag("parent", "version"); + this.parent = new Model(parentGroupId, parentArtifactId, parentVersion); + + try { + + File stocks = new File(this.path); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(stocks); + doc.getDocumentElement().normalize(); + + // verEle = doc.getElementsByTagName("modelVersion").item(0); + // System.out.println(" ver" + verEle.getNodeValue()); + System.out.println(doc.getElementsByTagName("version").item(0).getChildNodes().item(0).getNodeValue()); + + System.out.println("root of xml file " + doc.getDocumentElement().getNodeName()); + NodeList nodes = doc.getElementsByTagName("stock"); + System.out.println("=========================="); + + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + System.out.println("Stock Symbol: " + getValue("symbol", element)); + System.out.println("Stock Price: " + getValue("price", element)); + System.out.println("Stock Quantity: " + getValue("quantity", element)); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public static void main(String args[]) { + PomParser pp = PomParser.parse("pom.xml"); + // try { + + // File stocks = new File("Stocks.xml"); + // DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + // DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + // Document doc = dBuilder.parse(stocks); + // doc.getDocumentElement().normalize(); + // // Document doc = parseXml("Stocks.xml"); + + // System.out.println("root of xml file " + doc.getDocumentElement().getNodeName()); + // NodeList nodes = doc.getElementsByTagName("stock"); + // System.out.println("=========================="); + + // for (int i = 0; i < nodes.getLength(); i++) { + // Node node = nodes.item(i); + + // if (node.getNodeType() == Node.ELEMENT_NODE) { + // Element element = (Element) node; + // System.out.println("Stock Symbol: " + getValue("symbol", element)); + // System.out.println("Stock Price: " + getValue("price", element)); + // System.out.println("Stock Quantity: " + getValue("quantity", element)); + // } + // } + // } catch (Exception ex) { + // ex.printStackTrace(); + // } + } + + private static String getValue(String tag, Element element) { + NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes(); + Node node = (Node) nodes.item(0); + return node.getNodeValue(); + } +} +class Model{ + private String groupId; + private String artifactId; + private String version; + + public Model(String groupId, String artifactId, String version) { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + } +} diff --git a/java/simple/Stocks.xml b/java/simple/Stocks.xml new file mode 100644 index 0000000..ff884b2 --- /dev/null +++ b/java/simple/Stocks.xml @@ -0,0 +1,15 @@ + + + + Citibank + 100 + 1000 + + + Axis bank + 90 + 2000 + + + + diff --git a/java/simple/Test.java b/java/simple/Test.java index 6c16daf..7e313da 100644 --- a/java/simple/Test.java +++ b/java/simple/Test.java @@ -1,6 +1,12 @@ +import java.util.Arrays; + public class Test1{ public static void main(String args[]){ System.out.println("Hello World"); + var name = "wxnacy"; + var array = Arrays.asList("wxnacy"); + System.out.println(array); + System.out.println(name); Test2.main(new String()); } } diff --git a/java/simple/XmlParse.java b/java/simple/XmlParse.java new file mode 100644 index 0000000..8b03a09 --- /dev/null +++ b/java/simple/XmlParse.java @@ -0,0 +1,49 @@ +import java.io.File; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class DOMExampleJava { + + public static void main(String args[]) { + try { + + Document doc = parseXml("Stocks.xml") + + System.out.println("root of xml file " + doc.getDocumentElement().getNodeName()); + NodeList nodes = doc.getElementsByTagName("stock"); + System.out.println("=========================="); + + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + System.out.println("Stock Symbol: " + getValue("symbol", element)); + System.out.println("Stock Price: " + getValue("price", element)); + System.out.println("Stock Quantity: " + getValue("quantity", element)); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private static Document parseXml(String filePath) { + File stocks = new File(filePath); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(stocks); + doc.getDocumentElement().normalize(); + return doc; + } + + private static String getValue(String tag, Element element) { + NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes(); + Node node = (Node) nodes.item(0); + return node.getNodeValue(); + } +} diff --git a/java/simple/get_class_list.java b/java/simple/get_class_list.java new file mode 100644 index 0000000..3f31ed1 --- /dev/null +++ b/java/simple/get_class_list.java @@ -0,0 +1,42 @@ +import java.util.List; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +/** + * Created by wxnacy + */ +public class ClassList { + + public static void main(String args[]) { + + ClassList cl = new ClassList(); + String path = "/Users/wxnacy/.m2/repository/com/alibaba/fastjson/1.1.34/fastjson-1.1.34.jar"; + List classList = cl.getClassList(path); + + } + + public List getClassList(String path) { + List list = new ArrayList(); + try { + JarFile jarFile = new JarFile(path); + Enumeration enu = jarFile.entries(); + while (enu.hasMoreElements()) { + JarEntry jarEntry = (JarEntry) enu.nextElement(); + String name = jarEntry.getName(); + if (name.endsWith(".class") && name.indexOf("$") == -1 ) { + name = name.substring(0, name.indexOf(".class")); + name = name.replaceAll("/", "."); + System.out.println(name); + list.add(name); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } + +} diff --git a/java/simple/get_class_list.sh b/java/simple/get_class_list.sh new file mode 100644 index 0000000..e69de29 diff --git a/java/simple/pom.xml b/java/simple/pom.xml new file mode 100644 index 0000000..b08df2d --- /dev/null +++ b/java/simple/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + com.wxnacy.spring + TMD + jar + 1.0-SNAPSHOT + TMD + http://maven.apache.org + + org.springframework.boot + spring-boot-starter-parent + 1.5.9.RELEASE + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-devtools + true + + + mysql + mysql-connector-java + + + + 1.8 + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + + + + + diff --git a/java/wj/WJ.java b/java/wj/WJ.java new file mode 100644 index 0000000..611add2 --- /dev/null +++ b/java/wj/WJ.java @@ -0,0 +1,5 @@ +public class WJ{ + public static void main(String[] args){ + System.out.println("Hello World"); + } +} diff --git a/java/wj/wj b/java/wj/wj new file mode 100755 index 0000000..e69de29 diff --git a/react/first/.gitignore b/react/first/.gitignore new file mode 100755 index 0000000..4d29575 --- /dev/null +++ b/react/first/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/react/first/README.md b/react/first/README.md new file mode 100755 index 0000000..9d9614c --- /dev/null +++ b/react/first/README.md @@ -0,0 +1,68 @@ +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting + +### Analyzing the Bundle Size + +This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size + +### Making a Progressive Web App + +This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app + +### Advanced Configuration + +This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration + +### Deployment + +This section has moved here: https://facebook.github.io/create-react-app/docs/deployment + +### `npm run build` fails to minify + +This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify diff --git a/react/first/package.json b/react/first/package.json new file mode 100644 index 0000000..bec79f2 --- /dev/null +++ b/react/first/package.json @@ -0,0 +1,25 @@ +{ + "name": "first", + "version": "0.1.0", + "private": true, + "dependencies": { + "react": "^16.7.0", + "react-dom": "^16.7.0", + "react-scripts": "2.1.3" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} diff --git a/react/first/public/favicon.ico b/react/first/public/favicon.ico new file mode 100755 index 0000000..a11777c Binary files /dev/null and b/react/first/public/favicon.ico differ diff --git a/react/first/public/index.html b/react/first/public/index.html new file mode 100755 index 0000000..323182f --- /dev/null +++ b/react/first/public/index.html @@ -0,0 +1,41 @@ + + + + + + + + + + + React App + + + +
+ + + diff --git a/react/first/public/manifest.json b/react/first/public/manifest.json new file mode 100755 index 0000000..1f2f141 --- /dev/null +++ b/react/first/public/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/react/first/src/App.css b/react/first/src/App.css new file mode 100755 index 0000000..92f956e --- /dev/null +++ b/react/first/src/App.css @@ -0,0 +1,32 @@ +.App { + text-align: center; +} + +.App-logo { + animation: App-logo-spin infinite 20s linear; + height: 40vmin; +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/react/first/src/App.js b/react/first/src/App.js new file mode 100755 index 0000000..7e261ca --- /dev/null +++ b/react/first/src/App.js @@ -0,0 +1,28 @@ +import React, { Component } from 'react'; +import logo from './logo.svg'; +import './App.css'; + +class App extends Component { + render() { + return ( +
+
+ logo +

+ Edit src/App.js and save to reload. +

+ + Learn React + +
+
+ ); + } +} + +export default App; diff --git a/react/first/src/App.test.js b/react/first/src/App.test.js new file mode 100755 index 0000000..a754b20 --- /dev/null +++ b/react/first/src/App.test.js @@ -0,0 +1,9 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; + +it('renders without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(, div); + ReactDOM.unmountComponentAtNode(div); +}); diff --git a/react/first/src/index.css b/react/first/src/index.css new file mode 100755 index 0000000..cee5f34 --- /dev/null +++ b/react/first/src/index.css @@ -0,0 +1,14 @@ +body { + margin: 0; + padding: 0; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", + "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", + monospace; +} diff --git a/react/first/src/index.js b/react/first/src/index.js new file mode 100755 index 0000000..0c5e75d --- /dev/null +++ b/react/first/src/index.js @@ -0,0 +1,12 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import * as serviceWorker from './serviceWorker'; + +ReactDOM.render(, document.getElementById('root')); + +// If you want your app to work offline and load faster, you can change +// unregister() to register() below. Note this comes with some pitfalls. +// Learn more about service workers: http://bit.ly/CRA-PWA +serviceWorker.unregister(); diff --git a/react/first/src/logo.svg b/react/first/src/logo.svg new file mode 100755 index 0000000..6b60c10 --- /dev/null +++ b/react/first/src/logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/react/first/src/serviceWorker.js b/react/first/src/serviceWorker.js new file mode 100755 index 0000000..2283ff9 --- /dev/null +++ b/react/first/src/serviceWorker.js @@ -0,0 +1,135 @@ +// This optional code is used to register a service worker. +// register() is not called by default. + +// This lets the app load faster on subsequent visits in production, and gives +// it offline capabilities. However, it also means that developers (and users) +// will only see deployed updates on subsequent visits to a page, after all the +// existing tabs open on the page have been closed, since previously cached +// resources are updated in the background. + +// To learn more about the benefits of this model and instructions on how to +// opt-in, read http://bit.ly/CRA-PWA + +const isLocalhost = Boolean( + window.location.hostname === 'localhost' || + // [::1] is the IPv6 localhost address. + window.location.hostname === '[::1]' || + // 127.0.0.1/8 is considered localhost for IPv4. + window.location.hostname.match( + /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ + ) +); + +export function register(config) { + if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { + // The URL constructor is available in all browsers that support SW. + const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); + if (publicUrl.origin !== window.location.origin) { + // Our service worker won't work if PUBLIC_URL is on a different origin + // from what our page is served on. This might happen if a CDN is used to + // serve assets; see https://github.com/facebook/create-react-app/issues/2374 + return; + } + + window.addEventListener('load', () => { + const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; + + if (isLocalhost) { + // This is running on localhost. Let's check if a service worker still exists or not. + checkValidServiceWorker(swUrl, config); + + // Add some additional logging to localhost, pointing developers to the + // service worker/PWA documentation. + navigator.serviceWorker.ready.then(() => { + console.log( + 'This web app is being served cache-first by a service ' + + 'worker. To learn more, visit http://bit.ly/CRA-PWA' + ); + }); + } else { + // Is not localhost. Just register service worker + registerValidSW(swUrl, config); + } + }); + } +} + +function registerValidSW(swUrl, config) { + navigator.serviceWorker + .register(swUrl) + .then(registration => { + registration.onupdatefound = () => { + const installingWorker = registration.installing; + if (installingWorker == null) { + return; + } + installingWorker.onstatechange = () => { + if (installingWorker.state === 'installed') { + if (navigator.serviceWorker.controller) { + // At this point, the updated precached content has been fetched, + // but the previous service worker will still serve the older + // content until all client tabs are closed. + console.log( + 'New content is available and will be used when all ' + + 'tabs for this page are closed. See http://bit.ly/CRA-PWA.' + ); + + // Execute callback + if (config && config.onUpdate) { + config.onUpdate(registration); + } + } else { + // At this point, everything has been precached. + // It's the perfect time to display a + // "Content is cached for offline use." message. + console.log('Content is cached for offline use.'); + + // Execute callback + if (config && config.onSuccess) { + config.onSuccess(registration); + } + } + } + }; + }; + }) + .catch(error => { + console.error('Error during service worker registration:', error); + }); +} + +function checkValidServiceWorker(swUrl, config) { + // Check if the service worker can be found. If it can't reload the page. + fetch(swUrl) + .then(response => { + // Ensure service worker exists, and that we really are getting a JS file. + const contentType = response.headers.get('content-type'); + if ( + response.status === 404 || + (contentType != null && contentType.indexOf('javascript') === -1) + ) { + // No service worker found. Probably a different app. Reload the page. + navigator.serviceWorker.ready.then(registration => { + registration.unregister().then(() => { + window.location.reload(); + }); + }); + } else { + // Service worker found. Proceed as normal. + registerValidSW(swUrl, config); + } + }) + .catch(() => { + console.log( + 'No internet connection found. App is running in offline mode.' + ); + }); +} + +export function unregister() { + if ('serviceWorker' in navigator) { + navigator.serviceWorker.ready.then(registration => { + registration.unregister(); + }); + } +}