├── .github └── FUNDING.yml ├── .gitignore ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── LICENSE ├── PlutoniumOS ├── core │ ├── .gitignore │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── README.md │ ├── example │ │ └── index.js │ ├── lib │ │ ├── index.js │ │ ├── mouse │ │ │ └── index.js │ │ └── resolution │ │ │ └── index.js │ └── package.json ├── electronify │ ├── .gitignore │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── README.md │ ├── example │ │ ├── app │ │ │ ├── index.html │ │ │ ├── main.js │ │ │ └── style.css │ │ ├── index.js │ │ └── version.js │ ├── lib │ │ └── index.js │ └── package.json └── shell │ ├── .gitignore │ ├── README.md │ ├── launcher │ ├── app │ │ ├── api.js │ │ ├── default.png │ │ ├── index.js │ │ ├── leave.js │ │ └── run.js │ ├── client │ │ ├── hammer.js │ │ ├── index.js │ │ └── jquery.js │ ├── index.html │ ├── package.json │ └── style.css │ ├── start.js │ └── wallpaper │ ├── app │ ├── default.png │ ├── index.js │ └── wallpaper.js │ ├── client │ └── index.js │ ├── index.html │ └── package.json ├── README.md ├── _not-working └── caching │ └── server.js ├── address-to-geocode ├── .gitignore ├── README.md ├── index.js ├── package.json └── test │ └── index.js ├── algorithms ├── 1.js └── 2.js ├── array-form-data ├── app.js ├── bin │ └── www ├── package.json ├── public │ └── stylesheets │ │ └── style.css ├── routes │ ├── index.js │ └── users.js └── views │ ├── error.jade │ ├── index.jade │ └── layout.jade ├── async-await-with-arrays └── index.js ├── cheerio ├── README.md ├── htmlFile.html ├── main.js └── package.json ├── ciphers ├── index.js ├── package-lock.json └── package.json ├── classes └── index.js ├── commander ├── index.js └── package.json ├── comp └── package.json ├── connect-to-websocket └── index.js ├── data-stream ├── .gitignore ├── generate.js ├── package.json └── server.js ├── daty ├── index.js └── package.json ├── demo-server ├── index.js └── package.json ├── ejs ├── index.js └── package.json ├── elastic-search ├── index.js └── package.json ├── electron-clock ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app │ └── index.js ├── index.html └── package.json ├── env ├── index.js └── package.json ├── es6-extends └── index.js ├── file-upload ├── README.md ├── index.js ├── package.json ├── public │ ├── index.html │ └── uploads │ │ └── .gitignore └── test.js ├── formidable-mongodb ├── .gitignore ├── formidable-test.js ├── package.json ├── public │ └── index.html └── server.js ├── happy-birthday-jo ├── .gitignore ├── 1.js ├── README.md ├── jo.png └── package.json ├── hello-blah ├── .gitignore ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── README.md ├── example │ └── index.js ├── lib │ └── index.js ├── package.json └── test │ └── index.js ├── html-to-docx ├── index.js ├── package.json ├── test.docx ├── test1.doc └── test1.docx ├── html-to-pdf ├── .gitignore ├── README.md ├── index.js └── package.json ├── jasmine-test ├── index.html ├── js │ └── main.js ├── package.json └── spec │ ├── check-files.js │ ├── check-html.js │ └── support │ └── jasmine.json ├── js-score ├── .gitignore ├── LICENSE ├── README.md ├── foo.aup ├── glorify.ogg ├── lib │ └── index.js ├── package.json ├── test │ ├── communityamerica.zip │ ├── glorify.ogg │ ├── index.js │ └── songs │ │ ├── glorify.js │ │ ├── gober.js │ │ ├── gospel.js │ │ └── tmp.js ├── tmp.js └── vocal-exercises │ ├── .gitignore │ ├── 1.js │ ├── LICENSE │ ├── README.md │ ├── index.js │ └── package.json ├── jsdom ├── README.md ├── htmlFile.html ├── main.js └── package.json ├── json2md ├── index.js └── package.json ├── jwt-auth ├── index.js ├── keyFile.pem └── package.json ├── koa ├── index.js └── package.json ├── learning-es6 └── arrow-functions.js ├── limit-it └── index.js ├── login-with-bitbucket ├── .gitignore ├── README.md ├── bitbucket │ ├── abstract_api.js │ ├── authentication_test.js │ ├── email.js │ ├── email_test.js │ ├── index.js │ ├── repo.js │ ├── repo_test.js │ ├── request.js │ ├── secrets.js │ ├── ssh.js │ ├── ssh_test.js │ ├── user.js │ └── user_test.js ├── package.json └── server.js ├── login-with-github ├── .gitignore ├── README.md ├── package.json ├── public │ ├── index.html │ └── style.css └── server.js ├── longest-streak ├── README.md └── index.js ├── mongodb-map-reduce ├── .gitignore ├── README.md ├── package.json └── server.js ├── mongoose-sample-app ├── example │ └── index.js ├── lib │ └── index.js └── package.json ├── musicxml-to-json ├── foo.json ├── lib │ └── index.js └── test │ ├── 1.xml │ ├── 2.xml │ ├── 3.xml │ ├── My_First_Score.xml │ ├── foo.xml │ └── index.js ├── node-login ├── .gitignore ├── README.md ├── bitbucket-login.js ├── bitbucket │ ├── abstract_api.js │ ├── authentication_test.js │ ├── email.js │ ├── email_test.js │ ├── index.js │ ├── repo.js │ ├── repo_test.js │ ├── request.js │ ├── ssh.js │ ├── ssh_test.js │ ├── user.js │ └── user_test.js ├── github-login.js ├── package.json ├── public │ ├── 404.html │ ├── css │ │ └── style.css │ ├── editable │ │ ├── css │ │ │ └── bootstrap-editable.css │ │ ├── img │ │ │ ├── clear.png │ │ │ └── loading.gif │ │ ├── js │ │ │ ├── bootstrap-editable.js │ │ │ └── bootstrap-editable.min.js │ │ └── libs │ │ │ ├── bootstrap │ │ │ ├── css │ │ │ │ ├── bootstrap-responsive.css │ │ │ │ ├── bootstrap-responsive.min.css │ │ │ │ ├── bootstrap.css │ │ │ │ └── bootstrap.min.css │ │ │ ├── img │ │ │ │ ├── glyphicons-halflings-white.png │ │ │ │ └── glyphicons-halflings.png │ │ │ └── js │ │ │ │ ├── bootstrap.js │ │ │ │ └── bootstrap.min.js │ │ │ └── jquery │ │ │ └── jquery-1.8.2.min.js │ ├── error.html │ ├── img │ │ ├── 404.jpg │ │ ├── bitbucket-icon.png │ │ ├── github-icon.png │ │ └── spinner.gif │ ├── index.html │ ├── js │ │ └── client.js │ └── profile.html ├── secrets.template.js ├── server.js └── user.js ├── npm-programmatically ├── .gitignore ├── README.md ├── index.js └── tests │ └── package.json ├── nullish-coalescing └── index.js ├── optional-chaining └── index.js ├── orientdb └── index.js ├── package-lock.json ├── package.json ├── people-information-db ├── .gitignore ├── README.md ├── html.js ├── package.json └── server.js ├── phantom ├── google.pdf ├── index.js └── package.json ├── player.js ├── example │ ├── ._index.html │ └── index.html └── lib │ ├── player.css │ └── player.js ├── post-message ├── index.js ├── receiver │ └── html │ │ └── index.html └── sender │ └── html │ ├── .index.html.swp │ └── index.html ├── remarkable ├── index.js └── package.json ├── rename ├── index.js └── test │ └── foo │ └── a ├── score-scanner ├── ._out.png ├── lib │ ├── bubbles │ │ └── index.js │ ├── index.js │ └── portative │ │ └── index.js ├── out.png └── test │ ├── foo.png │ ├── fur-elise.png │ └── index.js ├── sequelizejs ├── README.md ├── books-issue.js ├── db.js ├── index.js ├── many-to-many.js ├── one-to-many.js ├── package.json └── remote.js ├── server-file-upload ├── package.json └── server.js ├── showdown ├── index.js └── package.json ├── streams ├── README.md ├── index.js └── package.json ├── templates-vs-paths └── index.js ├── using-sockjs ├── .gitignore ├── package.json ├── public │ └── index.html ├── readme.md └── server.js ├── web-sockets ├── package.json ├── public │ ├── html │ │ └── index.html │ └── js │ │ └── socket.io.js └── server.js ├── website-downloder ├── foo.js ├── lib │ └── index.js ├── package.json └── test │ ├── index.js │ └── localhost │ ├── api │ └── plugin-file │ │ └── lightbox │ │ └── css │ │ └── lightbox.css │ ├── favicon.ico │ ├── images │ └── logo.png │ ├── index.html │ └── theme │ └── css │ └── style.css ├── webview-electron ├── README.md ├── app.js ├── index.html └── package.json └── who-uses-me ├── index.js └── packages.json /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ionicabizau 2 | patreon: ionicabizau 3 | open_collective: ionicabizau 4 | custom: https://www.buymeacoffee.com/h96wwchmy -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules 6 | *.env 7 | .DS_Store 8 | package-lock.json 9 | .bloggify/* 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # 🌟 Contributing 2 | 3 | Want to contribute to this project? Great! Please read these quick steps to streamline the process and avoid unnecessary tasks. ✨ 4 | 5 | ## 💬 Discuss Changes 6 | Start by opening an issue in the repository using the [bug tracker][1]. Describe your proposed contribution or the bug you've found. If relevant, include platform info and screenshots. 🖼️ 7 | 8 | Wait for feedback before proceeding unless the fix is straightforward, like a typo. 📝 9 | 10 | ## 🔧 Fixing Issues 11 | 12 | Fork the project and create a branch for your fix, naming it `some-great-feature` or `some-issue-fix`. Commit changes while following the [code style][2]. If the project has tests, add one. ✅ 13 | 14 | If a `package.json` or `bower.json` exists, add yourself to the `contributors` array; create it if it doesn't. 🙌 15 | 16 | ```json 17 | { 18 | "contributors": [ 19 | "Your Name (http://your.website)" 20 | ] 21 | } 22 | ``` 23 | 24 | ## 📬 Creating a Pull Request 25 | Open a pull request and reference the initial issue (e.g., *fixes #*). Provide a clear title and consider adding visual aids for clarity. 📊 26 | 27 | ## ⏳ Wait for Feedback 28 | Your contributions will be reviewed. If feedback is given, update your branch as needed, and the pull request will auto-update. 🔄 29 | 30 | ## 🎉 Everyone Is Happy! 31 | Your contributions will be merged, and everyone will appreciate your effort! 😄❤️ 32 | 33 | Thanks! 🤩 34 | 35 | [1]: /issues 36 | [2]: https://github.com/IonicaBizau/code-style -------------------------------------------------------------------------------- /DOCUMENTATION.md: -------------------------------------------------------------------------------- 1 | ## Documentation 2 | 3 | You can see below the API reference of this module. 4 | 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-25 Ionică Bizău (https://ionicabizau.net) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PlutoniumOS/core/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules 6 | -------------------------------------------------------------------------------- /PlutoniumOS/core/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # :eight_spoked_asterisk: :stars: :sparkles: :dizzy: :star2: :star2: :sparkles: :dizzy: :star2: :star2: Contributing :star: :star2: :dizzy: :sparkles: :star: :star2: :dizzy: :sparkles: :stars: :eight_spoked_asterisk: 2 | 3 | So, you want to contribute to this project! That's awesome. However, before 4 | doing so, please read the following simple steps how to contribute. This will 5 | make the life easier and will avoid wasting time on things which are not 6 | requested. :sparkles: 7 | 8 | ## Discuss the changes before doing them 9 | - First of all, open an issue in the repository, using the [bug tracker][1], 10 | describing the contribution you would like to make, the bug you found or any 11 | other ideas you have. This will help us to get you started on the right 12 | foot. 13 | 14 | - If it makes sense, add the platform and software information (e.g. operating 15 | system, Node.JS version etc.), screenshots (so we can see what you are 16 | seeing). 17 | 18 | - It is recommended to wait for feedback before continuing to next steps. 19 | However, if the issue is clear (e.g. a typo) and the fix is simple, you can 20 | continue and fix it. 21 | 22 | ## Fixing issues 23 | - Fork the project in your account and create a branch with your fix: 24 | `some-great-feature` or `some-issue-fix`. 25 | 26 | - Commit your changes in that branch, writing the code following the 27 | [code style][2]. If the project contains tests (generally, the `test` 28 | directory), you are encouraged to add a test as well. :memo: 29 | 30 | - If the project contains a `package.json` or a `bower.json` file add yourself 31 | in the `contributors` array (or `authors` in the case of `bower.json`; 32 | if the array does not exist, create it): 33 | 34 | ```json 35 | { 36 | "contributors": [ 37 | "Your Name (http://your.website)" 38 | ] 39 | } 40 | ``` 41 | 42 | ## Creating a pull request 43 | 44 | - Open a pull request, and reference the initial issue in the pull request 45 | message (e.g. *fixes #*). Write a good description and 46 | title, so everybody will know what is fixed/improved. 47 | 48 | - If it makes sense, add screenshots, gifs etc., so it is easier to see what 49 | is going on. 50 | 51 | ## Wait for feedback 52 | Before accepting your contributions, we will review them. You may get feedback 53 | about what should be fixed in your modified code. If so, just keep committing 54 | in your branch and the pull request will be updated automatically. 55 | 56 | ## Everyone is happy! 57 | Finally, your contributions will be merged, and everyone will be happy! :smile: 58 | Contributions are more than welcome! 59 | 60 | Thanks! :sweat_smile: 61 | 62 | [1]: https://github.com/plutonium-os/plutonium-core/issues 63 | 64 | [2]: https://github.com/IonicaBizau/code-style -------------------------------------------------------------------------------- /PlutoniumOS/core/LICENSE: -------------------------------------------------------------------------------- 1 | The KINDLY License 2 | Copyright (c) 2015 Ionică Bizău (http://ionicabizau.net) 3 | 4 | You have the permission to use this software, read its source code, modify and 5 | redistribute it under the following terms: 6 | 7 | - if you want to use this software or include parts of its code in a 8 | closed-source or commercial project you should kindly ask the 9 | author (via a private message or email) and get a positive answer 10 | - this license should be included in the modified versions of this software 11 | - in case of redistributing modified copies, you are encouraged to clearly 12 | indicate that the copies are based on this work 13 | - if you think that your redistributed copy is awesome, you are encouraged to 14 | show the author of this software what you did and how you helped the others 15 | 16 | You are free to install and use this software on as many machines as you want, 17 | free of charge, making sure you met the terms above. 18 | 19 | You are encouraged to kindly support the software and its author by: 20 | 21 | - sharing his/her work 22 | - reporting issues/bugs and asking for feature requests 23 | - donating money or any other things that can help the author 24 | - contribute on the software code by fixing bugs and adding features 25 | -------------------------------------------------------------------------------- /PlutoniumOS/core/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | # plutonium-core [![Donate now][donate-now]][paypal-donations] 17 | 18 | The core module of the PlutoniumOS 19 | 20 | ## Installation 21 | 22 | ```sh 23 | $ npm i plutonium-core 24 | ``` 25 | 26 | ## Example 27 | 28 | ```js 29 | // Dependencies 30 | var PlutoniumOS = require("plutonium-core"); 31 | 32 | // Get resolution 33 | console.log(PlutoniumOS.Resolution.get()); 34 | 35 | ``` 36 | 37 | ## Documentation 38 | 39 | ## How to contribute 40 | Have an idea? Found a bug? See [how to contribute][contributing]. 41 | 42 | ## Who uses this 43 | If you are using this library in one of your projects, add it in this list. :sparkles: 44 | 45 | ## License 46 | [KINDLY][license] © [Ionică Bizău][website]–The [LICENSE](/LICENSE) file contains 47 | a copy of the license. 48 | 49 | [license]: http://ionicabizau.github.io/kindly-license/?author=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica@gmail.com%3E&year=2015 50 | [contributing]: /CONTRIBUTING.md 51 | [website]: http://ionicabizau.net 52 | [docs]: /DOCUMENTATION.md 53 | [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MG98D7NPFZ3MG 54 | [donate-now]: http://i.imgur.com/6cMbHOC.png 55 | -------------------------------------------------------------------------------- /PlutoniumOS/core/example/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var PlutoniumOS = require("../lib"); 3 | 4 | // Get resolution 5 | console.log(PlutoniumOS.Resolution.get()); 6 | -------------------------------------------------------------------------------- /PlutoniumOS/core/lib/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Resolution = require("./resolution") 3 | , Mouse = require("./mouse") 4 | ; 5 | 6 | // Create the PlutoniumOS Core 7 | var Plutonium = module.exports = {}; 8 | Plutonium.Resolution = Resolution; 9 | Plutonium.Mouse = Mouse; 10 | -------------------------------------------------------------------------------- /PlutoniumOS/core/lib/mouse/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Robot = require("robotjs"); 3 | 4 | var Mouse = module.exports = {}; 5 | 6 | Mouse.get = function () { 7 | return Robot.getMousePos(); 8 | }; 9 | 10 | Mouse.move = function (x, y) { 11 | return Robot.moveMouse(x, y); 12 | }; 13 | -------------------------------------------------------------------------------- /PlutoniumOS/core/lib/resolution/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require("screenres"); 2 | -------------------------------------------------------------------------------- /PlutoniumOS/core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "plutonium-core", 3 | "version": "1.0.0", 4 | "description": "The core module of the PlutoniumOS", 5 | "main": "lib/index.js", 6 | "directories": { 7 | "example": "example" 8 | }, 9 | "dependencies": { 10 | "screenres": "^2.0.3-rc1" 11 | }, 12 | "devDependencies": {}, 13 | "scripts": { 14 | "test": "echo \"Error: no test specified\" && exit 1" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+ssh://git@github.com/plutonium-os/plutonium-core.git" 19 | }, 20 | "keywords": [ 21 | "core", 22 | "plutonium" 23 | ], 24 | "author": "Ionică Bizău (http://ionicabizau.net)", 25 | "license": "KINDLY", 26 | "bugs": { 27 | "url": "https://github.com/plutonium-os/plutonium-core/issues" 28 | }, 29 | "homepage": "https://github.com/plutonium-os/plutonium-core#readme" 30 | } 31 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules 6 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # :eight_spoked_asterisk: :stars: :sparkles: :dizzy: :star2: :star2: :sparkles: :dizzy: :star2: :star2: Contributing :star: :star2: :dizzy: :sparkles: :star: :star2: :dizzy: :sparkles: :stars: :eight_spoked_asterisk: 2 | 3 | So, you want to contribute to this project! That's awesome. However, before 4 | doing so, please read the following simple steps how to contribute. This will 5 | make the life easier and will avoid wasting time on things which are not 6 | requested. :sparkles: 7 | 8 | ## Discuss the changes before doing them 9 | - First of all, open an issue in the repository, using the [bug tracker][1], 10 | describing the contribution you would like to make, the bug you found or any 11 | other ideas you have. This will help us to get you started on the right 12 | foot. 13 | 14 | - If it makes sense, add the platform and software information (e.g. operating 15 | system, Node.JS version etc.), screenshots (so we can see what you are 16 | seeing). 17 | 18 | - It is recommended to wait for feedback before continuing to next steps. 19 | However, if the issue is clear (e.g. a typo) and the fix is simple, you can 20 | continue and fix it. 21 | 22 | ## Fixing issues 23 | - Fork the project in your account and create a branch with your fix: 24 | `some-great-feature` or `some-issue-fix`. 25 | 26 | - Commit your changes in that branch, writing the code following the 27 | [code style][2]. If the project contains tests (generally, the `test` 28 | directory), you are encouraged to add a test as well. :memo: 29 | 30 | - If the project contains a `package.json` or a `bower.json` file add yourself 31 | in the `contributors` array (or `authors` in the case of `bower.json`; 32 | if the array does not exist, create it): 33 | 34 | ```json 35 | { 36 | "contributors": [ 37 | "Your Name (http://your.website)" 38 | ] 39 | } 40 | ``` 41 | 42 | ## Creating a pull request 43 | 44 | - Open a pull request, and reference the initial issue in the pull request 45 | message (e.g. *fixes #*). Write a good description and 46 | title, so everybody will know what is fixed/improved. 47 | 48 | - If it makes sense, add screenshots, gifs etc., so it is easier to see what 49 | is going on. 50 | 51 | ## Wait for feedback 52 | Before accepting your contributions, we will review them. You may get feedback 53 | about what should be fixed in your modified code. If so, just keep committing 54 | in your branch and the pull request will be updated automatically. 55 | 56 | ## Everyone is happy! 57 | Finally, your contributions will be merged, and everyone will be happy! :smile: 58 | Contributions are more than welcome! 59 | 60 | Thanks! :sweat_smile: 61 | 62 | [1]: https://github.com/IonicaBizau/electronify/issues 63 | 64 | [2]: https://github.com/IonicaBizau/code-style -------------------------------------------------------------------------------- /PlutoniumOS/electronify/LICENSE: -------------------------------------------------------------------------------- 1 | The KINDLY License 2 | Copyright (c) 2015 Ionică Bizău (http://ionicabizau.net) 3 | 4 | You have the permission to use this software, read its source code, modify and 5 | redistribute it under the following terms: 6 | 7 | - if you want to use this software or include parts of its code in a 8 | closed-source or commercial project you should kindly ask the 9 | author (via a private message or email) and get a positive answer 10 | - this license should be included in the modified versions of this software 11 | - in case of redistributing modified copies, you are encouraged to clearly 12 | indicate that the copies are based on this work 13 | - if you think that your redistributed copy is awesome, you are encouraged to 14 | show the author of this software what you did and how you helped the others 15 | 16 | You are free to install and use this software on as many machines as you want, 17 | free of charge, making sure you met the terms above. 18 | 19 | You are encouraged to kindly support the software and its author by: 20 | 21 | - sharing his/her work 22 | - reporting issues/bugs and asking for feature requests 23 | - donating money or any other things that can help the author 24 | - contribute on the software code by fixing bugs and adding features 25 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/example/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Electronify 6 | 7 | 8 | 9 |

