{"id":13713610,"url":"https://github.com/jlchn/language-x","last_synced_at":"2025-05-07T00:31:41.148Z","repository":{"id":230675685,"uuid":"213105331","full_name":"jlchn/language-x","owner":"jlchn","description":"language x cheatsheet","archived":false,"fork":false,"pushed_at":"2020-01-21T09:31:00.000Z","size":71,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-14T00:34:01.514Z","etag":null,"topics":["basics","c","cheatsheet","go","java","javascript","language","shell"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlchn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-10-06T03:48:36.000Z","updated_at":"2023-12-28T08:57:24.000Z","dependencies_parsed_at":"2024-03-31T07:52:19.611Z","dependency_job_id":null,"html_url":"https://github.com/jlchn/language-x","commit_stats":null,"previous_names":["jlchn/language-x"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlchn%2Flanguage-x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlchn%2Flanguage-x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlchn%2Flanguage-x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlchn%2Flanguage-x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlchn","download_url":"https://codeload.github.com/jlchn/language-x/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252791479,"owners_count":21804779,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["basics","c","cheatsheet","go","java","javascript","language","shell"],"created_at":"2024-08-02T23:01:40.430Z","updated_at":"2025-05-07T00:31:40.867Z","avatar_url":"https://github.com/jlchn.png","language":null,"funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"\n# basic types, operators, expressions\n\n# control flow\n\n## if, if else, else if\n\n## loops (for, foreach, while, break, continue)\n\n### for\n\n\n```\n- go\n```go\nfor i := 0; i \u003c len(os.Args); i++ {\n  fmt.Println(os.Args[i])\n}\nfmt.Println(s)\n```\n\n## switch\n\n- python \n    - no switch-case in python\n\n\n# object or struct\n\n# pointers\n\n# functions\n\n\n### scope and external variables\n\n\n- shell\n\n``` bash\nf1(){\nlocal xxx=1\necho $xxx;\necho \"all variables in a function are global like in js, set it with local to make them local variables\"\necho \"local can only be used in a function\"\n}\n```\n\n## pass by value and pass by reference\n\n## dynamic length variable\n\n# array\n\n### array to stream\n\n- java\n\n``` java  \nString[] array = {\"a\", \"b\", \"c\", \"d\", \"e\"};\nStream\u003cString\u003e stream1 = Arrays.stream(array);\nstream1.forEach(x -\u003e System.out.println(x));\n```\n\n## array to map\n\n# list \n\n### initialization\n\n\n### access via index\n\n### add, upate the list\n\n### delete from the list\n\n### traverse the list\n\n\n### slice the list\n\n\n### sort the list\n\n### copy the list\n\n- python\n\n- python tuple\n\n### reverse the list\n\n### list to map \n\n- java\n\n``` java\nMap\u003cString, Item\u003e map = list.stream().filter(\n                vo -\u003e !vo.getEnvType().equals(\"commercial\"))\n                .collect(\n                        Collectors.toMap(vo -\u003e String.join(\"@\", vo.name(), vo.region()),\n                                vo -\u003e vo));\n```\n### numeric list operations\n\n# map\n\n### initialization\n\n\n### add, update map\n\n### delete from map\n\n### traverse the map\n\n\n# enum\n\n- java\n``` java\n// declare enum\npublic enum Day {\n    MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY\n}\n\n// print enum\nSystem.out.println(Day.MONDAY);//MONDAY\nSystem.out.println(Day.TUESDAY);//TUESDAY\nSystem.out.println(Day.WEDNESDAY);//WEDNESDAY\nSystem.out.println(Day.TUESDAY);//TUESDAY\nSystem.out.println(Day.FRIDAY);//FRIDAY\nSystem.out.println(Day.SATURDAY);//SATURDAY\nSystem.out.println(Day.SUNDAY);//SUNDAY\n\n// get enum by string\n\nDay day = Day.valueOf(\"FRIDAY\");\nSystem.out.println(day);//FRIDAY\nday = Day.valueOf(\"WRONG\");\nSystem.out.println(day);//Exception in thread \"main\" java.lang.IllegalArgumentException: No enum constant com.company.Day.WRONG\n\n// loop over enum\nfor (Day day : Day.values()){\n    System.out.println(day);\n}\n\n// switch by enum\nDay day = Day.FRIDAY;\nswitch (day){\n    case MONDAY:\n        System.out.println(0);\n        break;\n    case TUESDAY:\n        System.out.println(1);\n        break;\n    case WEDNESDAY:\n        System.out.println(2);\n        break;\n    case THURSDAY:\n        System.out.println(3);\n        break;\n    case FRIDAY:\n        System.out.println(4);\n        break;\n    case SATURDAY:\n        System.out.println(5);\n        break;\n    case SUNDAY:\n        System.out.println(6);\n        break;\n}\n\n// compare enum\nDay day = Day.FRIDAY;\nSystem.out.println(day==Day.FRIDAY);\n```\n\n# string\n\n### string initialization\n\n\n### length \n\n\n### to lower case and upper case\n\n### trim\n\n### start with and end with\n### contains and index of\n### join and split\n\n\n- java\n\n``` java\n\n// using String.join\nString result = String.join(\"-\", \"2015\", \"10\", \"31\" );// 2015-10-31\nString result = String.join(\", \", list);\n\n// using StringJoiner\nStringJoiner sj = new StringJoiner(\",\");\nsj.add(\"aaa\");\nsj.add(\"bbb\");\nString result = sj.toString(); // aaa,bbb\n\nStringJoiner sj = new StringJoiner(\"/\", \"prefix-\", \"-suffix\");\nsj.add(\"2016\");\nsj.add(\"02\");\nString result = sj.toString(); // prefix-2016/02-suffix\n\n// using lambda\nString result = list.stream().map(x -\u003e x).collect(Collectors.joining(\" | \"));\n\n```\n\n### slice the string\n\n### compare\n### title\n# type conversion\n\n# date and time\n\n# json\n\n- java gson\n\n``` xml\n/* To use Gson, add following to pom.xml  */\n\u003cdependency\u003e\n    \t\u003cgroupId\u003ecom.google.code.gson\u003c/groupId\u003e\n    \t\u003cartifactId\u003egson\u003c/artifactId\u003e\n    \t\u003cversion\u003e2.6.2\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n``` java\n// Convert java object to json string\nUser user = new User();\nString userInString = new Gson().toJson(user);\n\n// Convert json string to java object\nUser user = new Gson().from(userInString,User.class);\n\n// Convert json array to java List\nString jsonInstring = \"[{\\\"tenant\\\":\\\"Google\\\"}, {\\\"tenant\\\":\\\"Facebook\\\"}]\";\nList\u003cCustomer\u003e list = gson.fromJson(jsonInString, new TypeToken\u003cList\u003cCustomer\u003e\u003e(){}.getType());\nlist.forEach(x -\u003e System.out.println(x));\n\n// Convert json to java Map\nString jsonInstring = \"{\\\"tenant\\\":\\\"Google\\\", \\\"landscape\\\":\"develop\"}\";\nMap\u003cString, Object\u003e map = gson.fromJson(jsonInString, new TypeToken\u003cMap\u003cString, Object\u003e\u003e(){}.getType());\nmap.forEach((x,y)-\u003e System.out.println( x + \"-\" + y));\n```\n\n# module\n\n- python\n\n\n# class\n# errors and exceptions\n\n# file IO\n- java\n\n``` java\n// construct a file path\nPaths.get(part1,part2,part3,.....)\n// create file as well as dirs\nFiles.createDirectories(scriptPath.getParent());\nFiles.createFile(scriptPath);\n// get a file or dir, create if not exists\nFile dir = FileUtils.getFile(path);\n// delete a directory\nFileUtils.deleteDirectory(dir);\n// inputstream to file\nFileUtils.copyInputStreamToFile(x.getInputStream(), targetFile);\n```\n# network IO\n\n# object oriented programming\n\n## object lifecycle\n\n## object initialization\n\n## memory nodel\n\n## reflect \n\n## garbage collection\n\n\n# process \n\n# thread\n\n# format \n\n# read from stdin\n\n\n# test\n\n# dependency/package management\n\n## go\n\n``` bash\ngo get -u -v -f all # download all dependencies\n\n```\n\n## maven for java\n\n``` shell\nmvn dependency:tree # check dependency\n```\n\n## npm for node.js\n\n```bash\nnpm search db # locate the modules by keywords db\nnpm install commander@\"\u003e1.0.0\" # greater than version 1.0.0\nnpm install commander@1.0.0 # exactly matches version 1.0.0\nnpm install commander@\"=1.0.0\" # exactly matches version 1.0.0\nnpm install commander@\"~1.0.0\" # greater than or equal to version 1.0.0 , but less than the mexe major version\n\nnpm outdated [module-name] [-g] # display outdated packages [in golbal folder]\nnpm update [module-name] [-g]  # update outdated packages [in golbal folder]\n\nnpm adduser\nnpm publish\n\nnpm ls # view all the m-odules installed in current directory\nnpm ls -g # view all the modules installed in global directory\nnpm root -g # view the path that the global modules been installed\n\nnpm rm module-name # remove a module\n\n# linking packages is very useful if you are developing a module and want another project to reference your local copy of the module . \n# a linked package can be refered as if it were a global package , \n# which is very similar to module installation . \n#1. create global link\ncd my-project \u0026 npm link # now your 'my-project' is a global module , you can verify using npm ls -g \n#2. reference an existing link \ncd other-project \u0026 npm link my-project # link my-project as a module in your other-project \n#3.unlink package \ncd other-project \u0026 npm unlink my-project \ncd my-project \u0026 npm unlink \n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlchn%2Flanguage-x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlchn%2Flanguage-x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlchn%2Flanguage-x/lists"}