Electronify

10 |

The simplest way to build Electron apps.

11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/example/app/main.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Remote = require("remote"); 3 | 4 | // Display the Electronify version 5 | version.innerHTML = Remote.require("./version"); 6 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/example/app/style.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Raleway:100); 2 | 3 | body { 4 | font-family: "Raleway", sans-serif; 5 | padding: 10px 155px; 6 | background-color: #ecf0f1; 7 | } 8 | 9 | h1 { 10 | font-size: 4em; 11 | text-align: center; 12 | text-shadow: 1px 2px 1px #c0392b; 13 | color: #e74c3c; 14 | border-bottom: 1px solid rgba(189, 195, 199, 0.39); 15 | padding-bottom: 20px; 16 | } 17 | 18 | p { 19 | font-size: 41px; 20 | text-align: center; 21 | text-shadow: 1px 1px 0px #bdc3c7; 22 | color: #2c3e50; 23 | } 24 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/example/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Electronify = require("../lib"); 3 | 4 | // Create the app 5 | var app = Electronify(__dirname + "/app/index.html", { 6 | resizable: false 7 | }); 8 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/example/version.js: -------------------------------------------------------------------------------- 1 | module.exports = require("../package").version; 2 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/lib/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var App = require("app") 3 | , BrowserWindow = require("browser-window") 4 | , Ul = require("ul") 5 | ; 6 | 7 | // Keep a global reference of the window object, if you don't, the window will 8 | // be closed automatically when the JavaScript object is GCed. 9 | var mainWindow = null; 10 | 11 | // Quit when all windows are closed. 12 | App.on("window-all-closed", function() { 13 | // On OS X it is common for applications and their menu bar 14 | // to stay active until the user quits explicitly with Cmd + Q 15 | if (process.platform != "darwin") { 16 | App.quit(); 17 | } 18 | }); 19 | 20 | var _isReady = false; 21 | 22 | /** 23 | * Electronify 24 | * Creates a new browser window based on Electron. 25 | * 26 | * @name Electronify 27 | * @function 28 | * @param {String} path The path to the HTML file. 29 | * @param {Object} options An object representing the browser window options. It has the following defaults: 30 | * 31 | * - `width` (Number): The window width (default: `800`). 32 | * - `height` (Number): The window height (default: `600`). 33 | * 34 | * @return {ElectronApp} The Electron app object extended with the following fields: 35 | * 36 | * - `mainWindow` (BrowserWindow): The browser window that was created. 37 | */ 38 | function Electronify(path, options) { 39 | if (!_isReady) { 40 | App.on("ready", function () { 41 | Electronify(path, options); 42 | }); 43 | return App; 44 | } 45 | 46 | // Defaults 47 | var bwOpts = Ul.merge(options, { 48 | width: 800 49 | , height: 600 50 | }); 51 | 52 | // Save the browser window 53 | App.mainWindow = new BrowserWindow(bwOpts); 54 | 55 | App.mainWindow.loadUrl("file://" + path); 56 | App.mainWindow.on("closed", function() { 57 | mainWindow = null; 58 | }); 59 | 60 | return App; 61 | } 62 | 63 | App.on("ready", function() { 64 | _isReady = true; 65 | }); 66 | 67 | module.exports = Electronify; 68 | -------------------------------------------------------------------------------- /PlutoniumOS/electronify/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electronify", 3 | "version": "1.0.1", 4 | "description": "The simplest way to build Electron apps.", 5 | "main": "lib/index.js", 6 | "directories": { 7 | "example": "example" 8 | }, 9 | "scripts": { 10 | "test": "electron example" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+ssh://git@github.com/IonicaBizau/electronify.git" 15 | }, 16 | "keywords": [ 17 | "electron", 18 | "applications", 19 | "desktop" 20 | ], 21 | "author": "Ionică Bizău (http://ionicabizau.net)", 22 | "license": "KINDLY", 23 | "bugs": { 24 | "url": "https://github.com/IonicaBizau/electronify/issues" 25 | }, 26 | "homepage": "https://github.com/IonicaBizau/electronify#readme", 27 | "blah": { 28 | "ex_img": "http://i.imgur.com/o5sBv1w.png", 29 | "h_img": "http://i.imgur.com/q2L4Qna.png", 30 | "title": "Electronify", 31 | "description": "[Electron](https://github.com/atom/electron) is amazing! Electronify makes its usage simpler by reusing the same code snippets in common apps." 32 | }, 33 | "devDependencies": { 34 | "electron-prebuilt": "^0.34.0" 35 | }, 36 | "dependencies": { 37 | "ul": "^5.0.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules 6 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/README.md: -------------------------------------------------------------------------------- 1 | Electron OS 2 | =========== 3 | 4 | An operating-system for the 21st century. 5 | 6 | This is powered by Linux and Electron. 7 | 8 | # Core Components 9 | 10 | - desktop shell 11 | - wallpaper 12 | - start programs 13 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/app/api.js: -------------------------------------------------------------------------------- 1 | var LauncherApp = module.exports = {}; 2 | 3 | var app = null; 4 | LauncherApp.init = function (a) { 5 | app = a; 6 | }; 7 | 8 | LauncherApp.show = function () { 9 | app.mainWindow.webContents.executeJavaScript("window.fnShow();"); 10 | app.mainWindow.show(); 11 | }; 12 | 13 | LauncherApp.hide = function () { 14 | var y = 10 15 | , x = 35 16 | , interval = setInterval(function () { 17 | console.log(x); 18 | app.mainWindow.setPosition(--x, y); 19 | if (x === -35) { 20 | clearInterval(interval); 21 | } 22 | }, 100) 23 | ; 24 | }; 25 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/app/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/PlutoniumOS/shell/launcher/app/default.png -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/app/index.js: -------------------------------------------------------------------------------- 1 | var Electronify = require("electronify") 2 | , IsThere = require("is-there") 3 | , Gkm = require("gkm") 4 | , Api = require("./api") 5 | ; 6 | 7 | var app = Electronify(__dirname + "/../index.html", { 8 | width: 200//500 9 | , height: 800 10 | , resizable: false 11 | , y: 10 12 | , x: 35 13 | , frame: false 14 | , "skip-taskbar": true 15 | , "always-on-top": true 16 | , transparent: true 17 | }); 18 | 19 | //app.on("ready", function () { 20 | // app.mainWindow.openDevTools(); 21 | //}); 22 | 23 | var isZeroX = 0 24 | , timer = null 25 | ; 26 | 27 | Api.init(app); 28 | 29 | Gkm.events.on('mouse.moved', function(data) { 30 | data = data[0].trim().split(",").map(Number); 31 | if (data[0] === 0) { 32 | if (++isZeroX === 10) { 33 | Api.show(); 34 | } 35 | } else { 36 | isZeroX = 0; 37 | } 38 | console.log(data); 39 | }); 40 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/app/leave.js: -------------------------------------------------------------------------------- 1 | var Api = require("./api"); 2 | 3 | module.exports = function (fn) { 4 | Api.hide(fn); 5 | }; 6 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/app/run.js: -------------------------------------------------------------------------------- 1 | var Spawn = require("child_process").spawn 2 | , Opn = require("opn") 3 | ; 4 | 5 | module.exports = function (input) { 6 | if (input.app) { 7 | Spawn(input.app); 8 | } 9 | 10 | if (input.url) { 11 | Opn(input.url); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/client/hammer.js: -------------------------------------------------------------------------------- 1 | Hammer = require("hammerjs") 2 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/client/index.js: -------------------------------------------------------------------------------- 1 | var Remote = require('remote') 2 | , Run = Remote.require("./run") 3 | , Api = Remote.require("./api") 4 | ; 5 | 6 | $(window).load(function() { 7 | var buttonCircles = $(".nav-circle"); 8 | 9 | $(".btn-nav").on("tap click", function() { 10 | $(this).toggleClass("closed-nav") 11 | if ($(this).hasClass("closed-nav")) { 12 | slideDown(); 13 | } else { 14 | slideUp() 15 | } 16 | }); 17 | 18 | $(".round-circle").click(function() { 19 | 20 | var $this = $(this) 21 | , app = $this.attr('data-app') 22 | , url = $this.attr('data-url') 23 | ; 24 | 25 | Run({ app: app, url: url }); 26 | 27 | $(".btn-nav").toggleClass("closed-nav"); 28 | slideUp(); 29 | }) 30 | 31 | function slideDown() { 32 | 33 | var topMargin = 20 34 | for (i = 0; i < buttonCircles.length; i++) { 35 | topMargin += 85 36 | $(buttonCircles[i]).animate({ 37 | top: topMargin 38 | }, 200, function() { 39 | $(".circle-container, .round-circle").css("visibility", "visible"); 40 | if ($(".fa-plus").hasClass("unRotateIcon")) { 41 | $(".fa-plus").removeClass("unRotateIcon").addClass("rotateIcon"); 42 | } else { 43 | $(".fa-plus").addClass("rotateIcon"); 44 | } 45 | 46 | }) 47 | } 48 | } 49 | 50 | function slideUp() { 51 | 52 | var resetTop = 20 53 | for (i = 0; i < buttonCircles.length; i++) { 54 | $(buttonCircles[i]).animate({ 55 | top: resetTop 56 | }, 200, function() { 57 | $(".circle-container, .round-circle").css("visibility", "hidden"); 58 | if ($(".fa-plus").hasClass("rotateIcon")) { 59 | $(".fa-plus").removeClass("rotateIcon").addClass("unRotateIcon"); 60 | } else { 61 | $(".fa-plus").addClass("unRotateIcon"); 62 | } 63 | }) 64 | } 65 | } 66 | }); 67 | 68 | window.fnShow = function (fn) { 69 | $("html").hide().fadeIn(fn); 70 | }; 71 | 72 | $(document).on("mouseleave", function () { 73 | // $("html").fadeOut(function () { 74 | Api.hide(); 75 | // }); 76 | }); 77 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/client/jquery.js: -------------------------------------------------------------------------------- 1 | $ = require("jquery"); 2 | jQuery = $; 3 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 |
16 | 19 | 22 | 25 | 28 |
29 |
30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/launcher/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "launcher", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "electron app --enable-transparent-visuals --disable-gpu" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "plutonium-core": "ssh://IonicaBizau@bitbucket.org:IonicaBizau/plutonium-core.git" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/start.js: -------------------------------------------------------------------------------- 1 | var Electroner = require("electroner") 2 | , Messager = require("messager") 3 | , Fs = require("fs") 4 | , IsThere = require("is-there") 5 | , Abs = require("abs") 6 | ; 7 | 8 | const LAUNCHER_PATH = __dirname + "/launcher/app" 9 | , WALLPAPER_PATH = __dirname + "/wallpaper/app" 10 | , SERVER_PATH = Abs("~/.plutonium/shell/main.sock") 11 | ; 12 | 13 | if (IsThere(SERVER_PATH)) { 14 | Fs.unlinkSync(SERVER_PATH); 15 | } 16 | 17 | var server = Messager.Server(SERVER_PATH); 18 | server.on("ready", function () { 19 | console.log("Plutonium Shell server is ready."); 20 | Electroner(LAUNCHER_PATH, { 21 | "enable-transparent-visuals": true 22 | , "disable-gpu": true 23 | }); 24 | }); 25 | server.on("launcherReady", function () { 26 | Electroner(WALLPAPER_PATH); 27 | }); 28 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/wallpaper/app/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/PlutoniumOS/shell/wallpaper/app/default.png -------------------------------------------------------------------------------- /PlutoniumOS/shell/wallpaper/app/index.js: -------------------------------------------------------------------------------- 1 | var Plutonium = require("plutonium-core") 2 | , Resolution = Plutonium.Resolution 3 | , Messager = require("messager") 4 | , Abs = require("abs") 5 | , Electronify = require("electronify") 6 | ; 7 | 8 | const LAUNCHER_PATH = Abs("~/.plutonium/shell/launcher.sock") 9 | var res = Resolution.get(); 10 | 11 | var launcherClient = Messager.Client(LAUNCHER_PATH); 12 | launcherClient.on("error", function (err) { 13 | console.log(err); 14 | }); 15 | 16 | var app = Electronify(__dirname + "/../index.html", { 17 | width: res[0] 18 | , height: res[1] 19 | , resizable: false 20 | , frame: false 21 | , type: "desktop" 22 | }); 23 | app.on("ready", function () { 24 | app.mainWindow.on("focus", function () { 25 | launcherClient.send("activateWindow"); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/wallpaper/app/wallpaper.js: -------------------------------------------------------------------------------- 1 | exports.get = function (callback) { 2 | callback(null, process.env.WALLPAPER || __dirname + "/default.png"); 3 | }; 4 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/wallpaper/client/index.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | 4 | debugger 5 | var Remote = require('remote') 6 | , Wallpaper = Remote.require("./wallpaper") 7 | ; 8 | 9 | Wallpaper.get(function (err, data) { 10 | document.getElementById("wallpaper").setAttribute("src", data); 11 | }); 12 | }, 1000); 13 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/wallpaper/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /PlutoniumOS/shell/wallpaper/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-os", 3 | "description": "An operating-system for the 21st century.", 4 | "version": "1.0.0", 5 | "devDependencies": { 6 | "electron-prebuilt": "^0.31.2", 7 | "electron-rebuild": "^1.0.0", 8 | "screenres": "ionicabizaukitchen/screenres", 9 | "plutonium-core": "ssh://IonicaBizau@bitbucket.org:IonicaBizau/plutonium-core.git" 10 | }, 11 | "scripts": { 12 | "start": "electron app" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /_not-working/caching/server.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Http = require("http") 3 | 4 | // Constants 5 | const CACHE_SIZE = 100; 6 | 7 | // Last modified 8 | var lastMod = new Date(); 9 | 10 | // Create server 11 | Http.createServer(function (req, res) { 12 | 13 | var mtime = lastMod 14 | , clientETag = req.headers["if-none-match"] 15 | , clientMTime = Date.parse(req.headers["if-modified-since"]) 16 | , contentToSend = "Hello World!" 17 | , contentType = "text" 18 | , headers = { 19 | "Etag": JSON.stringify([0, contentToSend, mtime].join("-")) 20 | , "Date": (new Date()).toUTCString() 21 | , "Last-Modified": lastMod.toUTCString() 22 | , "Content-Type": contentType 23 | , "Content-Length": contentToSend.length 24 | } 25 | ; 26 | 27 | debugger 28 | // File is cached 29 | if ((clientMTime || clientETag) && 30 | (!clientETag || clientETag === headers["Etag"]) && 31 | (!clientMTime || clientMTime >= mtime)) { 32 | // 304 response should not contain entity headers 33 | ["Content-Encoding", 34 | "Content-Language", 35 | "Content-Length", 36 | "Content-Location", 37 | "Content-MD5", 38 | "Content-Range", 39 | "Content-Type", 40 | "Expires", 41 | "Last-Modified"].forEach(function(entityHeader) { 42 | delete headers[entityHeader]; 43 | }); 44 | 45 | res.writeHead(304, headers); 46 | res.end(contentToSend); 47 | return; 48 | } 49 | 50 | // Set cache-control header 51 | headers["cache-control"] = "max-age=" + CACHE_SIZE; 52 | res.writeHead(200, headers); 53 | res.end(contentToSend); 54 | }).listen(8000, function (err) { 55 | console.log(err || "Listening on 8000."); 56 | }); 57 | -------------------------------------------------------------------------------- /address-to-geocode/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules -------------------------------------------------------------------------------- /address-to-geocode/README.md: -------------------------------------------------------------------------------- 1 | # address-to-geocode 2 | A test using node-geocode module 3 | 4 | ## Installation 5 | Run the following commands to download and install the application: 6 | 7 | ```sh 8 | $ git clone https://github.com/IonicaBizau/address-to-geocode.git address-to-geocode 9 | $ cd address-to-geocode 10 | $ npm install 11 | ``` 12 | 13 | ## Example 14 | 15 | ```js 16 | // My Location 17 | var myLocation = "New York"; 18 | 19 | // Handler to output data 20 | var handler = function (err, location) { 21 | if (err) { throw err; } 22 | console.log(location); 23 | }; 24 | 25 | require("../index") 26 | (myLocation, handler) 27 | ("Paris", handler) 28 | ; 29 | ``` 30 | 31 | ## Documentation 32 | ### `AddressToGeocode(address, callback)` 33 | Converts a string representing an address to geocode data. 34 | 35 | #### Params: 36 | * **String** *address* The searched location 37 | * **Function** *callback* The callback function 38 | 39 | #### Return: 40 | * **Object** AddressToGeocode function 41 | 42 | ### `AddressToGeocode.handleLocation(guess)` 43 | A function that handles the location. This can be overriden creating your own handler. 44 | 45 | #### Params: 46 | * **Array** *guess* Locations returned by Geocoder 47 | 48 | #### Return: 49 | * **Object** An object containing `lat` and `lng` fields. 50 | 51 | ## How to contribute 52 | 53 | 1. File an issue in the repository, using the bug tracker, describing the 54 | contribution you'd like to make. This will help us to get you started on the 55 | right foot. 56 | 2. Fork the project in your account and create a new branch: 57 | `your-great-feature`. 58 | 3. Commit your changes in that branch. 59 | 4. Open a pull request, and reference the initial issue in the pull request 60 | message. 61 | 62 | ## License 63 | See the [LICENSE](./LICENSE) file. 64 | -------------------------------------------------------------------------------- /address-to-geocode/index.js: -------------------------------------------------------------------------------- 1 | // Dependnecies 2 | var Geocoder = require("node-geocoder").getGeocoder("google"); 3 | 4 | /** 5 | * AddressToGeocode 6 | * Converts a string representing an address to geocode data. 7 | * 8 | * @name AddressToGeocode 9 | * @function 10 | * @param {String} address The searched location 11 | * @param {Function} callback The callback function 12 | * @return {Object} AddressToGeocode function 13 | */ 14 | var AddressToGeocode = function (address, callback) { 15 | Geocoder.geocode({ 16 | address: address 17 | }, function(err, guess) { 18 | if (err) { return callback(err); } 19 | callback(null, AddressToGeocode.handleLocation(guess)); 20 | }); 21 | return AddressToGeocode; 22 | }; 23 | 24 | /** 25 | * handleLocation 26 | * 27 | * @name handleLocation 28 | * @function 29 | * @param {Array} guess Locations returned by Geocoder 30 | * @return {Object} An object containing `lat` and `lng` fields. 31 | */ 32 | AddressToGeocode.handleLocation = function (guess) { 33 | if (!guess || !guess.length) { 34 | return {}; 35 | } 36 | return { 37 | lat: guess[0].latitude, 38 | lng: guess[0].longitude 39 | }; 40 | }; 41 | 42 | module.exports = AddressToGeocode; 43 | -------------------------------------------------------------------------------- /address-to-geocode/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "address-to-geocode", 3 | "version": "0.2.0", 4 | "description": "A test using node-geocode module", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node test/index" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/IonicaBizau/address-to-geocode.git" 12 | }, 13 | "keywords": [ 14 | "geocode", 15 | "node", 16 | "location" 17 | ], 18 | "dependencies": { 19 | "node-geocoder": "2.6.0" 20 | }, 21 | "author": "jillix ", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/IonicaBizau/address-to-geocode/issues" 25 | }, 26 | "homepage": "https://github.com/IonicaBizau/address-to-geocode" 27 | } 28 | -------------------------------------------------------------------------------- /address-to-geocode/test/index.js: -------------------------------------------------------------------------------- 1 | // My Location 2 | var myLocation = "New York"; 3 | 4 | // Handler to output data 5 | var handler = function (err, location) { 6 | if (err) { throw err; } 7 | console.log(location); 8 | }; 9 | 10 | require("../index") 11 | (myLocation, handler) 12 | ("Paris", handler) 13 | ; 14 | -------------------------------------------------------------------------------- /algorithms/1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Devise a function that takes an input 'n' (integer) and returns a string that is the 3 | * decimal representation of the number grouped by commas after every 3 digits. Do not 4 | * solve the task using a built-in formatting function that can accomplish the whole 5 | * task on its own. 6 | * 7 | * Assume: 0 <= n < 1000000000 8 | * 9 | * 1 -> "1" 10 | * 10 -> "10" 11 | * 100 -> "100" 12 | * 1000 -> "1,000" 13 | * 10000 -> "10,000" 14 | * 100000 -> "100,000" 15 | * 1000000 -> "1,000,000" 16 | * 35235235 -> "35,235,235" 17 | * 999999999 -> "999,999,999" 18 | */ 19 | 20 | const GROUP_LENGTH = 3; 21 | 22 | function Solution(n) { 23 | n = n.toString(); 24 | var groups = []; 25 | while (n) { 26 | if (n.length < GROUP_LENGTH) { 27 | groups.push(n); 28 | break; 29 | } 30 | groups.push(n.substr(-GROUP_LENGTH)); 31 | n = n.substr(0, n.length - GROUP_LENGTH); 32 | } 33 | return groups.reverse().join(","); 34 | } 35 | 36 | console.log(Solution(1)); 37 | console.log(Solution(10)); 38 | console.log(Solution(100)); 39 | console.log(Solution(1000)); 40 | console.log(Solution(10000)); 41 | console.log(Solution(100000)); 42 | console.log(Solution(1000000)); 43 | console.log(Solution(35235235)); 44 | console.log(Solution(999999999)); 45 | -------------------------------------------------------------------------------- /algorithms/2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A number is called a circular prime if it is prime and all of its rotations are primes. 3 | * 4 | * For example the number 197 has two rotations: 971, and 719. Both of them are prime. 5 | * 6 | * There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. 7 | * 8 | * How many circular primes are there below N? 9 | * 10 | * 1 <= N <= 1000000 11 | * 12 | * Test Cases 13 | * 14 | * There are 0 circular primes below 1. 15 | * There are 4 circular primes below 10. 16 | * There are 13 circular primes below 100. 17 | * There are 25 circular primes below 1000. 18 | * There are 33 circular primes below 10000. 19 | * There are 43 circular primes below 100000. 20 | * There are 55 circular primes below 1000000. 21 | */ 22 | 23 | function isPrime(c) { 24 | if (c === 1) { 25 | return false; 26 | } 27 | 28 | for (var i = 2; i < c; ++i) { 29 | if (c % i === 0) { 30 | return false; 31 | } 32 | } 33 | return true; 34 | } 35 | 36 | var map = {}; 37 | 38 | function rotations(n) { 39 | if (map[n]) { 40 | return map[n]; 41 | } 42 | var str = n.toString() 43 | , rot = [] 44 | , digits = str.split("").map(function (c) { 45 | return Number(c); 46 | }) 47 | ; 48 | 49 | if (digits.length === 1) { 50 | return [n]; 51 | } 52 | 53 | function rotate(k) { 54 | return Number(digits.slice(k).concat(digits.slice(0, k)).join("")); 55 | } 56 | 57 | for (i = 0; i < digits.length; ++i) { 58 | rot.push(rotate(i)); 59 | } 60 | 61 | return map[n] = rot; 62 | } 63 | 64 | function isCircularPrime(n) { 65 | var rot = rotations(n) 66 | , i = 0 67 | , c = null 68 | ; 69 | 70 | for (; i < rot.length; ++i) { 71 | c = rot[i]; 72 | if (!isPrime(c)) { 73 | return false; 74 | } 75 | } 76 | 77 | return true; 78 | } 79 | 80 | function Solution(n) { 81 | var count = 0; 82 | for (var i = 1; i <= n; ++i) { 83 | if (isCircularPrime(i)) { 84 | ++count; 85 | } 86 | } 87 | return count; 88 | } 89 | 90 | var tests = [ 91 | 1 92 | , 10 93 | , 100 94 | , 1000 95 | , 10000 96 | , 100000 97 | , 1000000 98 | , 10000000 99 | ]; 100 | 101 | tests.forEach(function (c) { 102 | console.log("There are " + Solution(c) + " circular primes below " + c); 103 | }); 104 | -------------------------------------------------------------------------------- /array-form-data/app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var path = require('path'); 3 | var favicon = require('serve-favicon'); 4 | var logger = require('morgan'); 5 | var cookieParser = require('cookie-parser'); 6 | var bodyParser = require('body-parser'); 7 | 8 | var index = require('./routes/index'); 9 | var users = require('./routes/users'); 10 | 11 | var app = express(); 12 | 13 | // view engine setup 14 | app.set('views', path.join(__dirname, 'views')); 15 | app.set('view engine', 'jade'); 16 | 17 | // uncomment after placing your favicon in /public 18 | //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); 19 | app.use(logger('dev')); 20 | app.use(bodyParser.json()); 21 | app.use(bodyParser.urlencoded({ extended: true })); 22 | app.use(cookieParser()); 23 | app.use(express.static(path.join(__dirname, 'public'))); 24 | 25 | app.get('/', index); 26 | app.post("/", (req, res) => { 27 | res.json(req.body); 28 | }); 29 | app.use('/users', users); 30 | 31 | // catch 404 and forward to error handler 32 | app.use(function(req, res, next) { 33 | var err = new Error('Not Found'); 34 | err.status = 404; 35 | next(err); 36 | }); 37 | 38 | // error handler 39 | app.use(function(err, req, res, next) { 40 | // set locals, only providing error in development 41 | res.locals.message = err.message; 42 | res.locals.error = req.app.get('env') === 'development' ? err : {}; 43 | 44 | // render the error page 45 | res.status(err.status || 500); 46 | res.render('error'); 47 | }); 48 | 49 | module.exports = app; 50 | -------------------------------------------------------------------------------- /array-form-data/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('array-form-data:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' 62 | ? 'Pipe ' + port 63 | : 'Port ' + port; 64 | 65 | // handle specific listen errors with friendly messages 66 | switch (error.code) { 67 | case 'EACCES': 68 | console.error(bind + ' requires elevated privileges'); 69 | process.exit(1); 70 | break; 71 | case 'EADDRINUSE': 72 | console.error(bind + ' is already in use'); 73 | process.exit(1); 74 | break; 75 | default: 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Event listener for HTTP server "listening" event. 82 | */ 83 | 84 | function onListening() { 85 | var addr = server.address(); 86 | var bind = typeof addr === 'string' 87 | ? 'pipe ' + addr 88 | : 'port ' + addr.port; 89 | debug('Listening on ' + bind); 90 | } 91 | -------------------------------------------------------------------------------- /array-form-data/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "array-form-data", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "body-parser": "~1.16.0", 10 | "cookie-parser": "~1.4.3", 11 | "debug": "~2.6.0", 12 | "express": "~4.14.1", 13 | "jade": "~1.11.0", 14 | "morgan": "~1.10.0", 15 | "serve-favicon": "~2.3.2" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /array-form-data/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /array-form-data/routes/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET home page. */ 5 | router.get('/', function(req, res, next) { 6 | res.render('index', { title: 'Express' }); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /array-form-data/routes/users.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET users listing. */ 5 | router.get('/', function(req, res, next) { 6 | res.send('respond with a resource'); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /array-form-data/views/error.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= message 5 | h2= error.status 6 | pre #{error.stack} 7 | -------------------------------------------------------------------------------- /array-form-data/views/index.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= title 5 | p Welcome to #{title} 6 | form(method="post") 7 | input(name="mentees[]", placeholder="Mentee 1") 8 | input(name="mentees[]", placeholder="Mentee 2") 9 | input(name="mentees[]", placeholder="Mentee 3") 10 | input(name="mentees[]", placeholder="Mentee 4") 11 | input(type="submit", value="Submit") 12 | -------------------------------------------------------------------------------- /array-form-data/views/layout.jade: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | title= title 5 | link(rel='stylesheet', href='/stylesheets/style.css') 6 | body 7 | block content 8 | -------------------------------------------------------------------------------- /async-await-with-arrays/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const getArrayOfPromises = async () => { 4 | return [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)]; 5 | }; 6 | 7 | const mapOverEntries = async () => { 8 | const data = await getArrayOfPromises(); 9 | const arrayOfResolvedPromises = await Promise.all(await data.map(async (entry) => await entry )); 10 | arrayOfResolvedPromises.forEach(entry => console.log(entry)); 11 | }; 12 | 13 | const reduceOverEntries = async () => { 14 | const data = await getArrayOfPromises(); 15 | const updatedData = await data.reduce(async (acc, entry) => { 16 | const accumulator = await acc; 17 | const resolvedEntry = await entry; 18 | accumulator.push(resolvedEntry + 1); 19 | return accumulator; 20 | }, Promise.resolve([])); 21 | updatedData.forEach(entry => console.log(entry)); 22 | }; 23 | 24 | const runEverything = async () => { 25 | console.log('First we will map over the entries and print them to the console'); 26 | await mapOverEntries(); 27 | console.log('Then we will add 1 to each entry through our reduce function and print them to the console again'); 28 | await reduceOverEntries(); 29 | } 30 | 31 | runEverything(); -------------------------------------------------------------------------------- /cheerio/README.md: -------------------------------------------------------------------------------- 1 | Cheerio 2 | ======= 3 | 4 | ```sh 5 | cd cheerio 6 | npm i 7 | node main.js 8 | ``` 9 | 10 | ## How to use 11 | 12 | ```js 13 | // Include cheerio 14 | var cheerio = require("cheerio"); 15 | 16 | // Load some HTML 17 | var $ = cheerio.load(""); 18 | 19 | // Append a new element 20 | $("body").append("hi"); 21 | 22 | // Output the final HTML 23 | console.log($.html()); 24 | // => "hi" 25 | ``` 26 | 27 | ## Resources 28 | 29 | Big thanks to the [Cheerio project](https://github.com/MatthewMueller/cheerio#readme)! 30 | -------------------------------------------------------------------------------- /cheerio/htmlFile.html: -------------------------------------------------------------------------------- 1 |

Testing the Cheerio NodeJS module.

2 | 3 |
4 |
Some text in template
5 |
6 | 7 |
8 |
Some text in template
9 |
10 | -------------------------------------------------------------------------------- /cheerio/main.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var cheerio = require("cheerio") 3 | , readFile = require("read-utf8") 4 | ; 5 | 6 | // Read the HTML file 7 | var html = readFile("./htmlFile.html"); 8 | 9 | //

Testing the jsDom NodeJS module.

10 | var $ = cheerio.load(html); 11 | 12 | // Apend some html 13 | $("p").append("Appending..."); 14 | console.log($.html()); 15 | console.log("------------------------------"); 16 | 17 | // Create an input 18 | var input = $(""); 19 | input.val("Test"); 20 | input.attr("type", "text"); 21 | $("p").after(input); 22 | 23 | console.log($.html()); 24 | console.log("Wow, going to ★ Star the cheerio repository."); 25 | 26 | // How to clone 27 | var $templ = $(".template").clone(); 28 | $templ.find(".text").text("Changed"); 29 | $templ.removeClass("template"); 30 | 31 | $(".template").after($templ); 32 | 33 | console.log($.html()); 34 | 35 | // Clone another template 36 | var $templ = $("[data-key='template']").clone(); 37 | $templ.find(".text").text("Changed"); 38 | $templ.removeClass("template"); 39 | 40 | $("[data-key='template']").after($templ); 41 | 42 | console.log($.html()); 43 | -------------------------------------------------------------------------------- /cheerio/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learning-node-cheerio-test", 3 | "dependencies": { 4 | "cheerio": "^0.19.0", 5 | "read-utf8": "^1.0.0" 6 | }, 7 | "description": "Learning how to manipulate DOM using Node.js", 8 | "version": "1.0.0", 9 | "main": "main.js", 10 | "devDependencies": {}, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+ssh://git@github.com/IonicaBizau/learning-nodejs.git" 17 | }, 18 | "keywords": [ 19 | "learning", 20 | "nodejs", 21 | "cheerio", 22 | "dom", 23 | "manipultation" 24 | ], 25 | "author": "Ionică Bizău (http://ionicabizau.net)", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/IonicaBizau/learning-nodejs/issues" 29 | }, 30 | "homepage": "https://github.com/IonicaBizau/learning-nodejs#readme" 31 | } -------------------------------------------------------------------------------- /ciphers/index.js: -------------------------------------------------------------------------------- 1 | const VigenereCipher = require('text-ciphers').VigenereCipher; 2 | const vigenereCipher = new VigenereCipher({ 3 | keyword: 'coduri' 4 | }); 5 | const deciphered = vigenereCipher.decipher('oionluqmniyzxjwreemvyhorkxinbtvkiangxr'); 6 | console.log(deciphered); 7 | -------------------------------------------------------------------------------- /ciphers/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ciphers", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "text-ciphers": { 8 | "version": "0.5.2", 9 | "resolved": "https://registry.npmjs.org/text-ciphers/-/text-ciphers-0.5.2.tgz", 10 | "integrity": "sha1-Opgx8/Hp/HC2ggUaVGS+qXCnux0=" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ciphers/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ciphers", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "text-ciphers": "^0.5.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /classes/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | class Foo { 4 | method (name) { 5 | console.log("Foo: ", name); 6 | } 7 | method2 (name) { 8 | console.log("Foo: ", name); 9 | } 10 | } 11 | 12 | class Bar extends Foo { 13 | constructor () { 14 | super(); 15 | } 16 | method (name) { 17 | console.log("Bar: ", name); 18 | } 19 | } 20 | 21 | var b = new Bar(); 22 | b.method("test"); 23 | b.method2("test"); 24 | -------------------------------------------------------------------------------- /commander/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { program } = require('commander'); 4 | 5 | program 6 | .command('hello') 7 | .description('for when you just need someone to talk to') 8 | .action(() => console.log('well, hello there!')); 9 | 10 | program 11 | .command('shields') 12 | .option('-p, --percent ', 'divert a percentage of the ships power to shields (must be a number)') 13 | .action((args) => { 14 | const percent = args.percent; 15 | if (isNaN(percent) || percent < 0 || percent > 100) { 16 | console.log('input must exist and be a number between 0 and 100. run "shields -h" for help'); 17 | } else { 18 | console.log(`diverting ${percent}% of power to shields!`); 19 | } 20 | }); 21 | 22 | program.parse(process.argv); -------------------------------------------------------------------------------- /commander/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "commanderjs", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "commander": "^6.1.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /comp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "comp", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "compromise": "^10.7.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /connect-to-websocket/index.js: -------------------------------------------------------------------------------- 1 | var socket = require('socket.io-client')('http://localhost:8080'); 2 | socket.on('connect', function(){ 3 | console.log(">> Connect"); 4 | }); 5 | socket.on('welcome', function(data){ 6 | console.log(data); 7 | }); 8 | socket.on('disconnect', function(){ 9 | console.log(">> Disconnect>"); 10 | }); 11 | -------------------------------------------------------------------------------- /data-stream/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *~ 3 | -------------------------------------------------------------------------------- /data-stream/generate.js: -------------------------------------------------------------------------------- 1 | var mongo = require("mongodb"); 2 | 3 | var db = new mongo.Db("stream", new mongo.Server("localhost", 27017), { w: 1 }); 4 | 5 | function checkError(err) { 6 | if (err) { 7 | console.error(err); 8 | process.exit(1); 9 | } 10 | } 11 | 12 | db.open(function(err, db) { 13 | 14 | checkError(err); 15 | 16 | db.collection("item", function(err, collection) { 17 | 18 | checkError(err); 19 | 20 | collection.remove(function(err) { 21 | 22 | checkError(err); 23 | 24 | var SIZE = 200000; 25 | var count = 0; 26 | 27 | for (var i = 0; i < SIZE; i++) { 28 | var item = { 29 | name: "Gabriel Petrovay " + (i + 1), 30 | number: i, 31 | randomString: random(25) 32 | }; 33 | collection.insert(item, function() { 34 | console.log("Inserted " + count); 35 | if (++count === SIZE) { 36 | db.close(); 37 | } 38 | }); 39 | } 40 | }); 41 | }); 42 | 43 | }); 44 | 45 | 46 | function random(length) { 47 | 48 | if (typeof length !== 'number' || length < 1) { 49 | length = 10; 50 | } 51 | 52 | var text = ""; 53 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 54 | 55 | for (var i = 0; i < length; i++) { 56 | text += possible[Math.floor(Math.random() * possible.length)]; 57 | } 58 | 59 | return text; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /data-stream/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stream", 3 | "version": "0.0.1", 4 | "dependencies" : { 5 | "mongodb": "*" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /daty/index.js: -------------------------------------------------------------------------------- 1 | // At the beginning of the file 2 | const Daty = require("daty"); 3 | const gen = require("generate-google-calendar-url"); 4 | 5 | const ev = { 6 | date: new Date() 7 | , title: "hey" 8 | , description: "foo" 9 | }; 10 | 11 | const ev_date = new Daty(ev.date); 12 | const dateFormat = "YYYYMMDDTHHmmss"; 13 | 14 | ev_date.setHours(19); 15 | const start_date = ev_date.utc().format(dateFormat) + "Z"; 16 | const end_date = ev_date.utc().add(2, "hours").format(dateFormat) + "Z"; 17 | 18 | const link = "http://www.google.com/calendar/event?" 19 | + "action=TEMPLATE" 20 | + "&text=" + ev.title 21 | + "&dates=" + start_date + '/' + end_date 22 | + "&details=" + ev.description; 23 | 24 | console.log(link); 25 | console.log(gen({ 26 | start: new Date(ev_date), 27 | end: new Date(ev_date.clone().add(2, "hours")), 28 | title: 'Hey', 29 | location: 'Paris', 30 | details: 'http://event.description.example.com/11234' 31 | })); 32 | -------------------------------------------------------------------------------- /daty/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "daty-example", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "daty": "^1.0.11", 14 | "generate-google-calendar-url": "0.0.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /demo-server/index.js: -------------------------------------------------------------------------------- 1 | require("http").createServer(function (req, res) { 2 | res.end("Hello World"); 3 | }).listen(process.env.PORT || 8081); 4 | -------------------------------------------------------------------------------- /demo-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /ejs/index.js: -------------------------------------------------------------------------------- 1 | const ejs = require('ejs'); 2 | var str = `<% posts.forEach(function (c) { -%> 3 | <%= c -%> 4 | s are great 5 | <% }) %>`; 6 | 7 | console.log(ejs.render(str, { 8 | posts: ["Apple", "Pear", "Orange"] 9 | })); 10 | -------------------------------------------------------------------------------- /ejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ejs-testing", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "ejs": "^2.4.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /elastic-search/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const elasticsearch = require("elasticsearch") 4 | , faker = require("faker") 5 | ; 6 | 7 | let client = new elasticsearch.Client({ 8 | host: "localhost:9200", 9 | log: "trace" 10 | }); 11 | 12 | if (process.argv.indexOf("--insert")) { 13 | for (let i = 0; i < 1e3; ++i) { 14 | client.index({ 15 | index: "users", 16 | type: "user", 17 | id: i, 18 | body: faker.helpers.userCard() 19 | }, function (err, res) { 20 | console.log(err || res); 21 | }); 22 | } 23 | } else { 24 | client.index({ 25 | index: "users", 26 | type: "user", 27 | id: i, 28 | body: faker.helpers.userCard() 29 | }, function (err, res) { 30 | console.log(err || res); 31 | }); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /elastic-search/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learn-elastic-search", 3 | "version": "1.0.0", 4 | "description": "Learning ES.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "elasticsearch": "^12.0.1", 13 | "faker": "^3.1.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /electron-clock/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # :eight_spoked_asterisk: :stars: :sparkles: :dizzy: :star2: :star2: :sparkles: :dizzy: :star2: :star2: Contributing :star: :star2: :dizzy: :sparkles: :star: :star2: :dizzy: :sparkles: :stars: :eight_spoked_asterisk: 2 | 3 | So, you want to contribute to this project! That's awesome. However, before 4 | doing so, please read the following simple steps how to contribute. This will 5 | make the life easier and will avoid wasting time on things which are not 6 | requested. :sparkles: 7 | 8 | ## Discuss the changes before doing them 9 | - First of all, open an issue in the repository, using the [bug tracker][1], 10 | describing the contribution you would like to make, the bug you found or any 11 | other ideas you have. This will help us to get you started on the right 12 | foot. 13 | 14 | - If it makes sense, add the platform and software information (e.g. operating 15 | system, Node.JS version etc.), screenshots (so we can see what you are 16 | seeing). 17 | 18 | - It is recommended to wait for feedback before continuing to next steps. 19 | However, if the issue is clear (e.g. a typo) and the fix is simple, you can 20 | continue and fix it. 21 | 22 | ## Fixing issues 23 | - Fork the project in your account and create a branch with your fix: 24 | `some-great-feature` or `some-issue-fix`. 25 | 26 | - Commit your changes in that branch, writing the code following the 27 | [code style][2]. If the project contains tests (generally, the `test` 28 | directory), you are encouraged to add a test as well. :memo: 29 | 30 | - If the project contains a `package.json` or a `bower.json` file add yourself 31 | in the `contributors` array (or `authors` in the case of `bower.json`; 32 | if the array does not exist, create it): 33 | 34 | ```json 35 | { 36 | "contributors": [ 37 | "Your Name (http://your.website)" 38 | ] 39 | } 40 | ``` 41 | 42 | ## Creating a pull request 43 | 44 | - Open a pull request, and reference the initial issue in the pull request 45 | message (e.g. *fixes #*). Write a good description and 46 | title, so everybody will know what is fixed/improved. 47 | 48 | - If it makes sense, add screenshots, gifs etc., so it is easier to see what 49 | is going on. 50 | 51 | ## Wait for feedback 52 | Before accepting your contributions, we will review them. You may get feedback 53 | about what should be fixed in your modified code. If so, just keep committing 54 | in your branch and the pull request will be updated automatically. 55 | 56 | ## Everyone is happy! 57 | Finally, your contributions will be merged, and everyone will be happy! :smile: 58 | Contributions are more than welcome! 59 | 60 | Thanks! :sweat_smile: 61 | 62 | [1]: https://github.com/IonicaBizau/launcher/issues 63 | 64 | [2]: https://github.com/IonicaBizau/code-style -------------------------------------------------------------------------------- /electron-clock/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ionică Bizău (http://ionicabizau.net) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /electron-clock/README.md: -------------------------------------------------------------------------------- 1 | # electron-clock [![PayPal](https://img.shields.io/badge/%24-paypal-f39c12.svg)][paypal-donations] [![Version](https://img.shields.io/npm/v/electron-clock.svg)](https://www.npmjs.com/package/electron-clock) [![Downloads](https://img.shields.io/npm/dt/electron-clock.svg)](https://www.npmjs.com/package/electron-clock) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github) 2 | 3 | > A nice clock for your desktop. 4 | 5 | ## How to contribute 6 | Have an idea? Found a bug? See [how to contribute][contributing]. 7 | 8 | ## License 9 | 10 | [MIT][license] © [Ionică Bizău][website] 11 | 12 | [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW 13 | [donate-now]: http://i.imgur.com/6cMbHOC.png 14 | 15 | [license]: http://showalicense.com/?fullname=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica%40gmail.com%3E%20(http%3A%2F%2Fionicabizau.net)&year=2016#license-mit 16 | [website]: http://ionicabizau.net 17 | [contributing]: /CONTRIBUTING.md 18 | [docs]: /DOCUMENTATION.md -------------------------------------------------------------------------------- /electron-clock/app/index.js: -------------------------------------------------------------------------------- 1 | const Electronify = require("electronify"); 2 | 3 | Electronify(`${__dirname}/../index.html`, { 4 | width: 580 5 | , height: 200 6 | , y: 1600 7 | , x: 1820 8 | , transparent: true 9 | , frame: false 10 | , resizable: false 11 | , "skip-taskbar": true 12 | }); 13 | -------------------------------------------------------------------------------- /electron-clock/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 |

22 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /electron-clock/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-clock", 3 | "description": "A nice clock for your desktop.", 4 | "version": "1.0.0", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "start": "electron app --enable-transparent-visuals --disable-gpu" 8 | }, 9 | "license": "MIT", 10 | "dependencies": { 11 | "electron-prebuilt": "^0.36.10", 12 | "electronify": "^1.3.1" 13 | }, 14 | "author": "Ionică Bizău (http://ionicabizau.net)", 15 | "repository": { 16 | "type": "git", 17 | "url": "git+ssh://git@github.com/IonicaBizau/launcher.git" 18 | }, 19 | "bugs": { 20 | "url": "https://github.com/IonicaBizau/launcher/issues" 21 | }, 22 | "homepage": "https://github.com/IonicaBizau/launcher#readme" 23 | } 24 | -------------------------------------------------------------------------------- /env/index.js: -------------------------------------------------------------------------------- 1 | const 2 | -------------------------------------------------------------------------------- /env/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "stringify-env": "^1.0.0-beta1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /es6-extends/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | class Person { 4 | constructor (name) { 5 | this.name = name; 6 | } 7 | getName () { 8 | return this.name; 9 | } 10 | } 11 | 12 | class Worker extends Person { 13 | constructor (name, type) { 14 | super(name); 15 | this.type = type; 16 | } 17 | work () { 18 | console.log(this.getName() + " is working."); 19 | console.log(this.getName() + " is a " + this.getType() + "."); 20 | } 21 | getType () { 22 | return this.type; 23 | } 24 | } 25 | 26 | var w = new Worker("Johnny", "builder"); 27 | w.work(); 28 | -------------------------------------------------------------------------------- /file-upload/README.md: -------------------------------------------------------------------------------- 1 | Upload files 2 | ============ 3 | 4 | 5 | ```sh 6 | cd file-upload 7 | npm i 8 | node index 9 | ``` 10 | 11 | Read the detailed article about this project [here](http://ionicabizau.net/blog/22-upload-files-using-nodejs). 12 | -------------------------------------------------------------------------------- /file-upload/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Lien = require("lien") 3 | , Fs = require("fs") 4 | , Formidable = require("formidable") 5 | ; 6 | 7 | // Constants 8 | const DIR_UPLOADS = __dirname + "/public/uploads/"; 9 | 10 | // Init lien server 11 | var server = new Lien({ 12 | host: "localhost" 13 | , port: 9000 14 | }); 15 | 16 | // Add page 17 | server.page.add("/", function (lien) { 18 | lien.file("/index.html"); 19 | }); 20 | 21 | // Upload 22 | server.page.add("/upload$", function (lien) { 23 | var form = new Formidable.IncomingForm( 24 | { uploadDir: DIR_UPLOADS } 25 | ); 26 | form.parse(lien.req, function (err, fields, files) { 27 | if (!files.file) { 28 | return lien.end("File is missing.", 400); 29 | } 30 | 31 | Fs.rename(files.file.path, DIR_UPLOADS + files.file.name, function (err) { 32 | if (err) { 33 | return lien.end(err, 400); 34 | } 35 | lien.redirect("/"); 36 | }); 37 | }); 38 | }); 39 | 40 | // List 41 | server.page.add("/upload/list", function (lien) { 42 | Fs.readdir(DIR_UPLOADS, function (err, files) { 43 | if (err) { return lien.end(err, 500); } 44 | files = files.filter(function (c) { 45 | return c !== ".gitignore"; 46 | }); 47 | 48 | var list = ["
    ", files.map(function (c) { 49 | return ["
  • ", "", c, "
  • "].join(""); 50 | }).join(""), "
"].join(""); 51 | 52 | lien.end(list); 53 | }); 54 | }); 55 | -------------------------------------------------------------------------------- /file-upload/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learning-node-file-upload", 3 | "version": "1.0.0", 4 | "description": "Learning how file uploads work in a NodeJS server.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git@github.com:IonicaBizau/learning-nodejs.git" 12 | }, 13 | "keywords": [ 14 | "file", 15 | "upload", 16 | "nodejs" 17 | ], 18 | "author": "Ionică Bizău (http://ionicabizau.net)", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/IonicaBizau/learning-nodejs/issues" 22 | }, 23 | "homepage": "https://github.com/IonicaBizau/learning-nodejs", 24 | "dependencies": { 25 | "formidable": "^1.0.17", 26 | "lien": "^0.0.8" 27 | }, 28 | "devDependencies": {} 29 | } -------------------------------------------------------------------------------- /file-upload/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | File upload 6 | 7 | 8 |
9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /file-upload/public/uploads/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /file-upload/test.js: -------------------------------------------------------------------------------- 1 | var formidable = require('formidable'), 2 | http = require('http'), 3 | util = require('util'); 4 | 5 | http.createServer(function(req, res) { 6 | if (req.url == '/upload' && req.method.toLowerCase() == 'post') { 7 | // parse a file upload 8 | var form = new formidable.IncomingForm(); 9 | 10 | form.parse(req, function(err, fields, files) { 11 | res.writeHead(200, {'content-type': 'text/plain'}); 12 | res.write('received upload:\n\n'); 13 | res.end(util.inspect({fields: fields, files: files})); 14 | }); 15 | 16 | return; 17 | } 18 | 19 | // show a file upload form 20 | res.writeHead(200, {'content-type': 'text/html'}); 21 | res.end( 22 | '
'+ 23 | '
'+ 24 | '
'+ 25 | ''+ 26 | '
' 27 | ); 28 | }).listen(8080); 29 | -------------------------------------------------------------------------------- /formidable-mongodb/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *~ 3 | -------------------------------------------------------------------------------- /formidable-mongodb/formidable-test.js: -------------------------------------------------------------------------------- 1 | var formidable = require('formidable'), 2 | http = require('http'), 3 | util = require('util') 4 | static = require('node-static'); 5 | 6 | var file = new(static.Server)('./public'); 7 | 8 | 9 | http.createServer(function(req, res) { 10 | if (req.url == '/upload' && req.method.toLowerCase() == 'post') { 11 | // parse a file upload 12 | var form = new formidable.IncomingForm(); 13 | 14 | form.parse(req, function(err, fields, files) { 15 | res.writeHead(200, {'content-type': 'text/plain'}); 16 | res.write('received upload:\n\n'); 17 | res.end(util.inspect({fields: fields, files: files})); 18 | }); 19 | 20 | return; 21 | } 22 | 23 | req.on('end', function(){ 24 | file.serve(req, res); 25 | }); 26 | }).listen(8080); 27 | -------------------------------------------------------------------------------- /formidable-mongodb/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lesson3", 3 | "version": "0.0.1", 4 | "dependencies": { 5 | "mongodb": "*", 6 | "node-static": "*", 7 | "formidable" : "*" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /formidable-mongodb/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |

Insert the data, and press Submit button

5 |
6 | 7 | First Name:
8 | Last Name:
9 | Age:
10 | Gender: Male 11 | Female
12 | 13 | 14 | 15 |
16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /formidable-mongodb/server.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | var static = require('node-static'); 3 | var mongo = require('mongodb'); 4 | var formidable = require('formidable'); 5 | 6 | // Mongo server 7 | var server = mongo.Server("127.0.0.1", 27017); 8 | var db = new mongo.Db('peopleInformationDb', server, { safe: true }); 9 | 10 | // Node static: public_html folder 11 | var file = new(static.Server)('./public'); 12 | 13 | // Create server 14 | var srv = http.createServer(function(req, res){ 15 | if(req.method === "GET"){ 16 | file.serve(req, res); 17 | } 18 | else{ 19 | var form = new formidable.IncomingForm(); 20 | var fieldsInformation = null; 21 | form.parse(req, function(err, fields) { 22 | fieldsInformation = fields; 23 | }); 24 | 25 | db.open(function(err, db) { 26 | if (err) return res.end("A problem occurred. Try again later."); 27 | 28 | db.collection("col_one", function(err, myCol) { 29 | if (err) return res.end("A problem occurred. Try again later."); 30 | 31 | var objectToInsert = { 32 | "firstName" : fieldsInformation.firstName, 33 | "lastName" : fieldsInformation.lastName, 34 | "age" : fieldsInformation.age, 35 | "gender" : fieldsInformation.gender, 36 | }; 37 | 38 | myCol.insert(objectToInsert, function(){ 39 | res.end("Successfully saved."); 40 | db.close(); 41 | }); 42 | }); 43 | }); 44 | } 45 | }); 46 | 47 | srv.listen(8080); 48 | -------------------------------------------------------------------------------- /happy-birthday-jo/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules -------------------------------------------------------------------------------- /happy-birthday-jo/1.js: -------------------------------------------------------------------------------- 1 | var Overlap = require ("overlap") 2 | , JAsciimo = require ("jasciimo").Figlet 3 | , Couleurs = require ("couleurs") 4 | , ImageToAscii = require ("image-to-ascii") 5 | , myImage = new ImageToAscii ({ 6 | resize: { 7 | height: "100%" 8 | , width: "50%" 9 | } 10 | , colored: true 11 | , multiplyWidth:1 12 | }) 13 | ; 14 | 15 | 16 | myImage.convert("./jo.png", function(err, converted) { 17 | console.log(converted); 18 | setTimeout(function () { 19 | 20 | var words = [ 21 | "Today".rgb(227, 32, 32) 22 | , "is".rgb(227, 165, 32) 23 | , "a".rgb(220, 227, 32) 24 | , "special".rgb(110, 227, 32) 25 | , "day".rgb(32, 136, 227) + "!" 26 | ] 27 | , i = -1 28 | , interval = setInterval(function () { 29 | var w = words[++i]; 30 | if (!w) { 31 | clearInterval(interval); 32 | return setTimeout(function () { 33 | JAsciimo.write("Happy", "starwars", function(happy) { 34 | JAsciimo.write("Birthday", "Cricket", function(birthday) { 35 | JAsciimo.write("Jo Luijten", "Basic", function(name) { 36 | console.log( 37 | Overlap({ 38 | // happy birthday 39 | who: Overlap({ 40 | who: happy 41 | , with: birthday 42 | , where: { 43 | x: 10 44 | , y: 4 45 | } 46 | }) 47 | // name 48 | , with: name 49 | , where: { 50 | x: 20 51 | , y: 13 52 | } 53 | }) 54 | ) 55 | }); 56 | }); 57 | }); 58 | }, 1000); 59 | } 60 | console.log(w) 61 | }, 700) 62 | ; 63 | }, 3000) 64 | }); 65 | -------------------------------------------------------------------------------- /happy-birthday-jo/README.md: -------------------------------------------------------------------------------- 1 | Happy-Birthday-Jo 2 | ================= 3 | 4 | A happy birthday application for Jo Luijten - http://www.joluijten.com/ 5 | 6 | ## How to run 7 | 8 | ```sh 9 | $ git clone git@github.com:IonicaBizau/Happy-Birthday-Jo.git hbj 10 | $ cd hbj 11 | $ npm install 12 | $ npm test 13 | ``` 14 | 15 | ## Demo 16 | 17 | > [![](http://i.imgur.com/r5PUDNM.png)](https://asciinema.org/a/9104) 18 | 19 | ## License 20 | See the LICENSE file. 21 | -------------------------------------------------------------------------------- /happy-birthday-jo/jo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/happy-birthday-jo/jo.png -------------------------------------------------------------------------------- /happy-birthday-jo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "happy-birthday-jo", 3 | "version": "0.1.0", 4 | "description": "A happy birthday application for Jo Luijten - http://www.joluijten.com/ ", 5 | "main": "1.js", 6 | "dependencies": { 7 | "couleurs": "^0.1.2", 8 | "image-to-ascii": "^0.1.1", 9 | "jasciimo": "^0.6.0", 10 | "overlap": "^0.1.0" 11 | }, 12 | "devDependencies": {}, 13 | "scripts": { 14 | "test": "node 1.js" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git@github.com:IonicaBizau/Happy-Birthday-Jo.git" 19 | }, 20 | "keywords": [ 21 | "jo", 22 | "luijten", 23 | "birthday", 24 | "node", 25 | "terminal" 26 | ], 27 | "author": "Ionică Bizău ", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/IonicaBizau/Happy-Birthday-Jo/issues" 31 | }, 32 | "homepage": "https://github.com/IonicaBizau/Happy-Birthday-Jo" 33 | } 34 | -------------------------------------------------------------------------------- /hello-blah/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules 6 | -------------------------------------------------------------------------------- /hello-blah/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # :eight_spoked_asterisk: :stars: :sparkles: :dizzy: :star2: :star2: :sparkles: :dizzy: :star2: :star2: Contributing :star: :star2: :dizzy: :sparkles: :star: :star2: :dizzy: :sparkles: :stars: :eight_spoked_asterisk: 2 | 3 | So, you want to contribute to this project! That's awesome. However, before 4 | doing so, please read the following simple steps how to contribute. This will 5 | make the life easier and will avoid wasting time on things which are not 6 | requested. :sparkles: 7 | 8 | ## Discuss the changes before doing them 9 | - First of all, open an issue in the repository, using the bug tracker 10 | describing the contribution you'd like to make, the bug you found or any 11 | other ideas you have. This will help us to get you started on the right 12 | foot. 13 | 14 | - If it makes sense, add the platform and software information (e.g. operating 15 | system, Node.JS version etc), screenshots (so we can see what you're seeing). 16 | 17 | - It's recommended to wait for feedback before continuing to next steps. However, 18 | if the issue is clear (e.g. a typo) and the fix is simple, you can continue 19 | and fix it. 20 | 21 | ## Fixing issues 22 | - Fork the project in your account and create a branch with your fix: 23 | `some-great-feature` or `some-issue-fix`. 24 | 25 | - Commit your changes in that branch, writing the code following the 26 | [code style][2]. If the project contains tests (generally, the `test` 27 | directory), you are encouraged to add a test as well. :memo: 28 | 29 | - If the project contains a `package.json` file add yourself in the 30 | `contributors` array (if it doesn't exist, create it): 31 | 32 | ```json 33 | { 34 | "contributors": [ 35 | "Your Name (http://your.website) 36 | ] 37 | } 38 | ``` 39 | 40 | ## Creating a pull request 41 | 42 | - Open a pull request, and reference the initial issue in the pull request 43 | message (e.g. *fixes #!* message. 6 | 7 | #### Params 8 | - **String** `world`: The world you want to say *Hello* to (default: `"World"`). 9 | 10 | #### Return 11 | - **String** The *Hello !* message. 12 | 13 | -------------------------------------------------------------------------------- /hello-blah/README.md: -------------------------------------------------------------------------------- 1 | # blah-test [![Support this project][donate-now]][paypal-donations] 2 | 3 | Testing the new version of blah. 4 | 5 | ## Installation 6 | 7 | ```sh 8 | $ npm i --save blah-test 9 | ``` 10 | 11 | ## Example 12 | 13 | ```js 14 | // Require the library file 15 | var HelloBlah = require("blah-test"); 16 | 17 | // Call the function exported by library 18 | HelloBlah(); 19 | HelloBlah("Blah"); 20 | ``` 21 | 22 | ## Documentation 23 | 24 | ### `HelloBlah(world)` 25 | Displays and returns a *Hello !* message. 26 | 27 | #### Params 28 | - **String** `world`: The world you want to say *Hello* to (default: `"World"`). 29 | 30 | #### Return 31 | - **String** The *Hello !* message. 32 | 33 | ## How to contribute 34 | Have an idea? Found a bug? See [how to contribute][contributing]. 35 | 36 | ## Where is this library used? 37 | If you are using this library in one of your projects, add it in this list. :sparkles: 38 | 39 | ## License 40 | 41 | [MIT][license] © [Ionică Bizău][website] 42 | 43 | [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW 44 | [donate-now]: http://i.imgur.com/6cMbHOC.png 45 | 46 | [license]: http://showalicense.com/?fullname=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica%40gmail.com%3E%20(http%3A%2F%2Fionicabizau.net)&year=2013#license-mit 47 | [website]: http://ionicabizau.net 48 | [contributing]: /CONTRIBUTING.md 49 | [docs]: /DOCUMENTATION.md 50 | -------------------------------------------------------------------------------- /hello-blah/example/index.js: -------------------------------------------------------------------------------- 1 | // Require the library file 2 | var HelloBlah = require("../lib"); 3 | 4 | // Call the function exported by library 5 | HelloBlah(); 6 | HelloBlah("Blah"); 7 | -------------------------------------------------------------------------------- /hello-blah/lib/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * HelloBlah 3 | * Displays and returns a *Hello !* message. 4 | * 5 | * @name HelloBlah 6 | * @function 7 | * @param {String} world The world you want to say *Hello* to (default: `"World"`). 8 | * @return {String} The *Hello !* message. 9 | */ 10 | function HelloBlah(world) { 11 | world = world || "World"; 12 | var message = "Hello " + world + "!"; 13 | console.log(message); 14 | return message; 15 | } 16 | 17 | module.exports = HelloBlah; 18 | -------------------------------------------------------------------------------- /hello-blah/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blah-test", 3 | "version": "1.0.0", 4 | "description": "Testing the new version of blah.", 5 | "main": "lib/index.js", 6 | "directories": { 7 | "example": "example", 8 | "test": "test" 9 | }, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Ionică Bizău (http://ionicabizau.net)", 14 | "license": "MIT" 15 | } -------------------------------------------------------------------------------- /hello-blah/test/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/hello-blah/test/index.js -------------------------------------------------------------------------------- /html-to-docx/index.js: -------------------------------------------------------------------------------- 1 | const htmlDocxJs = require("html-to-docx") 2 | const fs = require("fs") 3 | 4 | const html = ` 5 | 6 | 7 | 8 | 9 | 10 | 11 |

Hello World

12 | 13 | `; 14 | 15 | 16 | (async () => { 17 | const buff = await htmlDocxJs(html, "") 18 | debugger 19 | fs.writeFileSync("test1.doc", buff) 20 | })() 21 | -------------------------------------------------------------------------------- /html-to-docx/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "html-to-doc", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "html-docx-js": "^0.3.1", 14 | "html-to-docx": "^1.1.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /html-to-docx/test.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/html-to-docx/test.docx -------------------------------------------------------------------------------- /html-to-docx/test1.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/html-to-docx/test1.doc -------------------------------------------------------------------------------- /html-to-docx/test1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/html-to-docx/test1.docx -------------------------------------------------------------------------------- /html-to-pdf/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *~ 3 | config.json 4 | -------------------------------------------------------------------------------- /html-to-pdf/README.md: -------------------------------------------------------------------------------- 1 | Using PdfCrowd to generate PDFs 2 | =============================== 3 | 4 | You should create a file named `config.json` like below: 5 | 6 | ```json 7 | { 8 | "username": "your username", 9 | "apiKey": "your api key" 10 | } 11 | ``` 12 | 13 | Find more on http://pdfcrowd.com/ 14 | -------------------------------------------------------------------------------- /html-to-pdf/index.js: -------------------------------------------------------------------------------- 1 | 2 | // Dependencies 3 | var pdf = require('pdfcrowd'); 4 | 5 | // Configs 6 | var config = require("./config") 7 | , client = new pdf.Pdfcrowd(config.username, config.apiKey) 8 | ; 9 | 10 | // Save to file 11 | var callback = pdf.saveToFile("1123.pdf"); 12 | callback.end = function () { 13 | console.log("File saved successfully."); 14 | } 15 | 16 | callback.error = function (error, status) { 17 | console.log(">? ERROR::", error, status); 18 | } 19 | 20 | client.convertURI('google.com', callback); 21 | -------------------------------------------------------------------------------- /html-to-pdf/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "htmlToPdf", 3 | "version": "0.0.0", 4 | "description": "Converts a HTML page to PDF document.", 5 | "main": "main.js", 6 | "author": "Ionică Bizău ", 7 | "dependencies": { 8 | "pdfcrowd": "*" 9 | }, 10 | "license": "BSD" 11 | } 12 | -------------------------------------------------------------------------------- /jasmine-test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 |
Test
12 | 13 | 14 | -------------------------------------------------------------------------------- /jasmine-test/js/main.js: -------------------------------------------------------------------------------- 1 | setTimeout(function () { 2 | document.querySelector("#container").innerHTML = "Hello Jasmine"; 3 | }, 1000); 4 | 5 | document.title = "Testing Jasmine"; 6 | 7 | window.onload = function () { 8 | 9 | var btnEl = document.querySelector(".click-me") 10 | , resEl = document.querySelector(".result") 11 | ; 12 | 13 | btnEl.addEventListener("click", function () { 14 | resEl.innerHTML = "You clicked!"; 15 | }); 16 | }; 17 | -------------------------------------------------------------------------------- /jasmine-test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learning-nodejs-jasmine-test", 3 | "version": "1.0.0", 4 | "description": "Learning unit-testing using Jasmine.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jasmine" 8 | }, 9 | "dependencies": { 10 | "is-there": "^4.2.0", 11 | "jasmine": "^2.3.2" 12 | }, 13 | "devDependencies": { 14 | "jasmine2-reporter": "^0.1.1", 15 | "phantom-jquery": "^1.0.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /jasmine-test/spec/check-files.js: -------------------------------------------------------------------------------- 1 | const IsThere = require("is-there") 2 | , Reporter = require("jasmine2-reporter").Jasmine2Reporter 3 | ; 4 | 5 | jasmine.getEnv().addReporter(new Reporter()); 6 | 7 | describe("check the application files", () => { 8 | it("should find the index.html file", () => { 9 | expect(IsThere("index.html")).toBe(true); 10 | }); 11 | it("should find the js/main.js file", () => { 12 | expect(IsThere("js/main.js")).toBe(true); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /jasmine-test/spec/check-html.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | const jQueryPh = require("phantom-jquery"); 3 | 4 | // Constants 5 | const HTML_FILE = __dirname + "/../index.html"; 6 | 7 | describe("check the html", () => { 8 | 9 | // Initial HTML 10 | it("the initial container text should be \"test\"", (cb) => { 11 | jQueryPh.open(HTML_FILE, (err, $, page, ph) => { 12 | expect(err).toBe(null); 13 | $("#container").text(bodyHtml => { 14 | expect(bodyHtml).toBe("Test"); 15 | ph.exit(); 16 | cb(); 17 | }); 18 | }); 19 | }); 20 | 21 | // After one second the HTML should be changed 22 | it("after 1sec the container text should be \"Hello Jasmine\"", (cb) => { 23 | jQueryPh.open(HTML_FILE, (err, $, page, ph) => { 24 | expect(err).toBe(null); 25 | setTimeout(() => { 26 | $("#container").html(bodyHtml => { 27 | expect(bodyHtml).toBe("Hello Jasmine"); 28 | ph.exit(); 29 | cb(); 30 | }); 31 | }, 1000); 32 | }); 33 | }, 10000); 34 | 35 | //// Test the title 36 | it("the page title should be \"Testing Jasmine\"", (cb) => { 37 | jQueryPh.open(HTML_FILE, (err, $, page, ph) => { 38 | expect(err).toBe(null); 39 | page.evaluate(function () { 40 | return document.title; 41 | }, title => { 42 | expect(title).toBe("Testing Jasmine"); 43 | ph.exit(); 44 | cb(); 45 | }); 46 | }); 47 | }); 48 | 49 | // Test click 50 | it("should display \"You clicked!\" when clicking the button", (cb) => { 51 | jQueryPh.open(HTML_FILE, (err, $, page, ph) => { 52 | expect(err).toBe(null); 53 | $(".click-me").click(function () { 54 | $(".result").text(function (text) { 55 | expect(text).toBe("You clicked!"); 56 | ph.exit(); 57 | cb(); 58 | }); 59 | }); 60 | }); 61 | }); 62 | }); 63 | -------------------------------------------------------------------------------- /jasmine-test/spec/support/jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "spec", 3 | "spec_files": [ 4 | "check-files.js", 5 | "check-html.js" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /js-score/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules -------------------------------------------------------------------------------- /js-score/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ionică Bizău 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /js-score/README.md: -------------------------------------------------------------------------------- 1 | # js-score 2 | High-level library for creating music with JavaScript. 3 | 4 | ## Installation 5 | Run the following commands to download and install the application: 6 | 7 | ```sh 8 | $ git clone git@github.com:IonicaBizau/js-score.git js-score 9 | $ cd js-score 10 | $ npm install 11 | ``` 12 | 13 | ## Documentation 14 | 15 | 16 | 17 | 18 | ## How to contribute 19 | 20 | 1. File an issue in the repository, using the bug tracker, describing the 21 | contribution you'd like to make. This will help us to get you started on the 22 | right foot. 23 | 2. Fork the project in your account and create a new branch: 24 | `your-great-feature`. 25 | 3. Commit your changes in that branch. 26 | 4. Open a pull request, and reference the initial issue in the pull request 27 | message. 28 | 29 | ## License 30 | See the [LICENSE](./LICENSE) file. 31 | -------------------------------------------------------------------------------- /js-score/foo.aup: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /js-score/glorify.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/js-score/glorify.ogg -------------------------------------------------------------------------------- /js-score/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js-score", 3 | "version": "1.0.0", 4 | "description": "High-level library for creating music with JavaScript.", 5 | "main": "lib/index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "dependencies": { 10 | "baudio": "^2.1.2", 11 | "ul": "^2.1.0", 12 | "music-notes": "^1.0.0" 13 | }, 14 | "devDependencies": {}, 15 | "scripts": { 16 | "test": "node test" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git@github.com:IonicaBizau/js-score.git" 21 | }, 22 | "keywords": [ 23 | "score", 24 | "js" 25 | ], 26 | "author": "Ionică Bizău ", 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/IonicaBizau/js-score/issues" 30 | }, 31 | "homepage": "https://github.com/IonicaBizau/js-score" 32 | } 33 | -------------------------------------------------------------------------------- /js-score/test/communityamerica.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/js-score/test/communityamerica.zip -------------------------------------------------------------------------------- /js-score/test/glorify.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/js-score/test/glorify.ogg -------------------------------------------------------------------------------- /js-score/test/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var JsScore = require("../lib") 3 | , song = require(__dirname + "/songs/glorify") 4 | ; 5 | 6 | var score = new JsScore({ 7 | tempo: [4, 104] 8 | , measure: [4, 4] 9 | , key: JsScore.keys["Bb"] 10 | , tracks: song 11 | }); 12 | 13 | score.record("./glorify.ogg"); 14 | score.play(); 15 | 16 | -------------------------------------------------------------------------------- /js-score/test/songs/gospel.js: -------------------------------------------------------------------------------- 1 | var Ul = require("ul"); 2 | 3 | var m1 = [ 4 | { 5 | k: ["G4", "C5", "E5"] 6 | , d: 1 / 4 7 | , l: true 8 | }, 9 | { 10 | k: ["A4", "C5", "F5", "Eb5"] 11 | , d: 1 / 8 12 | , l: true 13 | } 14 | ] 15 | 16 | var tracks = [ 17 | { notes: m1 }, 18 | { notes: [ 19 | { 20 | k: ["Bb4"] 21 | , d: 1 / 64 22 | , l: true 23 | }, 24 | { 25 | k: ["C5"] 26 | , l: true 27 | , d: 63 / 64 28 | }, 29 | { 30 | k: ["Eb5"] 31 | , d: 4 / 6 32 | , l: true 33 | }, 34 | { 35 | k: ["C5"] 36 | , d: 6 / 48 37 | , l: true 38 | }, 39 | { 40 | k: ["Bb4"] 41 | , d: 2 / 48 42 | , l: true 43 | } 44 | ]} 45 | ]; 46 | 47 | module.exports = tracks; 48 | -------------------------------------------------------------------------------- /js-score/tmp.js: -------------------------------------------------------------------------------- 1 | var baudio = require('baudio'); 2 | var melody = [ 3 | 5, 3, 1, 3, 5, 5, 5, 5, 3, 3, 3, 3, 5, 8, 8, 8, 4 | 5, 3, 1, 3, 5, 5, 5, 5, 3, 3, 5, 3, 1, 1, 1, 1 5 | ]; 6 | var b = baudio(function (t) { 7 | var m = melody[Math.floor(t * 4 % melody.length)] 8 | return sin(441 * Math.pow(2, m / 12)) * sin(2); 9 | function sin (x) { return Math.sin(2 * Math.PI * t * x) } 10 | }); 11 | b.play(); 12 | -------------------------------------------------------------------------------- /js-score/vocal-exercises/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules -------------------------------------------------------------------------------- /js-score/vocal-exercises/1.js: -------------------------------------------------------------------------------- 1 | var baudio = require("baudio"); 2 | var melody = [1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]; 3 | var melody = [ 4 | 440, 5 | 466.16, 6 | 493.88, 7 | 523.25, 8 | 554, 9 | 587.33, 10 | 622.25, 11 | 659.25, 12 | 698.46, 13 | 739.99, 14 | 783.99, 15 | 830.61, 16 | 880.00 17 | ]; 18 | var rhythm = [3]; 19 | var xrhythm = [1, 3, 6, 3, 1, 3, 6, 12, 6, 24, 1, 3, 6, 3, 6, 3, 6, 3, 6, 12, 3, 1, 6, 6, 6, 6, 3, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 24]; 20 | var phase = [1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]; 21 | var d = snare(), 22 | e = snare(); 23 | 24 | var tau = Math.PI * 2; 25 | 26 | var b = baudio(function(t) { 27 | var m = melody[Math.floor(t * 1.5) % melody.length]; 28 | var r = rhythm[Math.floor(t * 3) % rhythm.length]; 29 | var q = xrhythm[Math.floor(t * 3) % xrhythm.length]; 30 | var p = t > 24 ? phase[Math.floor(t * r) % phase.length] : 1; 31 | 32 | return synth(m) * (t > 8) // or 82 -- DRONE PITCH 33 | + d(t % (1 / r / 2)) * 0.5 * (t > 4) + e(t % (1 / q)) * 0.5; 34 | 35 | function synth(x) { 36 | return 0; 37 | return saw(x) * 0.7 // SYNTH VOL. 38 | + saw(x + x / m * p) * 0.5 * (t > 12) + sin(x * 3 + saw(1 / x / 10)) * 0.2 * (t > 16) + sin(x * 4 + x / m * p) * 0.1 * (t > 20) + sin(x * 5 + 1 / 2) * 0.05 * (t > 24) + saw(x * 7 + 1) * 0.1 * (t > 24); 39 | } 40 | 41 | function sin(x) { 42 | return Math.sin(2 * Math.PI * t * x) 43 | } 44 | 45 | function saw(x) { 46 | return 1 - t % (1 / x) * x * 2 47 | } 48 | }); 49 | 50 | function snare() { 51 | var low0 = lowpass(30); 52 | var low1 = lowpass(80); 53 | var low2 = lowpass(10); 54 | 55 | return function(t) { 56 | return low0(snare(80, t)) * 4 // SNARE TAMBRE + VOL 57 | + low1(snare(40, t + 1 / 60)) * 7 + low2(snare(15, t + 1 / 30)) * 5; 58 | 59 | function snare(n, o) { 60 | var scalar = Math.max(0, 0.95 - (o * n) / ((o * n) + 1)); 61 | return sin(sin(sin(1303) * 139) * 4217) * scalar; 62 | } 63 | 64 | function sin(x) { 65 | return Math.sin(2 * Math.PI * t * x) 66 | } 67 | }; 68 | 69 | function lowpass(n) { 70 | var value = 0; 71 | return function(x) { 72 | return value += (x - value) / n 73 | } 74 | } 75 | } 76 | 77 | b.play(); 78 | -------------------------------------------------------------------------------- /js-score/vocal-exercises/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Ionică Bizău 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /js-score/vocal-exercises/README.md: -------------------------------------------------------------------------------- 1 | # vocal-excercises 2 | Some scripts for vocal exercises 3 | 4 | ## Installation 5 | Run the following commands to download and install the application: 6 | 7 | ```sh 8 | $ git clone git@github.com:IonicaBizau/vocal-exercises.git vocal-excercises 9 | $ cd vocal-excercises 10 | $ npm install 11 | ``` 12 | 13 | ## How to contribute 14 | 15 | 1. File an issue in the repository, using the bug tracker, describing the 16 | contribution you'd like to make. This will help us to get you started on the 17 | right foot. 18 | 2. Fork the project in your account and create a new branch: 19 | `your-great-feature`. 20 | 3. Commit your changes in that branch. 21 | 4. Open a pull request, and reference the initial issue in the pull request 22 | message. 23 | 24 | ## License 25 | See the [LICENSE](./LICENSE) file. 26 | -------------------------------------------------------------------------------- /js-score/vocal-exercises/index.js: -------------------------------------------------------------------------------- 1 | var baudio = require("baudio"); 2 | 3 | var tau = Math.PI * 2; 4 | 5 | var melody = [ 6 | 440, 7 | 466.16, 8 | 493.88, 9 | 523.25, 10 | 554, 11 | 587.33, 12 | 622.25, 13 | 659.25, 14 | 698.46, 15 | 739.99, 16 | 783.99, 17 | 830.61, 18 | 880.00 19 | ]; 20 | 21 | var b = baudio(function (t) { 22 | 23 | var n = t * 0.3 % 3 + 1; 24 | var f = Math.sin(tau * tau / ((n * 6 % 1 + 0.5) * 2)); 25 | var drums = Math.sin(tau * n * f); 26 | var now = 0; 27 | now = drums; 28 | var note = melody[Math.floor((t * 0.3) % melody.length)]; 29 | 30 | now += sawtooth(note) + sawtooth(note + 3) + square(note); 31 | 32 | function sin (freq) { 33 | return Math.sin(tau * t * freq); 34 | } 35 | 36 | function square (freq) { 37 | return Math.sin(tau * t * freq) < 0 ? -1 : 1; 38 | } 39 | 40 | function sawtooth (freq) { 41 | return t % (1 / freq) * freq * 2 - 1; 42 | } 43 | 44 | return now; 45 | }); 46 | 47 | b.play(); 48 | -------------------------------------------------------------------------------- /js-score/vocal-exercises/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vocal-exercises", 3 | "version": "1.0.1", 4 | "description": "Some scripts for vocal exercises", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node index" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git@github.com:IonicaBizau/vocal-exercises.git" 12 | }, 13 | "keywords": [ 14 | "vocal", 15 | "exercises", 16 | "baudio" 17 | ], 18 | "dependencies": { 19 | "baudio": "2.1.2" 20 | }, 21 | "author": "Ionică Bizău ", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/IonicaBizau/vocal-exercises/issues" 25 | }, 26 | "homepage": "https://github.com/IonicaBizau/vocal-exercises" 27 | } 28 | -------------------------------------------------------------------------------- /jsdom/README.md: -------------------------------------------------------------------------------- 1 | jsdom 2 | ===== 3 | 4 | Testing jsdom Node module. 5 | -------------------------------------------------------------------------------- /jsdom/htmlFile.html: -------------------------------------------------------------------------------- 1 |

Testing the jsDom NodeJS module.

2 | -------------------------------------------------------------------------------- /jsdom/main.js: -------------------------------------------------------------------------------- 1 | var jsdom = require("jsdom"); 2 | var fs = require("fs"); 3 | 4 | var html = fs.readFileSync("./htmlFile.html").toString(); 5 | 6 | jsdom.env({ 7 | html: html, 8 | scripts: ["http://code.jquery.com/jquery.js"], 9 | done: function (errors, window) { 10 | var $ = window.$; 11 | 12 | $("p").append("Appending..."); 13 | 14 | console.log($("body").html()); 15 | console.log("--------------"); 16 | 17 | var input = $(""); 18 | input.val("Test"); 19 | input.attr("type", "text"); 20 | 21 | $("p").after(input); 22 | console.log($("body").html()); 23 | 24 | console.log("Wow, going to ★ Star the jsdom repository."); 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /jsdom/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsdom", 3 | "version": "0.0.0", 4 | "description": "Test jsdom Node module.", 5 | "main": "main.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/IonicaBizau/NodeJS-Beginner-Projects" 9 | }, 10 | "dependencies": { 11 | "jsdom": "*" 12 | }, 13 | "author": "IonicaBizau", 14 | "license": "BSD", 15 | "bugs": { 16 | "url": "https://github.com/IonicaBizau/NodeJS-Beginner-Projects/issues" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /json2md/index.js: -------------------------------------------------------------------------------- 1 | const json2md = require("json2md"); 2 | 3 | const URL = "https://www.youtube.com/watch?v=pBYqen3B2gc"; 4 | 5 | // add custom types for json2md 6 | json2md.converters.linkToVideo = function(input, json2md) { 7 | return "Watch the video on [Youtube](" + input + ")"; 8 | }; 9 | 10 | var json = [ 11 | { h1: "" }, 12 | { linkToVideo: URL } 13 | ]; 14 | 15 | console.log(json2md(json)); 16 | -------------------------------------------------------------------------------- /json2md/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "json2md-example", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "json2md": "^1.6.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jwt-auth/index.js: -------------------------------------------------------------------------------- 1 | // dependencies 2 | var Assert = require('assert') 3 | , GoogleApis = require('googleapis') 4 | , authData = { 5 | email: "ionica.bizau@jillix.com" 6 | , keyFile: __dirname + "/keyFile.pem" 7 | , key: null 8 | , scopes: ["https://www.googleapis.com/auth/admin.directory.group"] 9 | } 10 | ; 11 | 12 | // set jwt data 13 | var jwt = new GoogleApis.auth.JWT( 14 | authData.email 15 | , authData.keyFile 16 | , authData.key 17 | , authData.scopes 18 | ); 19 | 20 | jwt.GAPI = function(opts, callback) { 21 | 22 | console.log("GAPI Options: ", opts); 23 | 24 | // set auth data 25 | Assert.equal(authData.email, opts.iss); 26 | Assert.equal(authData.keyFile, opts.keyFile); 27 | Assert.equal(authData.scopes.join(" "), opts.scope); 28 | 29 | // async callback 30 | setTimeout(function() { 31 | callback(null); 32 | }, 0); 33 | 34 | // return an object containing getToken function 35 | return { 36 | getToken: function(opt_callback) { 37 | console.log("Inside of getToken handler."); 38 | opt_callback(null, 'initial-access-token'); 39 | } 40 | } 41 | }; 42 | 43 | // authorize 44 | jwt.authorize(function (err, data) { 45 | 46 | // output error 47 | if (err) { 48 | console.log("Error: ", err); 49 | return; 50 | } 51 | 52 | // set credentials 53 | Assert.equal('initial-access-token', jwt.credentials.access_token); 54 | Assert.equal('jwt-placeholder', jwt.credentials.refresh_token); 55 | 56 | console.log("JWT Credentials: ", jwt.credentials); 57 | }); 58 | -------------------------------------------------------------------------------- /jwt-auth/keyFile.pem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/jwt-auth/keyFile.pem -------------------------------------------------------------------------------- /jwt-auth/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jwt-auth", 3 | "version": "0.0.0", 4 | "description": "Testing JWT Authentication via Google Apis.", 5 | "dependencies": { 6 | "googleapis": "*" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /koa/index.js: -------------------------------------------------------------------------------- 1 | const Koa = require('koa'); 2 | const app = new Koa(); 3 | 4 | // response 5 | app.use("/", ctx => { 6 | ctx.body = 'Hello Koa'; 7 | }); 8 | 9 | app.use(ctx => { 10 | ctx.status = 404 11 | ctx.body = 'Hello Koa'; 12 | }); 13 | 14 | app.listen(3000); 15 | -------------------------------------------------------------------------------- /koa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "koa-test", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "koa": "^2.2.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /learning-es6/arrow-functions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | class Bar { 4 | baz () { 5 | console.log("baz: ", this); 6 | } 7 | } 8 | 9 | function foo() { 10 | console.log("foo: ", this); 11 | setTimeout(() => { 12 | console.log("timeout: ", this); 13 | b.baz(); 14 | }, 1000); 15 | } 16 | 17 | var obj = { bar: 42 }; 18 | var b = new Bar(); 19 | foo.apply(obj, []); 20 | -------------------------------------------------------------------------------- /limit-it/index.js: -------------------------------------------------------------------------------- 1 | var LimitIt = require("limit-it"); 2 | 3 | // 2 4 | // 5 | // 6 | // 0 3 4 5 6 7 | // ^--------------$ 8 | // ^----------------$ 9 | // ^ -------------... 10 | // 11 | var l = new LimitIt(2); 12 | 13 | function foo (input, cb) { 14 | setTimeout(function() { 15 | cb("Hello " + input, 42); 16 | }, 4000); 17 | } 18 | 19 | function bar(input, callback) { 20 | if (typeof input === "string") { 21 | l.add(foo, ["World"], callback); 22 | } else { 23 | l.add(foo, ["Mars"], callback); 24 | } 25 | //setTimeout(function() { 26 | // l.add(foo, ["Mars"], callback); 27 | //}, 2000); 28 | } 29 | 30 | bar([], function (c, magicNumber) { 31 | console.log(c, magicNumber); 32 | }); 33 | 34 | bar("foo", function (c, magicNumber) { 35 | console.log(c, magicNumber); 36 | }); 37 | 38 | -------------------------------------------------------------------------------- /login-with-bitbucket/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | *~ 3 | -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/abstract_api.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Ajax.org B.V. 3 | * 4 | * This product includes software developed by 5 | * Ajax.org B.V. (http://www.ajax.org/). 6 | * 7 | * Author: Fabian Jaokbs 8 | */ 9 | 10 | var AbstractApi = exports.AbstractApi = function(api) { 11 | this.$api = api; 12 | }; 13 | 14 | (function() { 15 | 16 | this.$createListener = function(callback, key) { 17 | return function(err, response) { 18 | if (err) { 19 | callback & callback(err); 20 | return; 21 | } 22 | 23 | callback && callback(err, key ? response[key] : response); 24 | }; 25 | }; 26 | 27 | }).call(AbstractApi.prototype); -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/authentication_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Ajax.org B.V. 3 | * 4 | * This product includes software developed by 5 | * Ajax.org B.V. (http://www.ajax.org/). 6 | * 7 | * Author: Fabian Jaokbs 8 | */ 9 | 10 | var assert = require("assert"); 11 | var BitBucket = require("./index").BitBucket; 12 | var secrets = require("./secrets"); 13 | 14 | module.exports = { 15 | 16 | setUp: function() { 17 | this.bitbucket = new BitBucket(true); 18 | this.repoApi = this.bitbucket.getRepoApi(); 19 | }, 20 | 21 | // "test: show user without authentification should have no 'plan'" : function(finished) { 22 | // test.userApi.show(username, function(err, user) { 23 | // assert.equal(user.plan, undefined); 24 | // finished(); 25 | // }); 26 | // }, 27 | // 28 | // "test: show user with authentification should have a 'plan'" : function(finished) { 29 | // test.github.authenticateToken(username, token); 30 | // test.userApi.show(username, function(err, user) { 31 | // assert.ok(user.plan !== undefined); 32 | // finished(); 33 | // }); 34 | // }, 35 | 36 | // test disabled because I don't want to see my password on github :-) 37 | "test: authenticate using username and password should show private repose" : function(finished) { 38 | this.bitbucket.authenticatePassword(secrets.username, secrets.password); 39 | this.repoApi.getUserRepos(secrets.username, function(err, repos) { 40 | console.log(repos) 41 | assert.ok(repos.filter(function(repo) { return repo.is_private; }).length > 0); 42 | finished(); 43 | }); 44 | }, 45 | 46 | // "test: authenticate using username and wrong password" : function(finished) { 47 | // this.bitbucket.authenticatePassword(username, "1234"); 48 | // this.userApi.show(username, function(err, user) { 49 | // assert.ok(err !== undefined); 50 | // finished(); 51 | // }); 52 | // }, 53 | 54 | // "test: authenticate with bad token" : function(finished) { 55 | // this.github.authenticateToken(username, "bad-token"); 56 | // this.userApi.show(username, function(err, user) { 57 | // assert.ok(err !== undefined); 58 | // finished(); 59 | // }); 60 | // } 61 | }; 62 | 63 | !module.parent && require("asyncjs").test.testcase(module.exports).exec(); -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/email.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Ajax.org B.V. 3 | * 4 | * This product includes software developed by 5 | * Ajax.org B.V. (http://www.ajax.org/). 6 | * 7 | * Author: Fabian Jaokbs 8 | */ 9 | 10 | var util = require('util'); 11 | var AbstractApi = require("./abstract_api").AbstractApi; 12 | 13 | /** 14 | * API wrapper for http://confluence.atlassian.com/display/BBDEV/Emails 15 | */ 16 | var EmailApi = exports.EmailApi = function(api) { 17 | this.$api = api; 18 | }; 19 | 20 | util.inherits(EmailApi, AbstractApi); 21 | 22 | (function() { 23 | 24 | /** 25 | * Get auuser data including the repository list 26 | */ 27 | this.getAll = function(callback) { 28 | this.$api.get("emails/", null, null, callback); 29 | }; 30 | 31 | }).call(EmailApi.prototype); -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/email_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Ajax.org B.V. 3 | * 4 | * This product includes software developed by 5 | * Ajax.org B.V. (http://www.ajax.org/). 6 | * 7 | * Author: Fabian Jaokbs 8 | */ 9 | 10 | var assert = require("assert"); 11 | var async = require("asyncjs"); 12 | var BitBucket = require("./index").BitBucket; 13 | //var secrets = require("./secrets"); 14 | 15 | 16 | module.exports = { 17 | 18 | setUp: function() { 19 | this.bitbucket = new BitBucket(true); 20 | this.repoApi = this.bitbucket.getRepoApi(); 21 | this.emailApi = this.bitbucket.getEmailApi(); 22 | }, 23 | 24 | "test: get list of all email addresses" : function(finished) { 25 | this.emailApi.getAll(function(err, emails) { 26 | console.log(emails); 27 | assert.equal(err, null); 28 | assert.ok(emails.length); 29 | assert.ok(emails[0].email); 30 | finished(); 31 | }); 32 | } 33 | }; 34 | 35 | !module.parent && async.test.testcase(module.exports).exec(); -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/secrets.js: -------------------------------------------------------------------------------- 1 | exports.username = "" 2 | exports.password = ""; 3 | 4 | exports.oauth = { 5 | clientId: "your client id", 6 | secret: "your secret key" 7 | } -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/ssh.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Ajax.org B.V. 3 | * 4 | * This product includes software developed by 5 | * Ajax.org B.V. (http://www.ajax.org/). 6 | * 7 | * Author: Fabian Jaokbs 8 | */ 9 | 10 | var util = require('util'); 11 | var AbstractApi = require("./abstract_api").AbstractApi; 12 | 13 | /** 14 | * API wrapper for http://confluence.atlassian.com/display/BBDEV/SSH+Keys 15 | */ 16 | var SshApi = exports.SshApi = function(api) { 17 | this.$api = api; 18 | }; 19 | 20 | util.inherits(SshApi, AbstractApi); 21 | 22 | (function() { 23 | 24 | /** 25 | * List all public SSH keys on the account 26 | */ 27 | this.getKeys = function(callback) { 28 | this.$api.get("ssh-keys/", null, null, callback); 29 | }; 30 | 31 | /** 32 | * Add a public SSH key on the account 33 | */ 34 | this.addKey = function(key, callback) { 35 | this.$api.post("ssh-keys/", {key: key}, null, callback); 36 | }; 37 | 38 | /** 39 | * Delete a public SSH key on the account 40 | */ 41 | this.deleteKey = function(pk, callback) { 42 | this.$api["delete"]("ssh-keys/" + pk, null, null, callback); 43 | }; 44 | 45 | }).call(SshApi.prototype); -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/ssh_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Ajax.org B.V. 3 | * 4 | * This product includes software developed by 5 | * Ajax.org B.V. (http://www.ajax.org/). 6 | * 7 | * Author: Fabian Jaokbs 8 | */ 9 | 10 | var assert = require("assert"); 11 | var async = require("asyncjs"); 12 | var BitBucket = require("./index").BitBucket; 13 | var secrets = require("./secrets"); 14 | 15 | var pubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2YuevRJKTVUAjbUvGCi+rhEAdxc8CGXSiq3JwY0EpUXmD89UFSTr1XI+i3Bq5di/kAJhdI3mqiipN1+3LP7HZsd3sFuY9mb5wbZLwHrBvjEhTsOgxFEzyCm87K8OT2uuazsG2uHL/VT0E2o2Ttu2HEu6k3yrx+3ZcPTKJVOdT0tJ5nIobbpgfv3CHmbvdskqSTq1vefh2je8yeiQYMIFsdJ7ApZEmLtGwEIMEVFNSgBJauRQS6qDmI9D1oVV7h5zPNW1qCR1sjsPyb6jxQS2+N63duY0qZuA8C6h2zX+TneY1iSRJcgniAjds2alNH2MJTxl+toIjXvviA7hsVJCD c9@c9.io"; 16 | 17 | module.exports = { 18 | 19 | setUpSuite : function(next) { 20 | this.setUpApi(); 21 | this.deleteAllKeys(next); 22 | }, 23 | 24 | setUp: function() { 25 | this.setUpApi(); 26 | }, 27 | 28 | setUpApi: function() { 29 | this.bitbucket = new BitBucket(true); 30 | this.bitbucket.authenticatePassword(secrets.username, secrets.password); 31 | this.sshApi = this.bitbucket.getSshApi(); 32 | }, 33 | 34 | deleteAllKeys: function(callback) { 35 | var self = this; 36 | this.sshApi.getKeys(function(err, keys) { 37 | if (err) return callback(err); 38 | 39 | async.forEach(keys, function(key, next) { 40 | self.sshApi.deleteKey(key.pk); 41 | }, callback); 42 | }); 43 | }, 44 | 45 | "test: get all ssh keys" : function(finished) { 46 | var self = this; 47 | this.sshApi.addKey(pubkey, function(err, key) { 48 | assert.equal(err, null); 49 | self.sshApi.getKeys(function(err, keys) { 50 | assert.equal(err, null); 51 | assert.ok(keys.length > 0); 52 | assert.ok(keys[0].key == pubkey); 53 | assert.ok(keys[0].pk !== undefined); 54 | 55 | // cleanup 56 | self.sshApi.deleteKey(keys[0].pk, finished); 57 | }); 58 | }); 59 | }, 60 | 61 | "test: delete/add ssh key" : function(finished) { 62 | var self = this; 63 | this.sshApi.addKey(pubkey, function(err, key) { 64 | assert.equal(err, null); 65 | assert.ok(key.key == pubkey); 66 | 67 | // cleanup 68 | self.sshApi.deleteKey(key.pk, finished); 69 | }); 70 | }, 71 | 72 | "test: adding and existing key should return an error" : function(finished) { 73 | var self = this; 74 | this.sshApi.addKey(pubkey, function(err, key) { 75 | self.sshApi.addKey(pubkey, function(err) { 76 | assert.ok(err.msg.match(/Someone has already registered that SSH key/)); 77 | 78 | // cleanup 79 | self.sshApi.deleteKey(key.pk, finished); 80 | }); 81 | }); 82 | } 83 | }; 84 | 85 | !module.parent && async.test.testcase(module.exports).exec(); -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/user.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Ajax.org B.V. 3 | * 4 | * This product includes software developed by 5 | * Ajax.org B.V. (http://www.ajax.org/). 6 | * 7 | * Author: Fabian Jaokbs 8 | */ 9 | 10 | var util = require('util'); 11 | var AbstractApi = require("./abstract_api").AbstractApi; 12 | 13 | /** 14 | * API wrapper for http://confluence.atlassian.com/display/BBDEV/Users 15 | */ 16 | var UserApi = exports.UserApi = function(api) { 17 | this.$api = api; 18 | }; 19 | 20 | util.inherits(UserApi, AbstractApi); 21 | 22 | (function() { 23 | 24 | /** 25 | * Get user data including the repository list 26 | */ 27 | this.getUserData = function(username, callback) { 28 | this.$api.get("users/" + username, null, null, callback); 29 | }; 30 | 31 | }).call(UserApi.prototype); -------------------------------------------------------------------------------- /login-with-bitbucket/bitbucket/user_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Ajax.org B.V. 3 | * 4 | * This product includes software developed by 5 | * Ajax.org B.V. (http://www.ajax.org/). 6 | * 7 | * Author: Fabian Jaokbs 8 | */ 9 | 10 | var assert = require("assert"); 11 | var async = require("asyncjs"); 12 | var BitBucket = require("./index").BitBucket; 13 | var secrets = require("./secrets"); 14 | 15 | 16 | module.exports = { 17 | 18 | setUp: function() { 19 | this.bitbucket = new BitBucket(true); 20 | this.bitbucket.authenticatePassword(secrets.username, secrets.password); 21 | this.userApi = this.bitbucket.getUserApi(); 22 | }, 23 | 24 | "test: get data of authenticated user" : function(finished) { 25 | this.userApi.getUserData(secrets.username, function(err, data) { 26 | assert.equal(err, null); 27 | assert.equal(data.user.username, secrets.username); 28 | assert.ok("repositories" in data); 29 | finished(); 30 | }); 31 | } 32 | }; 33 | 34 | !module.parent && async.test.testcase(module.exports).exec(); -------------------------------------------------------------------------------- /login-with-bitbucket/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "login-with-bitbucket", 3 | "dependencies": { 4 | "asyncjs": ">=0.0.5", 5 | "oauth": ">=0.9.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /login-with-github/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | *~ 3 | -------------------------------------------------------------------------------- /login-with-github/README.md: -------------------------------------------------------------------------------- 1 | Login with Github 2 | ================= 3 | **Node** implementation for Github login. 4 | 5 | ### Need more information? 6 | Follow Github API. 7 | 8 | ## Introduction 9 | "OAuth2 is a protocol that lets external apps request authorization to private details in a user’s GitHub account without getting their password. This is preferred over Basic Authentication because tokens can be limited to specific types of data, and can be revoked by users at any time." (from Github API) 10 | 11 | ### Creating an Github APP 12 | All developers need to register their application before getting started. A registered OAuth application is assigned a unique Client ID and Client Secret. The Client Secret should not be shared. 13 | 14 | Click here for this. 15 | You will receive a CLIENT_ID and a SECRET_KEY. 16 | 17 | Replace them into `server.js` file and in `public/index.html` file. 18 | 19 | ## Installation 20 | 21 | 1. Clone this repository. 22 | 23 | ``` 24 | git clone https://github.com/IonicaBizau/login-with-github.git 25 | ``` 26 | 27 | 2. Install node modules. 28 | 29 | ``` 30 | npm install 31 | ``` 32 | 33 | ## Starting 34 | 35 | ``` 36 | node server.js 37 | ``` 38 | 39 | or 40 | 41 | ``` 42 | node server.js --showLogs 43 | ``` 44 | The second one will print the console messages. 45 | 46 | 47 | ## Testing 48 | 49 | Open http://localhost:8000/ and click the button to Sign In with Github account. 50 | You will can accept or deny the access to app. 51 | -------------------------------------------------------------------------------- /login-with-github/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LoginWithGithub", 3 | "version": "0.0.1", 4 | "dependencies": { 5 | "node-static": "*", 6 | "request": "*" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /login-with-github/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Login with Github - TEMPLATE 4 | 5 | 6 | 7 |
8 |

Welcome!

9 | 10 | 11 | 12 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /login-with-github/public/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Ubuntu, Arial; 3 | } 4 | 5 | h1 { 6 | color: red; 7 | font-family: Ubuntu, Arial; 8 | } 9 | 10 | img { 11 | border-radius: 10px 10px 10px 10px; 12 | box-shadow: 0 0 5px black; 13 | } 14 | 15 | input[type="button"], button { 16 | background: none repeat scroll 0 0 white; 17 | border: 2px solid black; 18 | border-radius: 10px 10px 10px 10px; 19 | height: 46px; 20 | width: 158px; 21 | margin-top: 10px; 22 | } 23 | 24 | input[type="text"], textarea { 25 | border: 2px solid black; 26 | border-radius: 10px 10px 10px 10px; 27 | font-size: 20px; 28 | height: 46px; 29 | margin-top: 10px; 30 | padding: 10px; 31 | text-align: center; 32 | width: 400px; 33 | } 34 | 35 | li { 36 | font-size: 20px; 37 | margin-right: 5px 38 | } 39 | 40 | .removeButton { 41 | margin-left: 10px; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /longest-streak/README.md: -------------------------------------------------------------------------------- 1 | # Longest Streak 2 | 3 | This creates a repository creating commits every day since 1 January 1970. 4 | -------------------------------------------------------------------------------- /longest-streak/index.js: -------------------------------------------------------------------------------- 1 | var Moment = require("moment") 2 | , Gry = require("gry") 3 | , Fs = require("fs") 4 | ; 5 | 6 | var repo = new Gry("./foo") 7 | , date = new Moment("1 January 1970") 8 | ; 9 | 10 | repo.create(function () { 11 | function makeCommit() { 12 | date.add("1", "days"); 13 | if (date.isAfter(new Moment())) { return; } 14 | console.log(date.format("LLL")); 15 | Fs.writeFileSync("./foo/test", Math.random()); 16 | repo.commit("Test", "--date='" + date.format("LLL") + "' .", makeCommit); 17 | } 18 | Fs.writeFileSync("./foo/test", Math.random()); 19 | repo.exec("add .", function () { 20 | repo.commit("Test", makeCommit); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /mongodb-map-reduce/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | /node_modules 3 | -------------------------------------------------------------------------------- /mongodb-map-reduce/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/mongodb-map-reduce/README.md -------------------------------------------------------------------------------- /mongodb-map-reduce/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MongoDBMapReduce", 3 | "version": "0.0.1", 4 | "dependencies": { 5 | "mongodb": "*" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /mongodb-map-reduce/server.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | var mongo = require("mongodb"); 3 | 4 | // Database config 5 | var firstCol = "col_one"; 6 | var reduceCol = "col_two"; 7 | 8 | // Mongo server 9 | var server = mongo.Server("127.0.0.1", 27017); 10 | var db = new mongo.Db("test", server, { safe: true }); 11 | 12 | // Open database 13 | db.open(function(err, db) { 14 | if (err) { 15 | process.exit(1); 16 | } 17 | }); 18 | 19 | // Create server 20 | var srv = http.createServer(function(req, res){ 21 | // Write the content of col_one 22 | res.write("ITEMS FROM test DB, collection: " + firstCol + "\n"); 23 | 24 | // Print items from col_one 25 | printItems(firstCol, res, function(err, collection) { 26 | if (err) { return res.end("Something went wrong.:("); } 27 | 28 | // Start reduce function 29 | var mapFunction1 = function() { 30 | emit(this.cust_id, this.price); 31 | }; 32 | 33 | var reduceFunction1 = function(keyCustId, valuesPrices) { 34 | return Array.sum(valuesPrices); 35 | }; 36 | 37 | collection.mapReduce( 38 | mapFunction1, 39 | reduceFunction1, 40 | { out: reduceCol }, 41 | 42 | function() { 43 | // Show the items from second collection 44 | res.write("ITEMS FROM test DB, collection: " + reduceCol + "\n"); 45 | printItems(reduceCol, res, function(err) { 46 | if (err) { return res.end("Something went wrong.:("); } 47 | res.end(); 48 | }); 49 | } 50 | ); 51 | }); 52 | }).listen(8080); 53 | 54 | function printItems(collection, res, callback) { 55 | db.collection(collection, function(err, col) { 56 | if(err) { return callback(err) } 57 | 58 | col.find().toArray(function(err, item) { 59 | if(err) { return callback(err) } 60 | 61 | res.write(JSON.stringify(item, null, 4) + "\n\n"); 62 | 63 | callback(null, col); 64 | }); 65 | }); 66 | } 67 | 68 | -------------------------------------------------------------------------------- /mongoose-sample-app/example/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Dependencies 4 | const mongoose = require("mongoose"); 5 | 6 | // Connect 7 | mongoose.connect(process.env.DB_URI || "mongodb://localhost/test", {useNewUrlParser: true}, err => { 8 | console.log(err || "Connected successfully...") 9 | }) 10 | 11 | 12 | // Create the model 13 | const Kitten = mongoose.model("Kitten", new mongoose.Schema({ 14 | name: String 15 | })); 16 | 17 | 18 | // Insert 19 | const noir = new Kitten({ name: "Noir" }); 20 | noir.save() 21 | .then(console.log) 22 | .catch(console.error) 23 | -------------------------------------------------------------------------------- /mongoose-sample-app/lib/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IonicaBizau/learning-nodejs/c02674af350c3a65935c1f03088d343d0796e750/mongoose-sample-app/lib/index.js -------------------------------------------------------------------------------- /mongoose-sample-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mongoose-sample-app", 3 | "description": "How to use Mongoose", 4 | "keywords": [ 5 | "mongoose", 6 | "sample", 7 | "app", 8 | "how", 9 | "to", 10 | "use" 11 | ], 12 | "license": "MIT", 13 | "version": "1.0.0", 14 | "main": "lib/index.js", 15 | "scripts": { 16 | "test": "echo \"Error: no test specified\" && exit 1" 17 | }, 18 | "author": "Ionică Bizău (https://ionicabizau.net)", 19 | "homepage": "https://github.com/IonicaBizau/mongoose-sample-app#readme", 20 | "files": [ 21 | "bin/", 22 | "app/", 23 | "lib/", 24 | "dist/", 25 | "src/", 26 | "scripts/", 27 | "resources/", 28 | "menu/", 29 | "cli.js", 30 | "index.js", 31 | "bloggify.js", 32 | "bloggify.json", 33 | "bloggify/" 34 | ], 35 | "repository": { 36 | "type": "git", 37 | "url": "git+ssh://git@github.com/IonicaBizau/mongoose-sample-app.git" 38 | }, 39 | "bugs": { 40 | "url": "https://github.com/IonicaBizau/mongoose-sample-app/issues" 41 | }, 42 | "dependencies": { 43 | "mongoose": "^5.10.0" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /musicxml-to-json/test/2.xml: -------------------------------------------------------------------------------- 1 | 2 | 1 3 | 4 | 3 5 | 6 |