├── .gitignore ├── MEAN-Stack.md ├── AWS ├── S3-Buckets.md ├── Cloudfront-S3-Lets-Encrypt.md ├── Namecheap-Route-53.md ├── AWS-NodeSDK.md └── SysOps-Solutions-Architect.md ├── Yeoman-Generator.md ├── gitcommit.sh ├── Data-Science └── Intermediat-DS-Python.md ├── VPC-Setup.md ├── Docker ├── Docker-Networking.md ├── Docker-Saving-Current-State.md └── MySQL-Development.md ├── AWS-Lex.md ├── Javascript-AWS.md ├── API-AI-Bot.md ├── Pasted image at 2016_08_23 04_06 PM.png ├── .esdoc.json ├── React-Router.md ├── SQL-Window-Functions.md ├── Machine-Learning-Stanford.md ├── my-sql-cheat-sheet.md ├── Dev-Ops.md ├── Redis └── Redis.md ├── Electron └── Electron-Udemy.md ├── React-Testing-Enzyme.md ├── React-Native-For-iOS-Devs.md ├── JS-Express.md ├── iOS └── Apple-Watch.md ├── Git-Remote-Help ├── smacss-cheat-sheet.scss ├── Writing-Bash-Scripts.md ├── Machine-Learning ├── CL-Classification-Intro.md ├── ML-Random-Forest-Regression.md ├── ML-Decision-Trees.md └── ML-Regression-Model-Performance.md ├── React-Native-Cheat-Sheet.md ├── README.md ├── docker-code-sheet.md ├── Drupal ├── Drupal-8-Modules.md └── Drupal-8.md ├── CocoaPods Workshop ├── Cpp-Udemy.md ├── ES6-fiddle.md ├── Npm-Create-Package.md ├── Docker-EC2.md ├── Swift-DOK-Code-Examples ├── package.json ├── d3 └── D3.md ├── Terminal └── Tips-and-Tricks.md ├── ios-objc-cheat-sheet.md ├── Android └── Lists-And-Adapters.md ├── Python-Intermediate-Data-Science.md ├── Intro-To-Scala.md ├── gulpfile.js ├── js-grid-alignment-cheat-sheet.md ├── Ethereum └── Course.md ├── Server-Side-React └── Create-React-App-Server-Side.md ├── pdo-cheat-sheet.md ├── Python-Slack-Bot.md ├── CSS-Style-Guide.md ├── Nginx └── Nginx-Nodejs-Docker.md ├── Laravel-5.4.md ├── flexbox-help-sheet.md ├── Unity └── Unity-Basics.md ├── th_understanding_this_js ├── th_npm_as_a_task_runner ├── WP-PC-Setup-Cheat-Sheet.md ├── Stripe └── Stripe-Node.md ├── Nightmare.md ├── COMP3306-AI └── 3-A*-Algorithm.md ├── Mongo-DB-Code-Guide.md ├── Google-Play.md ├── Chef └── Chef-General.md ├── th_laravel_basics.md ├── React-Native-With-SCSS.md ├── React-Animations.md ├── Webpack.md ├── Swift-3-Methods.md ├── npm-cheat-sheet.md ├── Vim └── Vim.md ├── React-Redux-Middleware.md ├── JS-Unit-Testing-Mocha-Chai.md ├── Laravel-Artisan.md ├── css-cheat-sheet.md ├── sass-cheat-sheet.scss ├── Testing-Cheat-Sheet.md ├── Dependency-Management-With-Gradle.md ├── th_oath_with_passport ├── Swift-3-Extensions.md ├── DevOps-Essentials.md ├── th_mean_stack ├── docker-cheat-sheet.md ├── linkedin-api-cheat-sheet.md ├── Enzyme-Testing.md ├── AWS-Certified-SysOps-Administrator.md ├── th_js_unit_testing ├── React-Native └── React-Native-iBeacon.md ├── css-transitions-transforms-cheat-sheet.md ├── COMP3520-OS └── 3-Threads.md ├── Python-Object-Orientated.md └── Swift-3-OOP.md /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | node_modules/ -------------------------------------------------------------------------------- /MEAN-Stack.md: -------------------------------------------------------------------------------- 1 | # MEAN Stack 2 | -------------------------------------------------------------------------------- /AWS/S3-Buckets.md: -------------------------------------------------------------------------------- 1 | # AWS with S3 2 | -------------------------------------------------------------------------------- /Yeoman-Generator.md: -------------------------------------------------------------------------------- 1 | # Yeoman Generator 2 | 3 | -------------------------------------------------------------------------------- /gitcommit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git add * 3 | git commit -m "$1" -------------------------------------------------------------------------------- /Data-Science/Intermediat-DS-Python.md: -------------------------------------------------------------------------------- 1 | # Intermediate Python Data Science 2 | -------------------------------------------------------------------------------- /VPC-Setup.md: -------------------------------------------------------------------------------- 1 | # VPC Setup 2 | 3 | http://blog.flux7.com/blogs/aws/vpc-best-configuration-practices 4 | -------------------------------------------------------------------------------- /Docker/Docker-Networking.md: -------------------------------------------------------------------------------- 1 | # Docker Networking 2 | 3 | Basic intro into networking together a few containers. 4 | -------------------------------------------------------------------------------- /AWS-Lex.md: -------------------------------------------------------------------------------- 1 | # AWS Lex 2 | 3 | [Javascript MediaRecorder API](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder) -------------------------------------------------------------------------------- /Javascript-AWS.md: -------------------------------------------------------------------------------- 1 | # Javascript AWS 2 | 3 | [Javascript AWS Install](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/index.html) -------------------------------------------------------------------------------- /API-AI-Bot.md: -------------------------------------------------------------------------------- 1 | # API.ai Bots 2 | 3 | [API.ai JS Voice](https://github.com/api-ai/apiai-nodejs-client/blob/master/samples/voice_request.js) -------------------------------------------------------------------------------- /Pasted image at 2016_08_23 04_06 PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okeeffed/cheat-sheets/HEAD/Pasted image at 2016_08_23 04_06 PM.png -------------------------------------------------------------------------------- /Docker/Docker-Saving-Current-State.md: -------------------------------------------------------------------------------- 1 | # Docker - saving to a new container 2 | 3 | `docker commit c3f279d17e0a svendowideit/testimage:version3` 4 | -------------------------------------------------------------------------------- /.esdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": ".", 3 | "destination": "./doc", 4 | "manual": { 5 | "design": ["./Design-Systems/Design-Systems.md"] 6 | }, 7 | "excludes": ["\\.(js)$"] 8 | } 9 | -------------------------------------------------------------------------------- /React-Router.md: -------------------------------------------------------------------------------- 1 | # React Router 2 | 3 | ## Prequisites 4 | 5 | Ensure that you're familiar with React. 6 | 7 | ## Table of Contents 8 | 9 | 10 | *** 11 | 12 | ## RR-1: Setting Routes 13 | -------------------------------------------------------------------------------- /SQL-Window-Functions.md: -------------------------------------------------------------------------------- 1 | # SQL-Window-Functions 2 | 3 | It allows you to compare values as they come through. 4 | 5 | This will use Postgres SQL. 6 | 7 | There are a number of SQL variations that can use window functions. -------------------------------------------------------------------------------- /Machine-Learning-Stanford.md: -------------------------------------------------------------------------------- 1 | # Machine Learning - Week 1 2 | 3 | - Knowing the algorithms isn't enough, if you can't get it to work on problems you don't care about! 4 | - Grew out of the field of AI 5 | 6 | ML was developed as a new capability for students. -------------------------------------------------------------------------------- /my-sql-cheat-sheet.md: -------------------------------------------------------------------------------- 1 | # mySQL Cheat Sheet 2 | 3 | ## CREATE TABLE 4 | 5 | ```sql 6 | CREATE TABLE pet ( 7 | name VARCHAR(20), 8 | owner VARCHAR(20), 9 | species VARCHAR(20), 10 | sex CHAR(1), 11 | birth DATE, 12 | death DATE 13 | ); 14 | ``` 15 | -------------------------------------------------------------------------------- /Dev-Ops.md: -------------------------------------------------------------------------------- 1 | In /etc/apache2/envvars 2 | 3 | ``` 4 | export EXAMPLE="this is an example" 5 | ``` 6 | 7 | In /var/www/html/.php 8 | 9 | ``` 10 | 11 | 12 | // if PHP7, maybe you will need 13 | // to use $_SERVER[] or $_ENV[] 14 | ``` 15 | -------------------------------------------------------------------------------- /Redis/Redis.md: -------------------------------------------------------------------------------- 1 | # Redis 2 | 3 | Function | Command 4 | --- | --- 5 | Install | brew install redis 6 | Run server | redis-server /usr/local/etc/redis.conf 7 | Uninstall | brew uninstall redis && rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist 8 | Info | brew info redis 9 | 10 | -------------------------------------------------------------------------------- /Electron/Electron-Udemy.md: -------------------------------------------------------------------------------- 1 | # Electron 2 | 3 | ## Installation 4 | 5 | For installation, simply use `yarn add electron`. 6 | 7 | Once that is complete, create a file and require `electron`. 8 | 9 | ## Properties 10 | 11 | The most important property of Electron is the `app` property. 12 | 13 | 14 | -------------------------------------------------------------------------------- /React-Testing-Enzyme.md: -------------------------------------------------------------------------------- 1 | # Testing React Components with Enzyme 2 | 3 | ## Table of Contents 4 | 5 | title 6 | ---- title 7 | 8 |
9 | 10 | *** 11 | 12 | ## newSection 13 | 14 |
15 | 16 | ### ---- newSubSection -------------------------------------------------------------------------------- /React-Native-For-iOS-Devs.md: -------------------------------------------------------------------------------- 1 | # Intro to React Native for iOS Developers 2 | 3 | ## Benefits 4 | 5 | If you and build a RN app for iOS, you can also build it for Android! 6 | 7 | *** 8 | 9 | ### Installation 10 | 11 | Head to the page and follow the installation instructions. 12 | 13 | Initial installation is done via `homebrew`. -------------------------------------------------------------------------------- /JS-Express.md: -------------------------------------------------------------------------------- 1 | # JS Express 2 | 3 | ## Table of Contents 4 | 5 | SEC-1.1 7 | 8 |
9 | 10 | *** 11 | 12 | ## EXP-1: Getting set up with Express 13 | 14 | 15 | 16 |
17 | 18 | ### newSubSection 19 | -------------------------------------------------------------------------------- /AWS/Cloudfront-S3-Lets-Encrypt.md: -------------------------------------------------------------------------------- 1 | # Let's encrypt with CloudFront and S3 2 | 3 | 4 | Use this as a reference https://medium.com/@richardkall/setup-lets-encrypt-ssl-certificate-on-amazon-cloudfront-b217669987b2 5 | 6 | Ensure in Route53 that your domain name resolves to the alias record of the CloudFront instance and then attach the cert to CloudFront. 7 | -------------------------------------------------------------------------------- /iOS/Apple-Watch.md: -------------------------------------------------------------------------------- 1 | # Development on Apple Watch 2 | 3 | ## Time Tracker 4 | 5 | In Xcode, create a new `watchOS` app. 6 | 7 | Having the watchOS app paired to the iOS app is required. 8 | 9 | ### Storyboards 10 | 11 | Easiest way to build out the app is to use the storyboard. 12 | 13 | Everything for iOS is top to bottom. 14 | 15 | ## Outlets and actions 16 | 17 | -------------------------------------------------------------------------------- /Git-Remote-Help: -------------------------------------------------------------------------------- 1 | # Git Remote Help 2 | 3 | ## GITREM-1: Setting up the remote 4 | 5 | __On Github__ 6 | 7 | Create a new, empty repo. 8 | 9 | __On the command line__ 10 | 11 | ``` 12 | git init 13 | git commit -m "First Commit" 14 | git remote -v 15 | git remote remove origin 16 | git remote add origin git@github.com:user/repo.git 17 | git push -u origin master 18 | ``` 19 | -------------------------------------------------------------------------------- /smacss-cheat-sheet.scss: -------------------------------------------------------------------------------- 1 | # SMACSS CHEAT SHEET 2 | 3 | // references 4 | 5 | // https://smacss.com/book/categorizing 6 | 7 | # 8 | # 9 | # LAYOUT 10 | # 11 | # 12 | 13 | Base 14 | Layout 15 | Module 16 | State 17 | Theme 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Writing-Bash-Scripts.md: -------------------------------------------------------------------------------- 1 | # Writing Bash Scripts 2 | 3 | ## BASH-1: Setting up scripts 4 | 5 | __Change shell__ 6 | 7 | `exec [zsh|bash]` 8 | 9 | __Set env variable from bash__ 10 | 11 | ``` 12 | export EXAMPLE='/to/script/path' 13 | ``` 14 | 15 | __For cd, use aliases__ 16 | 17 | `alias proj="cd /home/tree/projects/java"` 18 | 19 | __Writing a Shell Script__ 20 | 21 | file.sh 22 | 23 | ``` 24 | #!/bin/bash 25 | 26 | ``` 27 | -------------------------------------------------------------------------------- /AWS/Namecheap-Route-53.md: -------------------------------------------------------------------------------- 1 | # Namecheap to Route 53 2 | 3 | ## Validating Google Mail 4 | 5 | Change the Simple DNS from Namecheap and point it to the custom name servers at AWS. 6 | 7 | On AWS, ensure that you head onto Route 53 and create a new set (forget the name right now) and take the NS data it gives you and post it into the DNS settings in Namecheap. Once that is done, set up Route 53 similar to how you set up everything on AWS. Give the URL to the S3 site as an alias record and set up the MX records as need be. 8 | 9 | -------------------------------------------------------------------------------- /Machine-Learning/CL-Classification-Intro.md: -------------------------------------------------------------------------------- 1 | # Classificiation 2 | 3 | Whereas regression is used to predict a continuous number, you use classification to predict a category. 4 | 5 | There is a wide variety of applications from medicine to marketing. 6 | 7 | We will learn the following models: 8 | 9 | 1. Logistic Regression 10 | 2. K-Nearest Neighbors (K-NN) 11 | 3. Support Vector Machine (SVM) 12 | 4. Kernel SVM 13 | 5. Naive Bayes 14 | 6. Decision Tree Classification 15 | 7. Random Forest Classification 16 | 17 | -------------------------------------------------------------------------------- /React-Native-Cheat-Sheet.md: -------------------------------------------------------------------------------- 1 | # React Native Help Sheet 2 | 3 | ## RNHELP-1: Debugger 4 | 5 | To stop the React Native dev menu from showing up, ensure that you put into `Release` 6 | 7 | ## RNHELP-2: (void) casting for iOS10 8 | 9 | ``` 10 | (void)SecRandomCopyBytes(kSecRandomDefault, keyBytes.length, keyBytes.mutableBytes); 11 | (void)SecRandomCopyBytes(kSecRandomDefault, sizeof(uint32_t), (uint8_t *)mask_key); 12 | ``` 13 | 14 | ## RNHELP-3: Code Signing 15 | 16 | If disallowed for build, turn off automatic signing, clean, close the project, up back up and then turn automatic signing back on. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cheat Sheets 2 | 3 | **UPDATED REPO IS AT https://github.com/okeeffed/developer-notes** 4 | 5 | This repo is more than deprecated. I've hardly pushed any notes here for the last year. 6 | 7 | Since I've come back to surprising interest, there is a separate repo that I have just made public that has a bunch more notes on top of these and other concepts I've had to deal with in more recent years (think Deep Learning, Kubernetes etc). 8 | 9 | That repo also publishes notes on a CD pipeline to here https://docs.dennisokeeffe.com/ 10 | 11 | Follow me on Twitter for rancid dev chat and good times https://twitter.com/d_okeeffe 12 | -------------------------------------------------------------------------------- /docker-code-sheet.md: -------------------------------------------------------------------------------- 1 | # Docker Code Sheet 2 | 3 | ## Deploy to Docker Cloud Button 4 | 5 | The button redirects the user to the Launch new Stack wizard, with the stack definition already filled with the contents of any of the following files. 6 | 7 | - docker-cloud.yml 8 | - docker-compose.yml 9 | - fig.yml 10 | 11 | **GitHub** 12 | 13 | [![Deploy to Docker Cloud](https://files.cloud.docker.com/images/deploy-to-dockercloud.svg)](https://cloud.docker.com/stack/deploy/) 14 | 15 | **Docker Cloud** 16 | [![Deploy to Docker Cloud](https://files.cloud.docker.com/images/deploy-to-dockercloud.svg)](https://cloud.docker.com/stack/deploy/?repo=) 17 | -------------------------------------------------------------------------------- /Drupal/Drupal-8-Modules.md: -------------------------------------------------------------------------------- 1 | # Drupal 8 Modules 2 | 3 | Create `/web/modules//=8.2.0) 17 | ``` 18 | 19 | ## Hooks 20 | 21 | `HOOK_entity_load()` 22 | 23 | Generally you can place hooks into one of three categories: 24 | 25 | 1. Hooks that answer a question 26 | 2. Hooks that alter existing data 27 | 3. Hooks that react to an action 28 | 29 | `hook_form_alter()` is one of the most powerful hooks. 30 | -------------------------------------------------------------------------------- /CocoaPods Workshop: -------------------------------------------------------------------------------- 1 | # COCOA PODS WORKSHOP 2 | 3 | ## PODS-1: Keywords 4 | 5 | To start the project, go to the project folder... 6 | 7 | pod init 8 | open -a Xcode Podfile 9 | 10 | Remove the pounds sign that sets the platform. 11 | 12 | Then under the #Pod for..., you can add your pods! 13 | 14 | Check cocoapods website for pods. 15 | 16 | Then, to install the selected pods, type... 17 | pod install 18 | 19 | Now, we will want to open up the .xcworkspace file! 20 | 21 | ## PODS-2: Updating 22 | 23 | Change the pod file... 24 | 25 | eg pod 'Hue', '~> 1.1.0' // update to anything up to 1.2 but not above 26 | 27 | THEN just back in terminal 28 | 29 | pod update 30 | -------------------------------------------------------------------------------- /Cpp-Udemy.md: -------------------------------------------------------------------------------- 1 | # C++ Udemy 2 | 3 | ## Variables 4 | 5 | **Datatypes** 6 | - int 7 | - short 8 | - float 9 | - double 10 | - char 11 | - bool 12 | - also can add `unsigned` 13 | 14 | ```cpp 15 | #include 16 | 17 | main() 18 | { 19 | cout << 4 << endl; // endl for endline 20 | int A = 4; 21 | } 22 | ``` 23 | 24 | ## Getting input 25 | 26 | ```cpp 27 | #include 28 | 29 | using namespace std 30 | 31 | main() { 32 | char *example; 33 | cin >> example; 34 | 35 | cout << "test"; 36 | } 37 | ``` 38 | 39 | ## 5: Arrays 40 | 41 | ```cpp 42 | main() 43 | { 44 | int arr[3] = {3,4,5}; 45 | for (int i=0; i < 3; i++) { 46 | cout << arr[i] << endl; 47 | } 48 | } 49 | ``` -------------------------------------------------------------------------------- /ES6-fiddle.md: -------------------------------------------------------------------------------- 1 | # ES6 Fiddle 2 | 3 | *** 4 | 5 | ## Map Function 6 | 7 | ``` 8 | let doubles = [1,2,3,4].map(v => v+1); 9 | console.log(doubles[0]); //2 10 | 11 | let terms = ["Ben", "Den", "Sam"]; 12 | console.log(terms.map(name => `I am ${name}`)); 13 | // I am Ben, I am Den, I am Sam 14 | ``` 15 | 16 | ## Arrow Function 17 | 18 | ``` 19 | let nums = [1,2,3,4,5,6]; 20 | let fives = []; 21 | 22 | nums.forEach(v => { 23 | if (v % 5 === 0) 24 | fives.push(v) 25 | }) 26 | 27 | console.log(fives); 28 | // print 5 29 | ``` 30 | 31 | ## Rest Parameter 32 | 33 | ``` 34 | function f (x, y, ...a) { 35 | return (x + y) * a.length; 36 | } 37 | console.log(f(1, 2, "hello", true, 7) === 9); 38 | // returns true 39 | ``` -------------------------------------------------------------------------------- /Npm-Create-Package.md: -------------------------------------------------------------------------------- 1 | # Create a NPM Package 2 | 3 | ## How to Sign Up 4 | 5 | - Sign up on npmjs.com 6 | - npm login 7 | - Create package.json 8 | - Test 9 | - Publish 10 | 11 | Within your project, ensure you .gitignore node_modules. 12 | 13 | If your program depends on another package, ensure you compile it on the local machine. 14 | 15 | On the `npm` website, you need to login. Ensure you complete the form! Your email will also be shown with all the packages. 16 | 17 | ## Once you've signed up 18 | 19 | `npm login` to be able to login. 20 | 21 | When you're inside the folder, ensure that you npm init. 22 | 23 | Entry point will be the main file in the project. 24 | 25 | If you have want to test this, you can use `npm install /path/to/package/` 26 | -------------------------------------------------------------------------------- /Docker-EC2.md: -------------------------------------------------------------------------------- 1 | # Docker EC2 2 | 3 | 4 | 5 | * [Docker EC2](#docker-ec2) 6 | * [Steps](#steps) 7 | * [Useful Commands](#useful-commands) 8 | 9 | 10 | 11 | ## Steps 12 | 13 | 1. Deploy an EC2 Instance 14 | 2. Install Docker onto that instance 15 | 3. Create SSH Key 16 | 4. Add that the key to Github 17 | 5. Git pull using that key 18 | 6. Docker build 19 | 20 | [Installing Docker onto EC2](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html) 21 | [Github: Generating SSH Keys](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/) 22 | 23 | ## Useful Commands 24 | 25 | * `docker build . -t='dok/name:latest'` 26 | * `docker run -p 80:80 -d -t dok/name:latest` 27 | -------------------------------------------------------------------------------- /Swift-DOK-Code-Examples: -------------------------------------------------------------------------------- 1 | # Swift DOK Example Code 2 | 3 | ## SWIFTDOK-1: AppDelegate 4 | 5 | #### ---- SWIFTDOK-1.1: Set up the initial NIB file 6 | 7 | ``` 8 | class AppDelegate: UIResponder, UIApplicationDelegate { 9 | 10 | var window: UIWindow? 11 | 12 | 13 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 14 | // Override point for customization after application launch. 15 | 16 | window = UIWindow(frame: UIScreen.main.bounds) 17 | if let window = window { 18 | window.backgroundColor = UIColor.white 19 | window.rootViewController = ExampleViewController() 20 | window.makeKeyAndVisible() 21 | } 22 | return true 23 | } 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cheat-sheets", 3 | "version": "1.0.0", 4 | "description": "List of help sheets", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/okeeffed/cheat-sheets.git" 12 | }, 13 | "author": "Dennis O'Keeffe", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/okeeffed/cheat-sheets/issues" 17 | }, 18 | "homepage": "https://github.com/okeeffed/cheat-sheets#readme", 19 | "dependencies": { 20 | "dot-env": "0.0.1", 21 | "dotenv": "^4.0.0", 22 | "gulp": "^3.9.1", 23 | "gulp-git": "^2.2.0", 24 | "gulp-shell": "^0.6.3", 25 | "run-sequence": "^1.2.2" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /d3/D3.md: -------------------------------------------------------------------------------- 1 | # D3 2 | 3 | This all relates back to "D3 in action". Check back to the book for more info. 4 | 5 | ## The power of d3 6 | 7 | The main power of d3 comes through the ability to select document elements 8 | `d3.selectAll("circle.a").style("fill", "red").attr("cx", 100);` 9 | 10 | This takes every circle on our page with the class of "a" and turns it red and moves it so that its center is 100 pixels to the right of the left side of our canvas. 11 | 12 | ## Working with arrays 13 | 14 | ``` 15 | someNumbers = [17, 82, 9, 500, 40]; 16 | someColors = ["blue", "red", "chartreuse", "orange"]; 17 | ``` 18 | 19 | One example of a useful array function is .filter(), which returns an array whose elements satisfy a test you provide. For instance, here’s how to create an array out of someNumbers that had values greater than 40: 20 | 21 | `someNumbers.filter(function(el) {return el >= 40});` 22 | -------------------------------------------------------------------------------- /Terminal/Tips-and-Tricks.md: -------------------------------------------------------------------------------- 1 | # Tips and Tricks 2 | 3 | 4 | 5 | * [Tips and Tricks](#tips-and-tricks) 6 | * [Dealing with records](#dealing-with-records) 7 | * [Load balancing](#load-balancing) 8 | * [Ports](#ports) 9 | 10 | 11 | 12 | ## Dealing with records 13 | 14 | `curl -I ` 15 | 16 | Example response: 17 | 18 | ``` 19 | HTTP/1.1 301 Moved Permanently 20 | x-amz-id-2: GhbglnY4TMT7NQy4HEFfBbrYo1L6OgepT1130/R80lZm6yDUCH8Ok 21 | x-amz-request-id: C72E7BA4D7A6DEB8 22 | Date: Thu, 31 Aug 2017 22:51:42 GMT 23 | Location: https://www.domain.com/ 24 | Content-Length: 0 25 | Server: AmazonS3 26 | ``` 27 | 28 | `dig afxr gitgood.club` - gives back record data. 29 | 30 | ## Load balancing 31 | 32 | `ab -n 1000 -c 50 "https://staging.aemc.prescoapps.co/"` - test Load Balance with reqs 33 | . 34 | 35 | ## Ports 36 | 37 | `sudo lsof -i :3090` - what's using port 3090. 38 | 39 | `telnet redrooster.com.au 22` - Does the server at redrooster.com.au listen on port 22 (standard ssh port)? 40 | -------------------------------------------------------------------------------- /ios-objc-cheat-sheet.md: -------------------------------------------------------------------------------- 1 | # iOS Cheat Sheet 2 | 3 | ## OBJIOS-1: Open Settings 4 | 5 | ```objective-c 6 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; 7 | ``` 8 | 9 | # Dates and Time 10 | 11 | ## Check if the time is between two hours 12 | 13 | ```objective-c 14 | -(void)checkTimeFrame 15 | { 16 | NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]]; 17 | NSInteger currentHour = [components hour]; 18 | 19 | if (currentHour < 9 && currentHour > 3) { 20 | // Do Something 21 | NSLog(@"In between the times"); 22 | NSLog(@"%ld\n", (long)currentHour); 23 | } else { 24 | NSLog(@"Not between the times"); 25 | NSLog(@"%ld\n", (long)currentHour); 26 | } 27 | } 28 | ``` 29 | 30 | # UISearchBar 31 | 32 | ## Target Search Bar after load 33 | 34 | ```objective-c 35 | -(void)viewDidAppear:(BOOL)animated 36 | { 37 | [self.searchBar becomeFirstResponder]; 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /Docker/MySQL-Development.md: -------------------------------------------------------------------------------- 1 | # MySQL Development using Docker 2 | 3 | Firstly, pull `docker pull mysql/mysql-server`. 4 | 5 | Then `docker run --name sql-test -e MYSQL_ROOT_PASSWORD=password -p 6000:3306 -d mysql/mysql-server:latest`. If there a replacement or commited image, run that instead. 6 | 7 | If you are running it on a network, first create the network `docker network create dev-env`, then run with the `--net` flag to hook it up. 8 | 9 | `docker run --name sql-test -e MYSQL_ROOT_PASSWORD=password -p 6000:3306 --net dev-env -d mysql/mysql-server:latest`. 10 | 11 | Linking `docker run -d -name app-container-name --link mysql-container-name app-image-name`. 12 | 13 | ## Updating the local Docker MySQL instance 14 | 15 | Log into the container and first log into `mysql` using `mysql -u root -p`. This will prompt you for that password we created, so now type that in and enter the command line terminal. First, run `CREATE USER 'admin'@'%' IDENTIFIED BY 'password';` Run `GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;`. Finally, run `FLUSH PRIVILEGES;`. 16 | -------------------------------------------------------------------------------- /Android/Lists-And-Adapters.md: -------------------------------------------------------------------------------- 1 | # Lists and Adapters in Android 2 | 3 | **What is an adapter?** 4 | 5 | If we have our data and a list view, we can then use an adapter to adapt data for the view. 6 | 7 | Android provides a number of different adapters. 8 | 9 | Example with the `ArrayAdapter`, it is an extension of the `BaseAdapter`. 10 | 11 | Declaring a string adapter would be `ArrayAdapter` that can deal with generic types. We specify the type within the angle brackets. 12 | 13 | ```java 14 | package teamtreehouse.com.stormy.ui; 15 | 16 | import ... 17 | 18 | static class DailyForecastActivity extends ListActivity { 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_daily_forecast); 23 | 24 | String[] daysOfTheWeek = { 25 | "Sunday", 26 | "Monday", 27 | ... 28 | } 29 | ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, 30 | daysOfTheWeek); 31 | 32 | setListAdapter(adapter); 33 | } 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /Python-Intermediate-Data-Science.md: -------------------------------------------------------------------------------- 1 | # Python - Intermediate Data Science 2 | 3 | 4 | 5 | * [Python - Intermediate Data Science](#python---intermediate-data-science) 6 | * [PYINT-1: Matplotlib](#pyint-1-matplotlib) 7 | * [---- PYINT-1.1: Basic plots](#-----pyint-11-basic-plots) 8 | 9 | 10 | 11 | ## PYINT-1: Matplotlib 12 | 13 | ### ---- PYINT-1.1: Basic plots 14 | 15 | Using `pyplot` 16 | 17 | ```python 18 | # import pyplot 19 | import matplotlib.pyplot as plt 20 | 21 | year = [1950, 1970, 1990, 2010] 22 | pop = [2.519, 3.692, 5.263, 6.972] 23 | 24 | # make a plot 25 | plt.plot(year, pop) 26 | 27 | # show a plot 28 | plt.show() 29 | ``` 30 | 31 | How do we create a scatter plot? 32 | 33 | ```python 34 | # import pyplot 35 | import matplotlib.pyplot as plt 36 | 37 | year = [1950, 1970, 1990, 2010] 38 | pop = [2.519, 3.692, 5.263, 6.972] 39 | 40 | # make a plot 41 | plt.scatter(year, pop) 42 | 43 | # show a plot 44 | plt.show() 45 | ``` 46 | 47 | The basic ingredients of pyplot 48 | 49 | ``` 50 | import matplotlib.pyplot as plt 51 | plt.plot(x,y) 52 | plt.show() 53 | ``` 54 | 55 | You can use certain commands to show a different scale 56 | 57 | ``` 58 | plt.xscale('log') 59 | ``` 60 | -------------------------------------------------------------------------------- /Intro-To-Scala.md: -------------------------------------------------------------------------------- 1 | # Intro to Scala 2 | 3 | Builds on top of the JVC. Scala also does things like treating functions as first class citizens. You define functions without names and as closures. 4 | 5 | The adoption of Scala use it for a variety of projects. 6 | 7 | Apache Spark is also written in Scala. 8 | 9 | There are two ways to create variables: `val` (constant) and `var` (mutable). 10 | 11 | ```scala 12 | scala> val greeting = "Hello World!" 13 | greeting: String = Hello World! 14 | 15 | scala> greeting = "Allo" 16 | :12: error: reassignment to val 17 | greeting = "Allo" 18 | ^ 19 | 20 | scala> var mes = "Hello!" 21 | mes: String = Hello! 22 | 23 | scala> mes 24 | res0: String = Hello! 25 | 26 | scala> mes = "Hello World!" 27 | mes: String = Hello World! 28 | 29 | scala> mes 30 | res1: String = Hello World! 31 | ``` 32 | 33 | We can always provide type information or the semi-colon if we wanted to, although not recommended (interesting they would say this...). 34 | 35 | ## Function Declarations 36 | 37 | Last evaluation implicitly returned. 38 | 39 | You must declare return type for a recursive function though. 40 | 41 | ```scala 42 | def multipliedByTwo(x: Int) = (x == 0) x else x*2 43 | 44 | def multipliedByTen(x: Double = 10, y: Double): Double { 45 | x * y 46 | } 47 | ``` -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gutil = require('gulp-util'); 2 | var fs = require('fs'); 3 | var gulp = require('gulp'); 4 | var spawn = require('child_process').spawn; 5 | var git = require('gulp-git'); 6 | var runSequence = require('run-sequence'); 7 | require('dotenv').load(); 8 | 9 | gulp.task("watch", function () { 10 | gulp 11 | .watch([ 12 | // "*.md", 13 | "Business/*.md", 14 | ".env" 15 | ]) 16 | .on("change", function (file) { 17 | var list = file 18 | .path 19 | .split('/'); 20 | fileName = list[list.length - 1]; 21 | 22 | var prefix = ""; 23 | var suffix = ""; 24 | 25 | if (process.env.TASK) { 26 | prefix = process.env.TASK + " - "; 27 | } 28 | 29 | if (process.env.DESCRIPTION) { 30 | suffix = ": " + process.env.DESCRIPTION; 31 | } 32 | 33 | var gitChange = prefix + fileName + suffix; 34 | 35 | gutil.log(gitChange + " changed"); 36 | 37 | var gitAdd = spawn('./gitcommit.sh', [gitChange]); 38 | gitAdd 39 | .stdout 40 | .on('data', function (data) { 41 | gutil.log('gitcommit: ', data.toString().slice(0, -1)); // Remove \n 42 | }); 43 | // runSequence('push'); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /js-grid-alignment-cheat-sheet.md: -------------------------------------------------------------------------------- 1 | # JavaScript Grid Alignment Cheat Sheet 2 | 3 | ```javascript 4 | /* 5 | This example comes from the NPWS grid system 6 | */ 7 | 8 | var grid = { 9 | 10 | row: [], 11 | perRow: 0, 12 | height: 0, 13 | small: 767, 14 | medium: 1190, 15 | 16 | $grid: $('.grid'), 17 | $tile: $('.grid .tile'), 18 | 19 | init: function () { 20 | grid.resize(); 21 | 22 | $(window).resize(grid.resize); 23 | }, 24 | 25 | resize: function () { 26 | if ($(window).outerWidth() < grid.small) { 27 | grid.$tile.find('.info').height('auto'); 28 | } else { 29 | grid.$tile.each(function (key) { 30 | if ((key) % grid.elemPerRow + 1 === 1 && (key !== 0)) { 31 | grid.setHeight(); 32 | grid.height = 0; 33 | grid.row = []; 34 | } 35 | 36 | grid.row.push(this); 37 | 38 | if ($(this).find('.info').height() > grid.height) { 39 | grid.height = $(this).find('.info').height(); 40 | } 41 | }); 42 | 43 | if (grid.row.length) { 44 | grid.setHeight(); 45 | } 46 | } 47 | }, 48 | 49 | setHeight: function () { 50 | for (var i in grid.row) { 51 | $(grid.row[i]).find('.info').height(grid.height); 52 | } 53 | }, 54 | 55 | getElemPerRow: function () { 56 | if ($(window).outerWidth() > grid.medium) { 57 | grid.elemPerRow = 3; 58 | } else if ($(window).outerWidth() > grid.small) { 59 | grid.elemPerRow = 2; 60 | } else { 61 | grid.elemPerRow = 1; 62 | } 63 | }, 64 | }; 65 | ``` 66 | -------------------------------------------------------------------------------- /Ethereum/Course.md: -------------------------------------------------------------------------------- 1 | # Udemy ETH Course 2 | 3 | ## Short History 4 | 5 | - Oct 31, 2008: BTC White paper describing system that could pay each other directly without need of central authority. 6 | - Dec, 2013: 7 | - ETH White paper for need for more programmatic control over transactions 8 | - Wanted to enabled creation of decentralized austonomous corporations (DAC) 9 | - Introduces the idea of "Smart Contracts" as an entity that can send and recieve currency, beyond just humans 10 | - The "Smart Contract" lives within the Ethereum blockchain 11 | 12 | ### So what is ETH? 13 | 14 | **Primitive description:** 15 | 16 | - ETH networks are used to transfer money and store data 17 | - Different ETH networks 18 | - Networks are formed by one or more nodes 19 | - Each node is a machine running an ETH client 20 | - Anyone can run a node 21 | - Each node can contain a full copy of the blockchain 22 | 23 | You can also create your own private ETH network for testing etc. There is not just one network; there are many. 24 | 25 | ## Interfacing with ETH networks 26 | 27 | Some of the common ways: 28 | 29 | **Dev Tech:** 30 | - web3.js (our "portal" to the ETH network) 31 | 32 | **Consumers:** 33 | - Metamask (Chrome extension to interact) 34 | - Mist Browser (Full feature web browser) 35 | 36 | ### Metamask Extension 37 | 38 | - Test contracts will be done on Rinkeby Test Network 39 | 40 | ## ETH Accounts 41 | 42 | Metamask creates an account address, public key and private key. 43 | 44 | -------------------------------------------------------------------------------- /Server-Side-React/Create-React-App-Server-Side.md: -------------------------------------------------------------------------------- 1 | # create-react-app Server Side bootstrapping 2 | 3 | 1. npm run eject 4 | 2. Update config/paths.js 5 | 6 | ```javascript 7 | // config/paths.js 8 | 9 | module.exports = { 10 | ... 11 | appServer: resolveApp('server'), 12 | serverIndexJs: resolveApp('src/server.js'), 13 | ... 14 | } 15 | ``` 16 | 17 | 3. Create a `webpack.config.server.js` file. 18 | 4. Install `webpack-node-externals`. 19 | 20 | As described on the github: 21 | 22 | _Webpack allows you to define externals - modules that should not be bundled._ 23 | 24 | _When bundling with Webpack for the backend - you usually don't want to bundle its node_modules dependencies. This library creates an externals function that ignores node_modules when bundling in Webpack._ 25 | 26 | ``` 27 | const path = require('path'); 28 | const paths = require('./paths'); 29 | const webpackNodeExternals = require('webpack-node-externals'); 30 | 31 | module.exports = { 32 | // Target Nodehs 33 | target: 'node', 34 | // Looking for the root of server app 35 | entry: paths.serverIndexJs, 36 | output: { 37 | // The build folder. 38 | path: paths.appServer, 39 | filename: 'server.js' 40 | }, 41 | // Run Babel on every file 42 | module: { 43 | rules: [ 44 | { 45 | test: /\.js?$/, 46 | loader: 'babel-loader', 47 | exclude: /node_modules/, 48 | options: { 49 | presets: [ 50 | 'react', 51 | 'stage-0', 52 | ['env', { targets: { browsers: ['last 2 versions']}}] 53 | ] 54 | } 55 | } 56 | ] 57 | }, 58 | externals: [webpackNodeExternals()] 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /pdo-cheat-sheet.md: -------------------------------------------------------------------------------- 1 | # PDO Help Sheet 2 | 3 | // Full website list 4 | 5 | http://php.net/manual/en/class.pdostatement.php 6 | 7 | ## Setting up and making a query 8 | 9 | ```php 10 | setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 31 | $sql = "SELECT * FROM user"; 32 | // use exec() because no results are returned 33 | foreach($conn->query($sql) as $row){ 34 | echo $row['name'] . "\t"; 35 | echo $row['email'] . "\t"; 36 | echo $row['password'] . "\n"; 37 | } 38 | } 39 | catch(PDOException $e) 40 | { 41 | echo $sql . "
" . $e->getMessage(); 42 | } 43 | 44 | $conn = null; 45 | 46 | ?> 47 | ``` 48 | 49 | ## Treehouse Query Challenge 50 | 51 | ```php 52 | query("SELECT member_id, email, fullname, level FROM members"); 58 | */ 59 | $user = $results->fetchAll(PDO::FETCH_ASSOC); 60 | foreach ($user as $key) 61 | { 62 | send_offer( 63 | $key['member_id'], 64 | $key['email'], 65 | $key['fullname'], 66 | $key['level']); 67 | } 68 | ?> 69 | ``` 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Python-Slack-Bot.md: -------------------------------------------------------------------------------- 1 | # Add a Slack Bot! 2 | 3 | // this needs to be finished 4 | 5 | ## Table of Contents 6 | 7 | title 8 | ---- title 9 | 10 |
11 | 12 | *** 13 | 14 | ## Intro 15 | 16 | First of all, clone the `python_rtmbot` git repo. 17 | 18 | Then, head to slack.com for your personal account, click `build` from the apps page and add a custom bot. 19 | 20 | Grab the API token and copy it into a `rtmbot.conf` file at the root of your directory. 21 | 22 |
23 | 24 | ### ---- Creating plugins 25 | 26 | In the `plugins` folder, create a folder with the name of the plugin and then within the `plugin.py` itself. Inside, you want to ensure you have a `outputs = []` and `crontable = []` list ready to go. 27 | 28 | From here, you can define processes as so: `def process_namehere(data):`. 29 | 30 | The data argument is the data recieved by the bot. 31 | 32 |
33 | 34 | ### ---- Banana Plugin 35 | 36 | In the `plugins` directory, create `banana.py` 37 | 38 | ```python 39 | import random 40 | 41 | from nltk.tokenize import sent_tokenizem wordpunct_tokenize 42 | from noun_hound import NounHound 43 | 44 | crontable = [] 45 | outputs = [] 46 | 47 | nh = NounHound() 48 | 49 | def process_message(data): 50 | messaage = data['text'] 51 | sentences = sent_tokenize(message) 52 | sentences_num = random.randint(0, len(sentences) - 1) 53 | setence = sentences[stence_num] 54 | words = wordpunct_tokenize(sentence) 55 | nouns = nh.process(sentence) 56 | replacement = random.choice(nouns['nouns']) 57 | words[words.index(replacement) = 'banana'] 58 | sentences[sentence_num] = ' '.join(words) 59 | outputs.append([data["channel"], ' '.join(sentences)]) 60 | ``` 61 | -------------------------------------------------------------------------------- /AWS/AWS-NodeSDK.md: -------------------------------------------------------------------------------- 1 | # AWS Node SDK 2 | 3 | 4 | 5 | * [AWS Node SDK](#aws-node-sdk) 6 | * [Loading Credentials in Node.js from Environment Variables](#loading-credentials-in-nodejs-from-environment-variables) 7 | * [Example use in a task runner - get EC2 Details back](#example-use-in-a-task-runner---get-ec2-details-back) 8 | 9 | 10 | 11 | ## Loading Credentials in Node.js from Environment Variables 12 | 13 | * AWS_ACCESS_KEY_ID 14 | * AWS_SECRET_ACCESS_KEY 15 | * AWS_SESSION_TOKEN (optional) 16 | 17 | These can be set into your ENV variables. 18 | 19 | ## Example use in a task runner - get EC2 Details back 20 | 21 | ```javascript 22 | var fs = require('fs'); 23 | const util = require('util'); 24 | var dotenv = require('dotenv'); 25 | var envConfig = dotenv.parse(fs.readFileSync('.env')); 26 | for (var k in envConfig) { 27 | process.env[k] = envConfig[k]; 28 | } 29 | 30 | var gulp = require('gulp'); 31 | 32 | // Load the SDK for JavaScript 33 | var AWS = require('aws-sdk'); 34 | 35 | var params = { 36 | InstanceIds: [process.env.EC2_INSTANCE_ID] 37 | }; 38 | 39 | /* Get EC2 Details */ 40 | gulp.task('info', function() { 41 | AWS.config = { 42 | accessKeyId: process.env.AWS_ACCESS_KEY, 43 | secretAccessKey: process.env.AWS_SECRET_KEY, 44 | region: process.env.AWS_REGION 45 | }; 46 | 47 | // Create EC2 service object 48 | ec2 = new AWS.EC2({ apiVersion: '2016-11-15' }); 49 | 50 | // Call EC2 to retrieve the policy for selected bucket 51 | ec2.describeInstances(params, function(err, data) { 52 | if (err) { 53 | console.log('Error', err.stack); 54 | } else { 55 | console.log('Success', util.inspect(data, { depth: 6 })); 56 | } 57 | }); 58 | }); 59 | ``` 60 | -------------------------------------------------------------------------------- /CSS-Style-Guide.md: -------------------------------------------------------------------------------- 1 | # CSS Style Guide 2 | 3 | ## Table of Contents 4 | 5 | Ordering 6 | Structure 7 | 8 | 9 |
10 | 11 | *** 12 | 13 | ## CSS Ordering 14 | 15 | ```css 16 | .selector { 17 | /* Positioning */ 18 |  position: absolute; 19 |  z-index: 10; 20 |  top: 0; 21 |  right: 0; 22 | 23 |  /* Display & Box Model */ 24 |  display: inline-block; 25 |  overflow: hidden; 26 |  box-sizing: border-box; 27 |  width: 100px; 28 |  height: 100px; 29 |  padding: 10px; 30 |  border: 10px solid #333; 31 |  margin: 10px; 32 | 33 |  /* Color */ 34 |  background: #000; 35 |  color: #fff 36 |   37 |  /* Text */ 38 |  font-family: sans-serif; 39 |  font-size: 16px; 40 |  line-height: 1.4; 41 |  text-align: right; 42 | 43 |  /* Other */ 44 |  cursor: pointer; 45 | } 46 | ``` 47 | 48 |
49 | 50 | *** 51 | 52 | ## CSS Structure 53 | 54 |
55 | 56 | ### ---- One Component per file 57 | 58 | For each component, place them in their own file. 59 | 60 | ```css 61 | /* css/components/search-form.scss */ 62 | .search-form { 63 | > .button { /* ... */ } 64 | > .field { /* ... */ } 65 | > .label { /* ... */ } 66 | 67 | // variants 68 | &.-small { /* ... */ } 69 | &.-wide { /* ... */ } 70 | } 71 | ``` 72 | 73 |
74 | 75 | ### ---- Nesting 76 | 77 | Use no more than 1 level of nesting. It's easy to get lost with too much nesting. 78 | 79 | ``` 80 | /* ✗ Avoid: 3 levels of nesting */ 81 | .image-frame { 82 | > .description { 83 | /* ... */ 84 | 85 | > .icon { 86 | /* ... */ 87 | } 88 | } 89 | } 90 | 91 | /* ✓ Better: 2 levels */ 92 | .image-frame { 93 | > .description { /* ... */ } 94 | > .description > .icon { /* ... */ } 95 | } 96 | ``` -------------------------------------------------------------------------------- /Nginx/Nginx-Nodejs-Docker.md: -------------------------------------------------------------------------------- 1 | # Docker container with Nginx and Nodejs 2 | 3 | First create a directory for both `nginx` and `nodejs`. 4 | 5 | Within the Node folder, create a `Dockerfile` that contains the following to expose an app running on a particular port: 6 | 7 | ``` 8 | FROM mhart/alpine-node 9 | # Pretend to copy the node app entry 10 | # from current folder 11 | COPY index.js . 12 | # Expose the port that it is running on 13 | EXPOSE 3000 14 | # Run node - chances are you want pm2 here 15 | CMD node index.js 16 | ``` 17 | 18 | Then we can build with `docker built -t foo/node .` 19 | 20 | After the build, run the container with port 3000 exposed using `docker run -d -p 3000:3000 --name node-app foo/node`. 21 | 22 | First, we can test the Nginx latest container container using `docker run --rm -p 8000:80 nginx` to test out nginx:latest. This just removes the container after running. 23 | 24 | In the `nginx` folder, we can create `default.conf` file to overwrite the initial one. 25 | 26 | If settings are not defined below, Nginx will use the default values. 27 | 28 | ``` 29 | # config 30 | server { 31 | location / { 32 | # host name first 33 | proxy_set_header Host $host; 34 | # extra headers for host IP address 35 | proxy_set_header X-Real-IP $remote_addr; 36 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 37 | # passing protocol used (http | https) 38 | proxy_set_header X-Forwarded-Proto $scheme; 39 | # where to proxy reqs to 40 | proxy_pass http://app:3000; 41 | } 42 | } 43 | ``` 44 | 45 | For the Docker file. 46 | 47 | ``` 48 | FROM nginx 49 | COPY default.cong /etc/nginx/conf.d/ 50 | ``` 51 | 52 | Then build out this file using `docker built -t foo/nginx .`. 53 | 54 | Running it: `docker run -p 8000:80 --link node-app:app --name nginx-proxy foo/nginx` 55 | 56 | Since we expose 3000 for the node-app, we do not need to redo that. 57 | -------------------------------------------------------------------------------- /Laravel-5.4.md: -------------------------------------------------------------------------------- 1 | # Laravel 5.4 2 | 3 | ## Laravel Installation and Composer 4 | 5 | Laravel is a PHP framework - basic. 6 | 7 | Laravel also requires composer. 8 | 9 | | Commands | Description | 10 | | ----------- | ----------- | 11 | | `composer global require "laravel/installer"` | Global install command laravel | 12 | | `laravel new blog` | Create a new blog | 13 | | `composer create-project --prefer-dist laravel/laravel blog` | Create Blog with Composer Create-Project | 14 | | `php artisan serve` | Serve the project locally | 15 | 16 | If you are adding the `laravel` command globally, then ensure `$HOME/.composer/vendor/bin:$PATH` is in your path. 17 | 18 | ## Basic Routing and Views 19 | 20 | There will be a whole bunch of files etc after generating a Laravel program. 21 | 22 | Likely we can ignore the middleware once we're in the situation that requires it. 23 | 24 | The `routes` is where you will find the routes. 25 | 26 | This will do a standard `Routes::get('/', function () {})` for the `blade` template engine. 27 | 28 | **Defining** 29 | 30 | ```php 31 | Route::get('/welcome', function () { 32 | return view('welcome') 33 | }); 34 | ``` 35 | 36 | ## Laravel Valet 37 | 38 | In the `Dev Environments`, you can see `Homestead` and `Valet` - `Homestead` is a preconfigured Vagrant box which uses VMs. 39 | 40 | `Valet` is specifically for the Mac. It is a Laravel Dev Environment. No need to set up or alter any files. 41 | 42 | If you go `laravel new app` you could straight away hit up `app.dev`. 43 | 44 | This requires PHP 7.1. You can install `Valet` with composer as a global requirement. Run `valet install`. 45 | 46 | `brew services start mysql` will start `mysql` if it was installed via Brew and you're wishing to use. 47 | 48 | `valet park` is used to park the root of the directory that you wish to use for finding projects. 49 | 50 | `valet secure` will even secure the website. -------------------------------------------------------------------------------- /flexbox-help-sheet.md: -------------------------------------------------------------------------------- 1 | # Flexbox Help Sheet 2 | 3 | Sources: 4 | 5 | [CSS Tricks](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) 6 | 7 | ## Terminology 8 | 9 | #### Flex Container (parent) 10 | 11 | Properties of the parent: 12 | 13 | ```css 14 | .container { 15 | display: flex; /* or inline-flex */ 16 | flex-direction: row | row-reverse | column | column-reverse; 17 | flex-wrap: nowrap | wrap | wrap-reverse; 18 | flex-flow: <‘flex-direction’> || <‘flex-wrap’>; //shorthand code 19 | justify-content: flex-start | flex-end | center | space-between | space-around; 20 | align-items: flex-start | flex-end | center | baseline | stretch; 21 | align-content: flex-start | flex-end | center | space-between | space-around | stretch; 22 | } 23 | ``` 24 | 25 | #### Flex Items (child) 26 | 27 | Properties of the child: 28 | 29 | ```css 30 | .item { 31 | order: ; 32 | flex-grow: ; /* default 0 */ 33 | flex-shrink: ; /* default 1 */ 34 | flex-basis: | auto; /* default auto */ 35 | flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]; 36 | align-self: auto | flex-start | flex-end | center | baseline | stretch; 37 | } 38 | ``` 39 | 40 | ## Example 41 | 42 | ```css 43 | .parent { 44 | display: flex; 45 | height: 300px; /* Or whatever */ 46 | } 47 | 48 | .child { 49 | width: 100px; /* Or whatever */ 50 | height: 100px; /* Or whatever */ 51 | margin: auto; /* Magic! */ 52 | } 53 | 54 | .flex-container { 55 | /* We first create a flex layout context */ 56 | display: flex; 57 | 58 | /* Then we define the flow direction and if we allow the items to wrap 59 | * Remember this is the same as: 60 | * flex-direction: row; 61 | * flex-wrap: wrap; 62 | */ 63 | flex-flow: row wrap; 64 | 65 | /* Then we define how is distributed the remaining space */ 66 | justify-content: space-around; 67 | } 68 | ``` 69 | -------------------------------------------------------------------------------- /Unity/Unity-Basics.md: -------------------------------------------------------------------------------- 1 | # Unity Basics 2 | 3 | 4 | 5 | * [Unity Basics](#unity-basics) - [Overview](#overview) - [Scene View - Navigation and Positioning](#scene-view---navigation-and-positioning) - [Scene View Controls](#scene-view-controls) - [The Game View](#the-game-view) - [The Toolbar](#the-toolbar) 6 | 7 | 8 | 9 | The initial `default layout` is the initial arrangement. You can change the layout on the top right. 10 | 11 | ### Overview 12 | 13 | The hierarchy is on the left side of the screen. It's the list of objects in the scene. 14 | 15 | The bottom part is full of the assets. 16 | 17 | The main screen has the `scene` and `game` views that allow you to see different perspectives. 18 | 19 | There are also a number of different preset values that you can use as well. 20 | 21 | You can also use the tab and drag to rearrange the view. 22 | 23 | ### Scene View - Navigation and Positioning 24 | 25 | A quick navigation is to right click and use the arrows to move around. You can also use the mouse to change the direction of view. 26 | 27 | `F` key after selecting an object will focus in on the object. 28 | 29 | You can orbit by holding `alt` and dragging. 30 | 31 | | Position Tools | 32 | | -------------- | 33 | | Q: Pan | 34 | | W: Move | 35 | | E: Rotate | 36 | | R: Scale | 37 | 38 | ### Scene View Controls 39 | 40 | The `scene gizmo` is the viewing angle at the top right. 41 | 42 | The `shaded` dropdown is to switch between different dropdowns. 43 | 44 | The lighting is good for checking scenes that are or are not dark. 45 | 46 | You can use the gizmos dropdown to switch between gizmos. 47 | 48 | You can use the search box in order to find elements quickly. 49 | 50 | ### The Game View 51 | 52 | The game view will show what the game will look like at the end. 53 | 54 | You can select 2 by 3 to see a view of everything. 55 | 56 | ### The Toolbar 57 | -------------------------------------------------------------------------------- /th_understanding_this_js: -------------------------------------------------------------------------------- 1 | /******************************************/ 2 | 3 | Understanding "this" in JavaScript 4 | 5 | /******************************************/ 6 | 7 | 4 ways that "this" takes a value: 8 | 9 | 1. In normal function calls 10 | 2. Within methods on objects 11 | 3. Within an object that has been constructed 12 | 4. A function invoked with .call, .apply, or bind 13 | 14 | /****************/ 15 | First way 16 | /****************/ 17 | 18 | function helloWorld() { 19 | console.log("Hello world!"); 20 | }; 21 | 22 | //"this"in a browser, it's the window 23 | // bit different in node.js 24 | 25 | /****************/ 26 | Second way 27 | /****************/ 28 | 29 | //this is done using Node 30 | 31 | var Portland = { 32 | bridges: 12, 33 | airport: 1, 34 | soccerTeams: 1, 35 | logNumberOfBridges: function() { 36 | console.log("There are " + this.bridges + " bridges in Portland!") 37 | }, 38 | logTeams: function() { 39 | console.log(this.soccerTeams); 40 | } 41 | } 42 | 43 | //another way of logteams using this 44 | function logTeams() { 45 | console.log(this.soccerTeams); 46 | //if the word was just this, it would print all node info 47 | } 48 | 49 | Portland.foo = logTeams; 50 | 51 | Portland.logNumberOfBridges(); 52 | Portland.logTeams(); 53 | Portland.foo(); 54 | logTeams(); //comes back as undefined 55 | 56 | /****************/ 57 | Third way 58 | /****************/ 59 | 60 | var City = function(name, state) { 61 | this.name = name || 'Portland'; 62 | this.state = state || 'Oregon'; 63 | this.printMyCityAndState = function() { 64 | console.log("My city is " + this.name + ", and my state is " + this.state); 65 | }; 66 | }; 67 | 68 | portland = new City(); 69 | seattle = new City('Seattle', 'Washington'); 70 | 71 | console.log(portland); 72 | console.log(seattle); 73 | 74 | portland.printMyCityAndState(); 75 | seattle.printMyCityAndState(); 76 | 77 | - Note: Corresponds to the instance value itself 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /th_npm_as_a_task_runner: -------------------------------------------------------------------------------- 1 | NPM as a Task Runner 2 | 3 | ///////////////////////////////////////////////////////// 4 | 5 | What is a task? Something we need to do. 6 | 7 | Common Tasks 8 | - run test suite 9 | - compilng Sass/TypeScript/CoffeeScript 10 | - starting a web server 11 | - starting a worker 12 | 13 | npm tasks are called scripts -> add to 'scripts' in package.json 14 | 15 | "": "" 16 | 17 | then you can simply go... 18 | 19 | npm run ! 20 | 21 | Types of tasks: 22 | 1. Built-in 23 | - eg tests etc 24 | - can be run as npm test instead of npm run test 25 | 26 | 2. Arbitrary 27 | - requires a "run" 28 | - eg npm run compile 29 | 30 | For getting a project ready to be deployed... 31 | 32 | in the tests folder... test_dice.js //used in this example 33 | 34 | mocha is used as a mocha and uglify-js to compile all js files into one. 35 | 36 | Often encouraged to save global test scripts. 37 | 38 | node_modules/.bin/mocha //this is an executable 39 | 40 | Can run from npm without writing this. 41 | 42 | Change "test": "mocha" in the scripts. 43 | 44 | now we can go... 45 | 46 | npm run test //don't even need run since it is built-in 47 | 48 | ////////////////////////////////////////// 49 | 50 | Creating our own arbitrary scripts 51 | 52 | We can use the uglify to create an app.js 53 | 54 | Large, annoying code... 55 | node_modules/.bin/uglifyjs src/models/* src/frontend.js -m -c -o build/app.js 56 | 57 | //m flag reduces some names 58 | //c combines into single file 59 | 60 | INSTEAD, CREATE OUR OWN TASK 61 | 62 | "uglify": "node_modules/.bin/uglifyjs src/models/* src/frontend.js -m -c -o build/app.js" 63 | 64 | Now, we can just type: 65 | npm run uglify 66 | 67 | And TADAAAAA! 68 | 69 | For our css etc. 70 | 71 | "copy-files": "cp src/*.html build/ & cp src/*.css build/" 72 | 73 | npm run copy-files 74 | 75 | Now for a single task! 76 | 77 | "build": "npm run copy-files && npm run uglify" //&& run sequentially, & run in parallel 78 | 79 | npm help scripts //shows other default scripts 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Machine-Learning/ML-Random-Forest-Regression.md: -------------------------------------------------------------------------------- 1 | # Random Forest Regression 2 | 3 | ## Intuition 4 | 5 | Random forest is a version of ensemble learning. 6 | 7 | It's when you take the same algorithm multiple times and create something more powerful. 8 | 9 | **Steps** 10 | 11 | 1. Pick at random K data points from the Training Set. 12 | 2. Build the Decision Tree associated to these K data points. 13 | 3. Choose the number Ntree of trees you want to build and repeat steps 1 and 2. 14 | 4. For a new data point, make each one of your Ntree trees predict the value of `Y` for the data point in question, and assign the new data point the average across all the predicted `Y` values. 15 | 16 | Doing this allows you to improve the accuracy of your prediction. 17 | 18 | **Example** 19 | 20 | How many lollies in a jar? Imagine taking notes of every guess - getting around 1000 and then beginning to average them out or take the median. Statistically speaking, you have a highly likelihood of being closer to the truth. 21 | 22 | Once you hit the middle of the normal distribution, you are more likely to be on the money for the guess. 23 | 24 | ## PYTHON 25 | 26 | This is the last regression model. If you understand decision tree regression, you'll understand random forest. 27 | 28 | From decision tree, we know that we will need the visualisation using the non-continuous result. 29 | 30 | For the regressor, we use RandomForestRegressor library. 31 | 32 | ```python 33 | # Prediciting the Random Forest results 34 | # Create the Regressor 35 | from sklearn.ensemble import RandomForestRegressor 36 | regressor = RandomForestRegressor(random_state=0) 37 | regressor.fit(X, y) 38 | ``` 39 | 40 | Simply, with these lines, we can already determine that the graph is no longer continuous. 41 | 42 | By having several decision trees, we end up with a lot more "steps" than we had with just one decision tree. 43 | 44 | More tree !== more steps. The more trees you have, the more the average will converge towards the same average. 45 | 46 | Generally the steps will become better placed depending on the average. 47 | -------------------------------------------------------------------------------- /WP-PC-Setup-Cheat-Sheet.md: -------------------------------------------------------------------------------- 1 | ######## 2 | 3 | ! CHECK THE READ ME BEFORE ANYTHING ELSE 4 | 5 | ### 1. Install Bower 6 | 7 | bower install 8 | 9 | ### 2. Install Node Dependencies 10 | 11 | npm install 12 | 13 | ### 3. Install Composer Dependencies 14 | 15 | composer install // if others needed, check and manually move into folder in wp-content 16 | 17 | ### 4. Copy Across WordPress Files 18 | 19 | Locate the folder in finder, copy the files and paste them at the root of the project 20 | 21 | ### 5. Set MAMP to the correct folder 22 | 23 | Create the Database in Sequel Pro 24 | 25 | ### 6. Create Database 26 | 27 | Create the Database in Sequel Pro 28 | 29 | ### 7. Open the Localhost and begin the WP set up 30 | 31 | ! Ensure that the database is created in Sequel Pro 32 | 33 | Set the database field to the database name 34 | Set username and password to what is set for MAMP 35 | Run the Install 36 | 37 | ### 8. Open the Localhost and begin the WP set up 38 | 39 | ### 9. Ensure that any other files/plugins required in the correct folder (in reference to 3) 40 | 41 | ### 10. gulp watch - ensure that the gulpfile.js is all sweet! 42 | 43 | ### 11. Ensure the correct plugins are active 44 | 45 | ### 12. Active the appropriate theme 46 | 47 | 48 | 49 | 50 | // ************* 51 | 52 | OTHER FILES 53 | 54 | /+++++++++++++++++/ 55 | 56 | acf-json files 57 | 58 | - used to create the custom fields in WP admin! 59 | 60 | /+++++++++++++++++/ 61 | 62 | CPT-UI (custom post types) 63 | 64 | CPT UI controls the post types themselves. 65 | Can be used to import the data. 66 | - this will create the acf-json files 67 | 68 | 69 | // ************* 70 | 71 | TROUBLESHOOTING 72 | 73 | /+++++++++++++++++/ 74 | 75 | !ISSUE - check the correct plugins are installed. 76 | 77 | Steps: 78 | 79 | Check the wp_options under the Content tab 80 | Alter the template and stylesheet to work with an earlier version 81 | 82 | /+++++++++++++++++/ 83 | 84 | !ISSUE - admin password/database not showing 85 | 86 | Steps: 87 | 88 | Ensure the database has been set up 89 | Ensure gulp watch has compiled the file 90 | Ensure that the wp_config file is correctly set up for the wordpress admin stuff 91 | -------------------------------------------------------------------------------- /Stripe/Stripe-Node.md: -------------------------------------------------------------------------------- 1 | # Using Stripe with Node 2 | 3 | 4 | 5 | * [Using Stripe with Node](#using-stripe-with-node) 6 | * [Prereqs](#prereqs) 7 | * [Testing with Express](#testing-with-express) 8 | 9 | 10 | 11 | ## Prereqs 12 | 13 | 1. Sign up 14 | 2. `yarn add stripe` to your Node.js Project 15 | 3. Build out a server 16 | 17 | ## Testing with Express 18 | 19 | Configure the .env file and upload 20 | 21 | [Node Stripe Github](https://github.com/stripe/stripe-node) 22 | 23 | ```javascript 24 | const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); 25 | 26 | /* GET home page. */ 27 | module.exports = function(app) { 28 | app.get('/', function(req, res) { 29 | res.send('Server is healthy'); 30 | }); 31 | 32 | app.post('/', function(req, res) { 33 | console.log(req.body); 34 | // Create a new customer and then a new charge for that customer: 35 | stripe.customers 36 | .create({ 37 | email: 'foo-customer@example.com' 38 | }) 39 | .then(function(customer) { 40 | console.log(customer); 41 | return stripe.customers.createSource(customer.id, { 42 | source: { 43 | object: 'card', 44 | exp_month: 10, 45 | exp_year: 2018, 46 | number: '4242 4242 4242 4242', 47 | cvc: 100 48 | } 49 | }); 50 | }) 51 | .then(function(source) { 52 | return stripe.charges.create({ 53 | amount: 1600, 54 | currency: 'aud', 55 | customer: source.customer 56 | }); 57 | }) 58 | .then(function(charge) { 59 | // New charge created on a new customer 60 | console.log(charge); 61 | }) 62 | .catch(function(err) { 63 | // Deal with an error 64 | console.log(err); 65 | }); 66 | 67 | res.send('Post requests are healthy'); 68 | }); 69 | }; 70 | ``` 71 | -------------------------------------------------------------------------------- /Nightmare.md: -------------------------------------------------------------------------------- 1 | # Using Nightmare.js 2 | 3 | Nightmare.js with Mocha, Chai and Nightmare.js 4 | 5 | ```javascript 6 | var path = require('path'); 7 | var Nightmare = require('nightmare'); 8 | var should = require('chai').should(); 9 | 10 | describe('Nightmare demo', function () { 11 | this.timeout(15000); // Set timeout to 15 seconds, instead of the original 2 seconds 12 | 13 | var url = 'http://localhost:3000'; 14 | 15 | describe('Start page', function () { 16 | it('should show form when loaded', function (done) { 17 | new Nightmare() 18 | .goto(url) 19 | .evaluate(function () { 20 | return document.querySelectorAll('form').length; 21 | }, function (result) { 22 | result.should.equal(1); 23 | done(); 24 | }) 25 | .run(); 26 | }); 27 | }); 28 | 29 | describe('Send form', function () { 30 | it('should print the posted string on submit', function (done) { 31 | var expected = 'Hello, world!'; 32 | 33 | new Nightmare() 34 | .goto(url) 35 | .type('input[name="sometext"]', expected) 36 | .click('input[type="submit"]') 37 | .wait() 38 | .evaluate(function () { 39 | return document.querySelector('#result'); 40 | }, function (element) { 41 | element.innerText.should.equal(expected); 42 | done(); 43 | }) 44 | .run(); 45 | }); 46 | 47 | it('should print "nothing" on submit if no string were provided', function (done) { 48 | var expected = 'nothing'; 49 | 50 | new Nightmare() 51 | .goto(url) 52 | .click('input[type="submit"]') 53 | .wait() 54 | .evaluate(function () { 55 | return document.querySelector('#result'); 56 | }, function (element) { 57 | element.innerText.should.equal(expected); 58 | done(); 59 | }) 60 | .run(); 61 | }); 62 | }); 63 | }); 64 | ``` -------------------------------------------------------------------------------- /COMP3306-AI/3-A*-Algorithm.md: -------------------------------------------------------------------------------- 1 | # Week 3 - A* Algorithm 2 | 3 | **Aims** 4 | 5 | - A* search algorithm 6 | - How to invent admissible heuristics 7 | 8 | ## A* Search 9 | 10 | - UCS minimizes the cost so far `g(n)` 11 | - GS minimizes the estimated cost to the goal `h(n)` 12 | - A* combining UCS and GS 13 | - Evaluation function: `f(n)=g(n)+h(n)` 14 | - `g(n) = cost so far to reach n` 15 | - `h(n) = est. cost from n to goal` 16 | - `f(n) = est. total cost of path through n to the goal` 17 | 18 | The idea is that we take into account both the cost and estimated cost and combine them to decide which nodes to add to the fringe queue! 19 | 20 | **BFS and UCS Special Case** 21 | 22 | - BFS is a special case of A* when f(n)=depth(n) 23 | - BFS is also a special case of UCS when g(n)=depth(n) 24 | - UCS is a special case of A* when h(n)=0 25 | 26 | ## Admissible Heauristic 27 | 28 | - Heuristic `h(n)` is admissible if for every node n: 29 | - `h(n) <= h*(n)` where `h*(n)` is the true cost to reach a goal from `n` 30 | - The estimate to reach the goal is smaller or equal to the true cost to reach the goal 31 | - Admissible heuristics are `optimistic` - they think that the cost of solving the problem is less than it actually is. 32 | - heuristic never overestimates actual cost -> it is admissible 33 | 34 | **Theorem** 35 | 36 | If `h` is an `admissible heuristic` than A* is complete and optimal. 37 | 38 | How to check? 39 | 40 | See if the estimated cost for a node is <= the actual cost from that node to the goal node. 41 | 42 | ## Optimality of A* - Proof 43 | 44 | Compare f(G2) and f(G) 45 | 46 | 1. f(G2)=g(G2)+h(G2) (by definition) = g(G2) as h(G2)=0, G2 is a goal 47 | 2. f(G)=g(G)+h(G) (by definition) = g(G) as h(G)=0, G is a goal 48 | 3. g(G2)>g(G) as G2 is suboptimal 49 | 4. => f(G2)>f(G) by substituting 1) and 2) into 3) 50 | 5. f(n)=g(n)+h(n) (by definition) 51 | 6. h(n) <= h*(n) where h*(n) is the true cost from n to G (as h is admissible) 52 | 7. => f(n)<=g(n) + h*(n) (5 & 6) 53 | 8. = g(G) path cost from S to G via n 54 | 9. g(G) = f(G) as f(G)=g(G)+h(G)=g(G)+0 as h(G)=0, G is a goal 55 | 10. => f(n)<=f(G) (7,8,9) 56 | - Thus f(G) n will be expanded not G2; A* will not select G2 for expansion 59 | 60 | ## Dominance 61 | 62 | Two admissibleheuristics h(1) and h(2) 63 | - `h[2]` dominates `h[1]` if for all nodes `n` we have `h[2](n) >= h[1](n)` -------------------------------------------------------------------------------- /Mongo-DB-Code-Guide.md: -------------------------------------------------------------------------------- 1 | # Mongo Cheat Sheet 2 | 3 | ## MONGO-1: Mongo Install 4 | 5 | ``` 6 | npm install mongoose --save 7 | 8 | // to run 9 | 10 | mongod // starts the daemon 11 | mongo // check out the documents 12 | ``` 13 | 14 | ## MONGO-2: Mongo Shell 15 | 16 | ``` 17 | show dbs — // display the databases 18 | use bookworm — // specify the database you're going to work with 19 | show collections — // shows the document collections for the selected database 20 | db.users.find() — // display all the documents in the users collection 21 | db.users.find().pretty() — // nicer format for output documents within the shell 22 | db.users.drop() — // remove the users collection from the current database 23 | ``` 24 | 25 | ## MONGO-3: Mongo Sample Usage 26 | 27 | ```javascript 28 | // models > user.js 29 | 30 | var mongoose = require('mongoose'); 31 | 32 | var UserSchema = new mongoose.Schema({ 33 | email: { 34 | type: String, 35 | required: true, 36 | trim: true, 37 | unique: true, 38 | }, 39 | name: { 40 | type: String, 41 | required: true, 42 | trim: true, 43 | }, 44 | favoriteBook: { 45 | type: String, 46 | required: true, 47 | trim: true 48 | }, 49 | password: { 50 | type: String, 51 | required: true 52 | } 53 | }); 54 | 55 | var User = mongoose.model('User', UserSchema); 56 | module.exports = User; 57 | 58 | // in app.js 59 | 60 | var User = require('../models/user'); 61 | ``` 62 | 63 | ## MONGO-4: Building an Example Schema in the `mock` folder 64 | 65 | ``` 66 | // mock/example.js 67 | 68 | import mongoose from 'mongoose'; 69 | 70 | const schema = new mongoose.Schema({ 71 | question: String, 72 | answer: String, 73 | completed: Boolean 74 | }); 75 | 76 | export const model = mongoose.model('Layout', schema); 77 | ``` 78 | 79 | ## MONGO-5: Accessing the Schema results 80 | 81 | ``` 82 | // in a route file 83 | var express = require('express'); 84 | var router = express.Router(); 85 | 86 | import {ExampleModel} from '../models/example'; 87 | 88 | /* GET users listing. */ 89 | router.get('/', (req, res) => { 90 | console.log(ExampleModel); 91 | ExampleModel.find({}, "test string", (err, results) => { 92 | if (err) { 93 | return res.status(500).json({message: err.message}); 94 | } 95 | res.json({ results: results }); 96 | }); 97 | // res.json({ todos: "todos" }); 98 | // res.send('respond with a resource'); 99 | }); 100 | 101 | module.exports = router; 102 | ``` -------------------------------------------------------------------------------- /Google-Play.md: -------------------------------------------------------------------------------- 1 | # Google Play 2 | 3 | ## Virtual Devices 4 | 5 | Genymotion is useful to grab a bunch of different emulators for Android and come with a personal use or paid license. 6 | 7 | The device version and Genymotion may need to be aligned, so to do so, create a new Virtual Device. 8 | 9 | This can be easily done by selecting `Create`, choosing a device and then naming it to something useable like `reactnative`. 10 | 11 | ## Testing the app on the emulator 12 | 13 | To do so, first run the emulator. After the emulator is up and running, use `react-native run-android` on the CLI to start the app. The CLI will respond if there are any errors. 14 | 15 | ## Uploading to the Google Play Store 16 | 17 | ## Debugging 18 | 19 | **General Notes** 20 | 21 | Running a build from the IDE will generally give better support for debugging issues and auto-updating code. 22 | 23 | Some errors I've come across: 24 | 25 | | Error | Resolution | 26 | | --- | --- | 27 | | `error: could not install *smartsocket* listener: Address already in use` | Ensure socket not in use eg no `gulp watch` | 28 | | Component Install error | Update your install for `android/build.gradle` (look for buildToolsVersion) - Android Studio can automate this for you | 29 | | `Could not get BatchedBridge, make sure your nundle is packaged correctly` | Run `react-native start` from the CLI and reload app | 30 | | UNMET PEER DEPENDENCY | `rm -rf node-modules/ && npm cache clear && npm install` | 31 | | `protected boolean getUseDeveloperSupport()` issue | Change `protected` to `public` (Java Error) | 32 | | `@providesModule naming collision` | If caused by react-native-router-flux -> update or search Github | 33 | | Full cache reset | watchman watch-del-all && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache | 34 | 35 | **react-native-router-flux issues** 36 | 37 | This one was a bit tricky - some useful Github pages: 38 | 39 | https://github.com/aksonov/react-native-router-flux/issues/1803 40 | https://github.com/facebook/react-native/issues/13390 41 | https://github.com/react-community/react-navigation/issues/923 42 | https://github.com/aksonov/react-native-router-flux/issues/1816 43 | 44 | **General React Native Commands** 45 | 46 | - `react-native upgrade` - upgrade the files being used 47 | - `react-native-git-upgrade` - newer upgrade (needs to be install globally first) 48 | 49 | **Issues with React/ build path in Xcode?** 50 | 51 | https://github.com/oblador/react-native-vector-icons/issues/373 52 | 53 | **Other issues** 54 | 55 | - Ensure Cocoapods is up to date `sudo gem install cocoapods` -------------------------------------------------------------------------------- /Chef/Chef-General.md: -------------------------------------------------------------------------------- 1 | # Chef General 2 | 3 | 4 | 5 | * [Chef General](#chef-general) 6 | * [kitchen commands](#kitchen-commands) 7 | * [Chef ops layout](#chef-ops-layout) 8 | 9 | 10 | 11 | ## kitchen commands 12 | 13 | | Commands | Action | 14 | | --------------------- | ---------------------------------- | 15 | | kitchen test | Tear down & restart full build | 16 | | kitchen converge | Re-run recipes on already built VM | 17 | | kitchen list | List all the VM IDs | 18 | | kitchen verify | Verify kitchen tests | 19 | | kitchen login | Login to a local VM | 20 | | kitchen destroy | Tear down instance | 21 | 22 | ## Chef ops layout 23 | 24 | Without the hidden files. 25 | 26 | ``` 27 | . 28 | ├── Berksfile 29 | ├── Berksfile.lock 30 | ├── README.md 31 | ├── cookbooks 32 | │   ├── example 33 | │   │   ├── files 34 | │   │   │   └── default 35 | │   │   │   ├── known_hosts # accessible with cookbook_file 36 | │   │   │   └── ssh_config 37 | │   │   ├── metadata.rb 38 | │   │   ├── recipes 39 | │   │   │   ├── configure.rb 40 | │   │   │   └── default.rb 41 | │   │   └── templates 42 | │   │   ├── newrelic-node.erb 43 | │   │   ├── nginx-node.erb 44 | │   │   └── ssh-key.erb 45 | │   ├── example-api 46 | │   │   ├── metadata.rb 47 | │   │   ├── recipes 48 | │   │   │   ├── configure.rb 49 | │   │   │   ├── default.rb 50 | │   │   │   └── deploy.rb 51 | │   │   └── templates 52 | │   │   └── env.erb 53 | │   ├── example-bot 54 | │   │   ├── metadata.rb 55 | │   │   ├── recipes 56 | │   │   │   ├── configure.rb 57 | │   │   │   ├── default.rb 58 | │   │   │   └── deploy.rb 59 | │   │   └── templates 60 | │   │   └── env.erb 61 | │   └── example-db 62 | │   ├── metadata.rb 63 | │   ├── recipes 64 | │   │   ├── configure.rb 65 | │   │   ├── default.rb 66 | │   │   └── deploy.rb 67 | │   └── templates 68 | │   └── env.erb 69 | ├── publish.sh 70 | └── test 71 | ├── data_bags 72 | │   ├── data_app 73 | │   │   ├── data_api.json 74 | │   │   ├── data_bot.json 75 | │   │   └── data_db.json 76 | │   └── data_command 77 | │   ├── deploy_data_api.json 78 | │   ├── deploy_data_bot.json 79 | │   └── deploy_data_db.json 80 | ├── environments 81 | │   ├── test.json 82 | │   └── test.json.example 83 | └── smoke 84 | ├── test 85 | │   └── default_test.rb 86 | ├── second 87 | │   └── default_test.rb 88 | └── third 89 | └── default_test.rb 90 | ``` 91 | -------------------------------------------------------------------------------- /th_laravel_basics.md: -------------------------------------------------------------------------------- 1 | # LARAVEL 4 BASICS 2 | 3 | ## Getting Started with Laravel 4 | 5 | #### Installing VirtualBox, Homestead & Vagrant 6 | 7 | 1. Download VirtualBox for your OS from their website 8 | 2. Download Vagrant for your OS from their website 9 | 3. Use a command to install install Homestead 10 | 11 | `vagrant box add laravel/homestead` 12 | 13 | In a shell, check that you have SSH. 14 | 15 | ``` 16 | cd ~ 17 | ls -la 18 | # check for .ssh 19 | ``` 20 | 21 | If not, you can generate a key. 22 | 23 | In terminal: 24 | 25 | ``` 26 | ssh-keygen -t rsa -C "youremail@email.com". 27 | ``` 28 | 29 | There is also a great guide on GitHub. 30 | 31 | https://help.github.com/articles/generating-an-ssh-key/ 32 | 33 | ** Init the Homestead.yaml file ** 34 | 35 | ```bash init.sh``` 36 | 37 | In ~/Homestead, alter the Homestead.yaml file. 38 | 39 | 1. Replace "me" with the User 40 | 2. Under "folders" where it has the map and to, change the to direction to have .../Sites if you don't want the default and to follow along with TH. 41 | 42 | Sites we can change to anything. Eg. laravel.dev 43 | 44 | Ensure sites is okay too and that the Sites// is laravel-basics/public 45 | 46 | Run the Vagrant Up command in terminal `vagrant up` 47 | 48 | If there is a host issue, change the Homestead.yaml host. 49 | 50 | ** Getting into the box ** 51 | 52 | Connect via SSH 53 | 54 | run `vagrant ssh` 55 | 56 | #### Install Laravel 57 | 58 | Ensure composer is installed on your external SSH OS. 59 | 60 | Run `composer global require "laravel/installer"` 61 | 62 | ** Composer Create-Project ** 63 | 64 | ``` 65 | composer create-project --prefer-dist laravel/laravel laravel-basics 66 | ``` 67 | 68 | Alternatively... 69 | 70 | ``` 71 | laravel new laravel-basics 72 | ``` 73 | 74 | **Note** laravel-basics can be swapped for anything. 75 | 76 | Run pwd and check this against what you have in ~/.homestead/Homestead.yaml 77 | 78 | Then jump to the site (127.0.0.1:8000) to see if it is running successfully. 79 | 80 | To get rid of the 127.0.0.1, we can change it to another host. 81 | 82 | cd /etc from the Homestead file and adjust the hosts file in a text editor to make the website easier to navigate to. 83 | 84 | #### Laravel Folder Structure 85 | 86 | 87 | 88 | *** 89 | 90 | ## Project Setup 91 | 92 | *** 93 | 94 | ## Laravel Controllers 95 | 96 | *** 97 | 98 | ## Laravel and Databases 99 | 100 | *** 101 | 102 | ## Blade and Forms 103 | 104 | *** 105 | 106 | ## Validation & Flash Messages 107 | 108 | *** 109 | 110 | ## Continuing CRUD 111 | 112 | *** 113 | 114 | ## Relating Data 115 | -------------------------------------------------------------------------------- /React-Native-With-SCSS.md: -------------------------------------------------------------------------------- 1 | # React Native with CSS and SCSS 2 | 3 | ## React Native to CSS/SCSS Node Package 4 | 5 | [This is the link to the package](https://github.com/sabeurthabti/react-native-css) 6 | 7 | This package converts css/scss to a .js file that we can use in the react-native component/container files. 8 | 9 | __Instructions__ 10 | 11 | Install globally `npm install react-native-css -g` 12 | 13 | Now we can run `react-native-css -i INPUT_CSS_FILE -o OUTPUT_JS_FILE --watch` - check the .md 14 | 15 | __! IMPORTANT: Rules for the SASS File__ 16 | 17 | The target classes _NEED be written in camel case_ 18 | 19 | __Basic Example: style.css__ 20 | 21 | ``` 22 | .container { 23 | margin-top: 75; 24 | align-items: center; 25 | } 26 | 27 | .image { 28 | width: 107; 29 | height: 165; 30 | padding: 10; 31 | } 32 | 33 | .descriptionCamelCaseExample { 34 | padding: 10; 35 | font-size: 25; 36 | color: #656565; 37 | } 38 | ``` 39 | 40 | If we run `react-native-css -i ./style.css -o ./style.js --watch` 41 | 42 | The following will be in style.js 43 | 44 | ``` 45 | module.exports = require('react-native').StyleSheet.create({ 46 | "container": { 47 | "marginTop":75, 48 | "alignItems":"center" 49 | }, 50 | "image": { 51 | "width":107, 52 | "height":165, 53 | "padding":10 54 | }, 55 | "descriptionCamelCaseExample": { 56 | "padding":10, 57 | "fontSize":25, 58 | "color":"#656565"} 59 | }); 60 | ``` 61 | 62 | In the respective component js file, you will now need to import this. 63 | 64 | ``` 65 | 'use strict'; 66 | 67 | // var React = require('react-native'); 68 | import React, { Component } from 'react'; 69 | import styles from './style.js'; 70 | 71 | import { 72 | StyleSheet, 73 | Text, 74 | View, 75 | Image 76 | } from 'react-native'; 77 | 78 | class ExampleComponentOrContainer extends Component { 79 | render() { 80 | 81 | // example variable declarations 82 | // not directly relevant to explanation 83 | var book = this.props.book; 84 | var imageURI = (typeof book.volumeInfo.imageLinks !== 'undefined') ? book.volumeInfo.imageLinks.thumbnail : ''; 85 | var description = (typeof book.volumeInfo.description !== 'undefined') ? book.volumeInfo.description : ''; 86 | 87 | return ( 88 | 89 | // use style = {styles.} 90 | // to apply the styles 91 | 92 | 93 | 94 | {description} 95 | 96 | ); 97 | } 98 | } 99 | 100 | export { BookDetail }; 101 | ``` 102 | 103 | Happy days! 104 | -------------------------------------------------------------------------------- /React-Animations.md: -------------------------------------------------------------------------------- 1 | # Animations in React 2 | 3 | 4 | 5 | * [Animations in React](#animations-in-react) 6 | * [REACTAN-1: Installation](#reactan-1-installation) 7 | * [REACTAN-2: Using CSS to now run the Transitions and Transforms](#reactan-2-using-css-to-now-run-the-transitions-and-transforms) 8 | 9 | 10 | 11 | # REACTAN-1: Installation 12 | 13 | React Transistions can be done use the `ReactCSSTransitionGroup`. 14 | 15 | Since React uses the virtual DOM, we don't get a chance to directly apply a CSS transition like you normally would with jQuery or JS. 16 | 17 | To install: `yarn add react-addons-css-transition-group` 18 | 19 | In the JS file: 20 | 21 | ``` 22 | // within some component 23 | ... 24 | import ReactCSSTransitionGroup from 'react-addons-css-transition-group'; 25 | ... 26 | 27 | class Transition extends Component { 28 | 29 | ... 30 | 31 | render() { 32 | return { 33 | 34 | { list } 35 | 36 | } 37 | } 38 | } 39 | ``` 40 | 41 | By default, renders as a `span`, but we can give it a `component` property to change it! E.g. `` 42 | 43 | To access the property for animations, we need to set a property of `transitionName`. 44 | 45 | E.g. `` 46 | 47 | There are a couple of other noteworthy properties: 48 | 49 | ``` 50 | 58 | { list } 59 | 60 | ``` 61 | 62 | # REACTAN-2: Using CSS to now run the Transitions and Transforms 63 | 64 | ``` 65 | // in the css file 66 | 67 | /* start enter state */ 68 | .slide-enter { 69 | transform: translateX(-100%); 70 | } 71 | 72 | /* end enter state */ 73 | .slide-enter.slide-enter-active { 74 | transform: translateX(0); 75 | transition: transform 0.5s ease-out; 76 | } 77 | 78 | /* start leave state */ 79 | .slide-leave { 80 | transform: translateX(0); 81 | } 82 | 83 | /* end leave state */ 84 | .slide-leave.slide-leave-active { 85 | transform: translateX(-100%); 86 | opacity: 0; 87 | transition: 0.5s ease-in; 88 | } 89 | 90 | /* initial mounting */ 91 | .slide-appear { 92 | opacity: 0; 93 | } 94 | 95 | .slide-appear.slide-appear-active { 96 | opacity: 1; 97 | transition: opacity 0.5s ease-in; 98 | } 99 | ``` 100 | -------------------------------------------------------------------------------- /Webpack.md: -------------------------------------------------------------------------------- 1 | # Webpack 2 | 3 | For results from this, the react gen will have the results of the Webpack tutorial installed! 4 | 5 | It is important that you generate this folder or refer to the Treehouse course files. 6 | 7 | Because the way Webpack current stands and how it is designed, think of using it for React projects. 8 | 9 | ## Table of Contents 10 | 11 | title 13 | 14 |
15 | 16 | *** 17 | 18 | ## WEB-1: Webpack - The Why. 19 | 20 | Build Tasks 21 | 22 | 1. Module loading 23 | 24 | Looks for `require` and `import` statements. This helps prevents errors. 25 | 26 | 2. Concatenation 27 | 28 | Combining several files into one for loading performance. Minimal HTTP reqs. 29 | 30 | 3. Minification 31 | 32 | Compressing/extraction unnecessary lines and characters. 33 | 34 |
35 | 36 | ## WEB-2: Webpack Config 37 | 38 | Webpack is an opinionated tool. If you stick to industry standard, you won't need to do much config. 39 | 40 | 41 | Config is done in `webpack.config.js` 42 | 43 | For now, we'll just look at 3 configuration properties: 44 | 45 | ``` 46 | 1. entry 47 | 2. output 48 | 3. module 49 | ``` 50 | 51 | The file looks like so: 52 | 53 | ``` 54 | var HtmlWebpackPlugin = require("html-webpack-plugin"); 55 | 56 | // ensure all the webpack dependencies are installed 57 | var webpackConfig = { 58 | entry: "./src/app.js", 59 | output: { 60 | path: "build", 61 | filename: "bundle.js" 62 | }, 63 | module: { 64 | loaders: [ 65 | { 66 | // used to ensure js loads 67 | loader: "babel-loader", 68 | test: /\.js$/ 69 | } 70 | ] 71 | } 72 | } 73 | ``` 74 | 75 | `entry` can be specified with a string for a single entry point or an object for multiple entry points. 76 | 77 | `output` used for building for production - which folder to place your build in and what file to have the bundled file. 78 | 79 | `module` many properties that are used to config webpack. Loaders will be used for using installed loaders. 80 | 81 |
82 | 83 | *** 84 | 85 | ## WEB-3: Building an app 86 | 87 | Webpack has it's own CLI tool. 88 | 89 | In the example file from the TH lesson, index.js is the entry point and index.ejs is then used to inject JS into a HTML file. 90 | 91 | We're going to define a npm script for webpack. 92 | 93 | ``` 94 | // in package.json 95 | ... 96 | "script": { 97 | "build": "webpack --optimize-minimize" 98 | } 99 | ... 100 | ``` 101 | 102 |
103 | 104 | *** 105 | 106 | ## WEB-4: Webpack Dev Server 107 | 108 | `webpack-dev-server` is an npm file you can use for serving, however you can just flag `webpack --watch` and run from MAMP if you want. 109 | 110 |
111 | 112 | *** 113 | 114 | ## WEB-5: Adding Styles 115 | 116 | Loaders are extensions that enable more webpack config options. 117 | 118 |
119 | 120 | *** 121 | 122 | ## WEB-6: Loaders 123 | 124 | Source maps, fonts etc. 125 | 126 | We can pipe loaders. 127 | -------------------------------------------------------------------------------- /Swift-3-Methods.md: -------------------------------------------------------------------------------- 1 | # Swift 3 Methods 2 | 3 | 4 | 5 | * [Swift 3 Methods](#swift-3-methods) 6 | * [Mutating Methods](#mutating-methods) 7 | 8 | 9 | 10 | --- 11 | 12 | ## Mutating Methods 13 | 14 | Structures and enumerations are value types. By default, the properties of a value type cannot be modified from within its instance methods. 15 | 16 | However, if you need to modify the properties of your structure or enumeration within a particular method, you can opt in to mutating behavior for that method. The method can then mutate (that is, change) its properties from within the method, and any changes that it makes are written back to the original structure when the method ends. The method can also assign a completely new instance to its implicit self property, and this new instance will replace the existing one when the method ends. 17 | 18 | You can opt in to this behavior by placing the mutating keyword before the func keyword for that method: 19 | 20 | ``` 21 | struct Point { 22 | var x = 0.0, y = 0.0 23 | mutating func moveBy(x deltaX: Double, y deltaY: Double) { 24 | x += deltaX 25 | y += deltaY 26 | } 27 | } 28 | var somePoint = Point(x: 1.0, y: 1.0) 29 | somePoint.moveBy(x: 2.0, y: 3.0) 30 | print("The point is now at (\(somePoint.x), \(somePoint.y))") 31 | // Prints "The point is now at (3.0, 4.0)" 32 | ``` 33 | 34 | Note that you cannot call a mutating method on a constant of structure type, because its properties cannot be changed, even if they are variable properties, as described in Stored Properties of Constant Structure Instances: 35 | 36 | ``` 37 | let fixedPoint = Point(x: 3.0, y: 3.0) 38 | fixedPoint.moveBy(x: 2.0, y: 3.0) 39 | // this will report an error 40 | ``` 41 | 42 | **Assigning to self Within a Mutating Method** 43 | 44 | Mutating methods can assign an entirely new instance to the implicit self property. The Point example shown above could have been written in the following way instead: 45 | 46 | ``` 47 | struct Point { 48 | var x = 0.0, y = 0.0 49 | mutating func moveBy(x deltaX: Double, y deltaY: Double) { 50 | self = Point(x: x + deltaX, y: y + deltaY) 51 | } 52 | } 53 | ``` 54 | 55 | This version of the mutating moveBy(x:y:) method creates a brand new structure whose x and y values are set to the target location. The end result of calling this alternative version of the method will be exactly the same as for calling the earlier version. 56 | 57 | Mutating methods for enumerations can set the implicit self parameter to be a different case from the same enumeration: 58 | 59 | ``` 60 | enum TriStateSwitch { 61 | case off, low, high 62 | mutating func next() { 63 | switch self { 64 | case .off: 65 | self = .low 66 | case .low: 67 | self = .high 68 | case .high: 69 | self = .off 70 | } 71 | } 72 | } 73 | 74 | var ovenLight = TriStateSwitch.low 75 | ovenLight.next() 76 | // ovenLight is now equal to .high 77 | ovenLight.next() 78 | // ovenLight is now equal to .off 79 | ``` 80 | 81 | This example defines an enumeration for a three-state switch. The switch cycles between three different power states (off, low and high) every time its next() method is called. 82 | -------------------------------------------------------------------------------- /npm-cheat-sheet.md: -------------------------------------------------------------------------------- 1 | # npm help sheet 2 | 3 | ## install npm dependencies 4 | 5 | ``` 6 | npm install 7 | ``` 8 | 9 | ## USEFUL NPM DEPENDENCIES 10 | 11 | #### MONGOOSE - database helper for MongoDB 12 | 13 | ``` 14 | npm install --save mongoose 15 | 16 | mongod // starts the daemon 17 | mongo // check out the documents 18 | ``` 19 | 20 | 21 | ```javascript 22 | var User = mongoose.model('User', UserSchema); 23 | module.exports = User; 24 | 25 | // in app.js 26 | var User = require('../models/user'); 27 | ``` 28 | 29 | #### BCRYPT - used for hashing and salting 30 | 31 | ``` 32 | npm install --save bcrypt 33 | ``` 34 | 35 | ```javascript 36 | // in User.js 37 | var bcrypt = require('bcrypt'); 38 | UserSchema.pre('save', function(next) { 39 | var user = this; 40 | bcrypt.hash(user.password, 10, function(err, hash) { 41 | if (err) { 42 | return next(err); 43 | } 44 | user.password = hash; 45 | next(); 46 | }) 47 | }); 48 | 49 | UserSchema.statics.authenticate = function(email, password, callback) { 50 | User.findOne({ email: email }) 51 | .exec(function (error, user) { 52 | if (error) { 53 | return callback(error); 54 | } else if (!user) { 55 | var err = new Error('User not found.'); 56 | err.status = 401; 57 | return callback(err); 58 | } 59 | bcrypt.compare(password, user.password, function (error, result) { 60 | if (result === true) { 61 | return callback(null, user); 62 | } else { 63 | return callback(); 64 | } 65 | }); 66 | }); 67 | } 68 | 69 | // Example in app.js for Express 70 | 71 | router.post('/login', function(req, res, next) { 72 | if (req.body.email && req.body.password) { 73 | User.authenticate(req.body.email, req.body.password, function (error, user) { 74 | if (error || !user) { 75 | var err = new Error('Wrong email or password.'); 76 | err.status = 401; 77 | return next(err); 78 | } else { 79 | req.session.userId = user._id; 80 | return res.redirect('/profile'); 81 | } 82 | }); 83 | } else { 84 | var err = new Error('Email and password are required.'); 85 | err.status = 401; 86 | return next(err); 87 | } 88 | }); 89 | ``` 90 | 91 | 92 | #### EXPRESS SESSION - save sessions to use throughout the website 93 | 94 | ``` 95 | npm install express-session --save 96 | ``` 97 | 98 | ```javascript 99 | // in app.js 100 | 101 | var session = require('express-session'); 102 | 103 | // use sessions for tracking logins - check more in the readme 104 | app.use(session({ 105 | secret: 'treehouse loves you', 106 | resave: true, 107 | saveUninitialized: false 108 | })); 109 | 110 | // not useful when in production. check https://github.com/expressjs/session#compatible-session-stores 111 | ``` 112 | 113 | #### CONNECT-MONGO - used for quick middleware access to Mongo 114 | 115 | connect-mongo is a middleware already written for us! 116 | 117 | ``` 118 | npm install connect-mongo --save 119 | ``` 120 | 121 | ```javascript 122 | require MongoStore = require('connect-mongo')(session); 123 | 124 | // in app.js 125 | 126 | app.use(session({ 127 | secret: 'treehouse loves you', 128 | resave: true, 129 | saveUninitialized: false 130 | store: new MongoStore({ 131 | mongooseConnection: db 132 | }) 133 | })); 134 | ``` 135 | -------------------------------------------------------------------------------- /Vim/Vim.md: -------------------------------------------------------------------------------- 1 | # Vim 2 | 3 | 4 | 5 | - [Vim](#vim) 6 | - [Vim Packages and creating files](#vim-packages-and-creating-files) 7 | - [Vim modes, navigation and commands](#vim-modes--navigation-and-commands) 8 | - [Executing external commands](#executing-external-commands) 9 | - [Files and buffers](#files-and-buffers) 10 | 11 | 12 | 13 | ## Vim Packages and creating files 14 | 15 | Installing Vim `yum install vim` of `apt-get install vim`. 16 | 17 | `vim -g` can actually run the GUI - who cares though. There are a number of different GUI wrappers. `gvim` is the most popular. 18 | 19 | So we have `vi`, `vim` - the improved vi and `gvim`. 20 | 21 | ## Vim modes, navigation and commands 22 | 23 | 1. Command/Normal mode 24 | 2. Insert/Ex mode 25 | 3. Mark mode 26 | 27 | | Key | What it does | 28 | | ---------------------- | --------------------------------- | 29 | | x | Delete character | 30 | | :q! | Quit and omit changes | 31 | | :wq | Write and quit | 32 | | : | "File mode" | 33 | | h | Left | 34 | | j | Down | 35 | | k | Up | 36 | | l | Right | 37 | | w | Word forward | 38 | | e | Word forward last char | 39 | | b | Back word | 40 | | 0 | Go to start | 41 | | $ | Go to end | 42 | | v | Highlight words | 43 | | % | Go to matching bracket/quotes etc | 44 | | Number, command | Move by certain amount | 45 | | r | Replace | 46 | | u | Undo | 47 | | . | Redo | 48 | | d (twice) | Delete the line | 49 | | d, w | Delete the word | 50 | | Number, i | Insert a number of times | 51 | | Number, r | Replace a number of chars | 52 | | Number, x | Delete certain number of keys | 53 | | y, move to new spot, p | Yank the link, then paste | 54 | | v, then y | Mark mode and yank | 55 | | >> | Indent forward | 56 | | << | Indent back | 57 | | / | Find a word | 58 | | n/N | Forward search, N upwards | 59 | | ? | Search bottom up (N/n swap) | 60 | | %s/ex/EX/g | Global ex regex | 61 | | #s/ex/EX/gc | Confirm value swapping | 62 | 63 | ## Executing external commands 64 | 65 | These are a few of the more advanced things. 66 | 67 | `: ! ls -al ~` - it will run the command, and then we get the option to run a command. 68 | 69 | `:r ! cat /root/.bash_profile` for example will read in the profile. 70 | 71 | ## Files and buffers 72 | 73 | `:saveas ` 74 | -------------------------------------------------------------------------------- /React-Redux-Middleware.md: -------------------------------------------------------------------------------- 1 | # React with Redux - Middleware 2 | 3 | 4 | 5 | * [React with Redux - Middleware](#react-with-redux---middleware) 6 | * [REDMID-1: Overview](#redmid-1-overview) - [---- REDMID-1.1: Component Set up](#-----redmid-11-component-set-up) - [---- REDMID-1.2: Controlled Components and Binding Text](#-----redmid-12-controlled-components-and-binding-text) 7 | 8 | 9 | 10 | ## REDMID-1: Overview 11 | 12 | In the last chapter, we saw some main ideas about Redux. Now, we want to create an app. We will have async (like AJAX) calls in this. 13 | 14 | We're going to create a webpage that will search for cities and give back Temp, Pressure and Humidity. 15 | 16 | We will use things like a line chart for the temp etc. 17 | 18 | In general, the components won't make AJAX calls... we want Redux to that for us. 19 | 20 | #### ---- REDMID-1.1: Component Set up 21 | 22 | 1. SearchBar 23 | 2. App 24 | 3. ForecastList 25 | 4. Chart 26 | 27 | Ensure that within source, you have the folders that you are looking for. 28 | 29 | **In containers > SearchBar.js** 30 | 31 | ```javascript 32 | import React, { Component } from 'react'; 33 | 34 | export default class SearchBar extends Component { 35 | render() { 36 | return ( 37 |
38 | 39 | 40 | 43 | 44 |
45 | ); 46 | } 47 | } 48 | ``` 49 | 50 | **In components > app.js** 51 | 52 | ```javascript 53 | import React, { Component } from 'react'; 54 | import SearchBar from '../containers/SearchBar.js'; 55 | 56 | export default class App extends Component { 57 | render() { 58 | return ( 59 |
60 | 61 |
62 | ); 63 | } 64 | } 65 | ``` 66 | 67 | #### ---- REDMID-1.2: Controlled Components and Binding Text 68 | 69 | To create the component level state. (not redux) 70 | 71 | Remember, for event handlers, we need to set the callback function where the callback reference is "this", it will have the wrong context from the render section. 72 | 73 | You can fix this in the constructor by let the instance of search bar to bind "this" and replace this.onInputChange with this result. 74 | 75 | The other option sometimes would be to instead of using the constructor, we could us onChange={ () => this.onInputChange } 76 | 77 | **In containers > SearchBar.js** 78 | 79 | ```javascript 80 | import React, { Component } from 'react' 81 | 82 | export default class SearchBar extends Component { 83 | 84 | contructor(props) { 85 | super(props); 86 | 87 | this.state = { term: '' }; 88 | 89 | this.onInputChage = this.onInputChange.bind(this); 90 | } 91 | 92 | onInputChange(event) { 93 | console.log(event.target.value); 94 | this.setState({ term: event.target.value }); 95 | } 96 | 97 | render() { 98 | return ( 99 |
100 | 106 | 107 | 108 | 109 |
110 | ) 111 | } 112 | } 113 | ``` 114 | -------------------------------------------------------------------------------- /JS-Unit-Testing-Mocha-Chai.md: -------------------------------------------------------------------------------- 1 | # Mocha and Chai 2 | 3 | ## Table of Contents 4 | 5 | title 6 | ---- title 7 | 8 |
9 | 10 | *** 11 | 12 | ## Getting Started 13 | 14 | BDD - Behaviour Driven Development 15 | 16 | We want to put the test code in a file separate from the other code. 17 | 18 | After install the dev dependency of mocha and chai, you can write a test.js file and then run `mocha test.js' and it will simply run the test! 19 | 20 | To start making these tests, we __NEED__ to make a `test` file in the same directory as `package.json` 21 | 22 |
23 | 24 | ### ---- Building a test suite 25 | 26 | Write a test that will run the test using the npm task `test` and just reply an assertion to be true. 27 | 28 | ``` 29 | const expect = require('chai').expect; 30 | 31 | // Test suite 32 | describe('Mocha', () => { 33 | 34 | // Test spec (unit test) 35 | it('should run our test using npm', () => { 36 | expect(true).to.be.ok; 37 | }); 38 | 39 | }); 40 | ``` 41 | 42 | A `spec` looks very similar to a `suite`. It takes 2 arguments. 43 | 44 | 1. A string describing the desired behaviour. 45 | 2. A function that wraps all the expectations together. 46 | 47 | It's important to start guessing what the function might expect etc. 48 | 49 | We do a lot of the guess work for setting the spec itself. It may feel awkward at the start, but it will help get some bearings. 50 | 51 | Once the spec is written, if we actually get `undefined` returned, that is likely because the function hasn't been written and/or does not return anything. 52 | 53 | ``` 54 | let expect = require('chai').expect; 55 | 56 | describe('checkForShip', () => { 57 | const checkForShip = require('../path/to/src').checkForShip; 58 | 59 | // this is the test spec 60 | it('should correctly report no ship at a given player's coordinate', () => { 61 | 62 | player = { 63 | ships: [ 64 | { 65 | locations: [[0,0]] 66 | } 67 | ] 68 | } 69 | 70 | expect(checkForShip(player, [9, 9])).to.be.false; 71 | }); 72 | 73 | it('should handle ships located at more than one coordinate', () => { 74 | 75 | player = { 76 | ships: [ 77 | { 78 | locations: [[0,0], [0,1]] 79 | } 80 | ] 81 | } 82 | 83 | expect(checkForShip(player, [0, 1])).to.be.true; 84 | expect(checkForShip(player, [9, 9])).to.be.false; 85 | }); 86 | 87 | it('should handle ships located at more than one coordinate', () => { 88 | 89 | player = { 90 | ships: [ 91 | { 92 | locations: [[0,0], [0,1]] 93 | } 94 | ] 95 | } 96 | 97 | expect(checkForShip(player, [0, 1])).to.be.true; 98 | expect(checkForShip(player, [9, 9])).to.be.false; 99 | }); 100 | }); 101 | ``` 102 | 103 | // example in the /src/js/ship_methods.js 104 | 105 | function checkForShip (player, coordinates) { 106 | 107 | var shipPresent, ship; 108 | 109 | for (var i = 0; i < player.ships.length; i++) { 110 | ship = player.ships[i]; 111 | 112 | shipPresent = ship.locations.filter( (actualCoordinate) => { 113 | return (actualCoordinate[0] === coordinates[0]) && (actualCoordinate[1] === coordinates[1]); 114 | })[0]; 115 | 116 | if (!shipPresent) { 117 | return false; 118 | } 119 | } 120 | } 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /Machine-Learning/ML-Decision-Trees.md: -------------------------------------------------------------------------------- 1 | # Decision Trees 2 | 3 | 4 | 5 | * [Decision Trees](#decision-trees) 6 | * [Intuition](#intuition) 7 | * [Decision Tree Regression in Python](#decision-tree-regression-in-python) 8 | 9 | 10 | 11 | ## Intuition 12 | 13 | **CART: Classification and Regression Trees** 14 | 15 | We speak about both types, but for now - focus on regression trees. 16 | 17 | Regression trees are a bit more complex than classification trees. 18 | 19 | Imagine a scatter plot with two IV and we are predicting an DV y (which you wouldn't be able to see on the chart). Essentially the DV would sit on the z axis. 20 | 21 | Once you run the regression decision tree algorithm, the scatter plot will be split up into segments. 22 | 23 | For example, x1 might be split at 20. Another split may happen for x2 at 170, 200 etc. 24 | 25 | The question, are the splits adding value to way we want to group our points? 26 | 27 | Each split itself is known as a leaf. 28 | 29 | The algorithm can handle mathematical issues and we can focus on the practical element of the algorithm. 30 | 31 | **Splitting** 32 | 33 | If we split `x[1] < 20`, we have two options (y/N). If we then split `x[2] < 170`, we add a child node to `x[1] < 20` that checks y/N. If we then set ``x[2] < 200`. 34 | 35 | After having a two child tree, if we set `x[1] < 40` such that `x[1] < 20` is not true and `x[2] < 170` is true, we can then set `x[1] < 40` as the child to `x[2] < 170`. 36 | 37 | Once we start this tree, what do we populate into those boxes? Well, we decide how we predict `y` with a new observation added to the plane x[1] and x[2]. 38 | 39 | Key note: `Adding splits adds information`. 40 | 41 | What we do is that for each terminal leaf, we take the average and assign the value that we give to any new element that falls into that leaf. 42 | 43 | Now, if we have a new value, we check the decision tree where it falls and then assign the new element the value of where it falls as a prediction. 44 | 45 | ## Decision Tree Regression in Python 46 | 47 | Warning for the decision tree, because we need to consider the entropy and split the result into data points. If we stick to one dimension, how do we have a line that is not horizontal? If the splits are made, they should remain a constant. 48 | 49 | Either the intervals are infinite (which they are not), or the model has an issue. 50 | 51 | The reason the issue came up, is because of what we have used to create the plot since this is no longer linear. 52 | 53 | This is now a non-linear, non-continuous regression model. 54 | 55 | What is the best way to view something non-continuous? 56 | 57 | ```python 58 | # Visualising the Decision Tree results 59 | X_grid = np.arange(min(X), max(X), 0.01) 60 | X_grid = X_grid.reshape(len(X_grid), 1) 61 | plt.scatter(X, y, color = 'red') 62 | plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') 63 | plt.title('Truth or Bluff (Decision Tree Regression)') 64 | plt.xlabel('Position level') 65 | plt.ylabel('Salary') 66 | plt.savefig('decision-tree.png') 67 | plt.show() 68 | ``` 69 | 70 | As for getting the decision tree code to run: 71 | 72 | ```python 73 | # Prediciting the Decision Tree results 74 | # Create the Regressor 75 | from sklearn.tree import DecisionTreeRegressor 76 | regressor = DecisionTreeRegressor(random_state=0) 77 | regressor.fit(X, y) 78 | 79 | y_pred = regressor.predict(6.5) 80 | ``` 81 | 82 | Ensure you have a higher resolution in order to visualize the splits. Given that the example in the tutorial has just 1 DV and 1 IV, it will come out like steps as the only splits will occur on the x axis. 83 | 84 | The model itself is not necessarily that interesting in 1D, but over many dimensions it becomes far more interesting. 85 | 86 | **What happens when you use a random forest?** 87 | 88 | A Random Forest is a team of decision trees. What happens with a team of 10 trees? 50 trees? 500 trees? 89 | -------------------------------------------------------------------------------- /Drupal/Drupal-8.md: -------------------------------------------------------------------------------- 1 | # Drupal 8 2 | 3 | 4 | 5 | * [Drupal 8](#drupal-8) 6 | * [Installation](#installation) 7 | * [Basics of Content Creation](#basics-of-content-creation) 8 | * [Publishing Options - Published, Promoted, URL](#publishing-options---published-promoted-url) 9 | * [5. Simple Site - Content](#5-simple-site---content) 10 | * [8. Extending Drupal](#8-extending-drupal) 11 | * [Core Modules](#core-modules) 12 | * [Forum module](#forum-module) 13 | * [Finding modules](#finding-modules) 14 | * [9. Creating a site - Content Types](#9-creating-a-site---content-types) 15 | * [Updating an existing content type](#updating-an-existing-content-type) 16 | * [Changing how the content type displays](#changing-how-the-content-type-displays) 17 | * [Create a new content type - Event](#create-a-new-content-type---event) 18 | 19 | 20 | 21 | ## Installation 22 | 23 | Download Drupal: https://www.drupal.org/download 24 | 25 | * Save the contents at the base of your new repo/directory i.e. so the url will be `localhost/YOUR_DIRECTORY/DRUPAL-CONTENT/` 26 | 27 | Go to `localhost/YOUR_DIRECTORY/DRUPAL-CONTENT/` and follow the prompts 28 | You also need to run `composer install` from your sites root directory. 29 | 30 | ## Basics of Content Creation 31 | 32 | What we deal with out-of-the-box. Content entry being the most important. 33 | 34 | Using `Content > Add content` to get a list of content that we can add. 35 | 36 | If we create a page `About` and change the settings on the right hand side, we can also begin to add tables for quick access. 37 | 38 | ## Publishing Options - Published, Promoted, URL 39 | 40 | If we create an article without the default settings, we can then use `saved as unpublished` from the save and publish dropdown. If content is not published, you'll be redirected to a login from a private browser and not allowed to use. 41 | 42 | On the right-hand side options, we can also edit things out of the box such as comments, the url path, author info, promotion options as well as the previously explored comment settings. Promotion options also allow you to deal with `sticky-at-top-of-list`. 43 | 44 | ## 5. Simple Site - Content 45 | 46 | ## 8. Extending Drupal 47 | 48 | ### Core Modules 49 | 50 | Two types: `core` and `contributed`. Contributed is given back from the community. It's not maintained by the community. 51 | 52 | Under the `manage > extend` tab, you can manage the modules. Selecting them on or off and seeing more information is available from here. 53 | 54 | Extra configuration may be available from the accordian dropdown. 55 | 56 | ### Forum module 57 | 58 | You can also manage permissions from the `people` section. If you have modules installed, you can see from the accordian dropdown what is required for it to work. 59 | 60 | If modules themselves are enabled, they may become directly available on the `content` menu. 61 | 62 | ### Finding modules 63 | 64 | We can search drupal.org and search for modules. 65 | 66 | ## 9. Creating a site - Content Types 67 | 68 | ### Updating an existing content type 69 | 70 | What happens if we want to add a field for articles if we want to add photo credit? If you are building a site for someone else, take them into account. 71 | 72 | From `Structure > Content Type` you can select the `Manage fields` dropdown to edit existing types and what we can easily view. To add something such as a new field, we need to `manage fields`. 73 | 74 | As we update the field names, we can see the `machine name` on the left updating - this is important for the database itself. 75 | 76 | The next step is asking for global settings themselves. 77 | 78 | Next, we can add help text, add `required` and a default value. 79 | 80 | ### Changing how the content type displays 81 | 82 | From `Structure > Content Type`, we can change the display. 83 | 84 | ### Create a new content type - Event 85 | -------------------------------------------------------------------------------- /Machine-Learning/ML-Regression-Model-Performance.md: -------------------------------------------------------------------------------- 1 | # Regression Model Performance 2 | 3 | 4 | 5 | * [Regression Model Performance](#regression-model-performance) 6 | * [R-Squared Intuition](#r-squared-intuition) 7 | * [Adjusted R-Squared Intuition](#adjusted-r-squared-intuition) 8 | * [Evaluating Regression Models Performance](#evaluating-regression-models-performance) 9 | * [Interpretting Linear Regressions Coefficients](#interpretting-linear-regressions-coefficients) 10 | 11 | 12 | 13 | ## R-Squared Intuition 14 | 15 | Interesting parameter and most people use it without understanding the underlying principles. 16 | 17 | We spoke about the `simple linear regression` model being the result of the `ordinary least squares` method. This is also known as `sum of squares residuals` and is given as `SS[res]`. 18 | 19 | If we instead took `SUM(y[i] - y[avg])^2`, we get the `total sum of squares SS[tot]`. To get our regression, we get `R^2 = 1 - (SS[res]/SS[tot])`. 20 | 21 | As you minimize the SS[res], it becomes smaller, and as we get `1 - (SS[res]/SS[tot])` we actually start to get closer to 1. The closer we get to 1, the better. Can R^2 be negative? Yes. It can if the SS[res] fits the line worse. In that case it would be better to use the average than the model - although it would be hard to do! 22 | 23 | ## Adjusted R-Squared Intuition 24 | 25 | This is the fun part! 26 | 27 | Here we have our `simple linear regression` regression from before. We, the same concepts apply for multiple linear regression. 28 | 29 | R^2 - goodness of fit. The closer the one, the better - BUT the problem is when we start adding more IVs into the model. What we can look at is whether the R^2 getting better or worse, but because of SS[res] the minimum will never decrease. **THIS IS IMPORTANT**. 30 | 31 | Once you add a new variable, it will affect what the variable looks like. Either the new variable will help minimize the SS[res]. If you cannot decress SS[res], the new variable would be zero (unlikely). 32 | 33 | Therefore, `R^2` will never decrease when you add in more variables. That being said, if the IV has zero correlation or causation with the DV, there randomly will be a slight correlation - therefore R^2 might slightly increase even though the variable is not helping the model. 34 | 35 | This is where `adjusted R^2` comes in. 36 | 37 | ``` 38 | Adj R^2 = 1 - (1-R^2)*((n - 1)/(n - p - 1)) 39 | p - number of regressors 40 | n - sample size 41 | ``` 42 | 43 | This formula will penalise you for adding in IVs that have no correlation. 44 | 45 | ## Evaluating Regression Models Performance 46 | 47 | Reflecting back on the `Backward Elimination` process that we used, we actually came to a feeling that we shouldn't have excluded the last value of `Marketing Spend`. 48 | 49 | The problem with the algorithms that we chose and the p value threshhold we chose is that the threshhold is arbitrary. 50 | 51 | What we can actually find at the bottom of those same reports that we used is that it also gives us the values of `R-squared` and `Adjusted R-squared`. 52 | 53 | If we observe this as we build our model in code, then we can use the report to help check the goodness of fit. 54 | 55 | ## Interpretting Linear Regressions Coefficients 56 | 57 | If we look at the third model and look at the IVs. If we change the IV value, we should be able to tell that DV should correlate in a certain direction. 58 | 59 | The coefficients come under their own heading. 60 | 61 | We should be able to ue logistics just for this. Magnitude can also trip you up. The `Estimate` value doesn't really give you more indication. We could alter the value of input and it would change values for `Estimate` etc. Think of magnitude in term of units of the IV. 62 | 63 | What the estimate shows that for every unit you increase, the IV would increase by a certain amount. 64 | 65 | **THE IMPORTANT PART: THING IN TERMS OF PER UNIT** 66 | 67 | You'll also know that as you take out certain IVs, the actual effect that it brings into the model will also change. 68 | -------------------------------------------------------------------------------- /Laravel-Artisan.md: -------------------------------------------------------------------------------- 1 | # Laravel and Artisan 2 | 3 | Artisan is the command-line interface included with Laravel. It provides a number of helpful commands that can assist you while you build your application. 4 | 5 | ## Basics 6 | 7 | | Commands | Description | 8 | | ---------------- | ---------------- | 9 | | `php artisan list` | List commands | 10 | | `php aristan help migrate` | Example that every command has it's own help command | 11 | | `php artisan tinker` | All Laravel applications include Tinker, a REPL powered by the PsySH package. | 12 | | `php artisan make:command SendEmails` | Create custom command SendEmails | 13 | | `email:send {user}` | Adding custom args | 14 | | `email:send {user?}` | Optional custom args | 15 | | `email:send {user=foo}` | Default custom args | 16 | | `email:send {user} {--queue=}` | Adding custom options | 17 | | `email:send {user} {--Q|queue}` | option shortcuts | 18 | | `email:send {user*}` | Input arrays | 19 | | `email:send {user : The ID of the user}` | Input descriptions | 20 | 21 | 22 | **Laravel REPL** 23 | 24 | All Laravel applications include Tinker, a REPL powered by the PsySH package. Tinker allows you to interact with your entire Laravel application on the command line, including the Eloquent ORM, jobs, events, and more. To enter the Tinker environment, run the tinker Artisan command `php artisan tinker`. 25 | 26 | ## Custom Commands 27 | 28 | You can build your own custom commands which are typically stored in the `app/Console/Commands` directory. 29 | 30 | Feel free to change storage as long as it can be accessed by `Composer`. 31 | 32 | Once you have created a command for the CLI, you will need to register it before you can use it on the CLI. 33 | 34 | **Command Structure** 35 | 36 | Example commands `SendEmails`. Note that we are able to inject any dependencies we need into the command's constructor. The Laravel service container will automatically inject all dependencies type-hinted in the constructor. 37 | 38 | ```php 39 | drip = $drip; 81 | } 82 | 83 | /** 84 | * Execute the console command. 85 | * 86 | * @return mixed 87 | */ 88 | public function handle() 89 | { 90 | $this->drip->send(User::find($this->argument('user'))); 91 | } 92 | } 93 | ``` 94 | 95 | **Closure Commands** 96 | 97 | This is an alternative to declaring a class for a console command. This is similar to the same way that route Closures are an alternative to controllers. 98 | 99 | Within the commands method of your app/Console/Kernel.php file, Laravel loads the routes/console.php file. 100 | 101 | ```php 102 | /** 103 | * Register the Closure based commands for the application. 104 | * 105 | * @return void 106 | */ 107 | protected function commands() 108 | { 109 | require base_path('routes/console.php'); 110 | } 111 | ``` 112 | 113 | Even though this file does not define HTTP routes, it defines console based entry points (routes) into your application. Within this file, you may define all of your Closure based routes using the Artisan::command method. The command method accepts two arguments: the command signature and a Closure which receives the commands arguments and options. 114 | 115 | ```php 116 | Artisan::command('build {project}', function ($project) { 117 | $this->info("Building {$project}!"); 118 | }); 119 | ``` 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /css-cheat-sheet.md: -------------------------------------------------------------------------------- 1 | # CSS Syntax 2 | 3 | ```css 4 | selector {property: value;} 5 | 6 | External Style Sheet 7 | 8 | Internal Style 9 | 12 | Inline Style 13 | 14 | ``` 15 | 16 | ### Antialiasing 17 | 18 | ```css 19 | -webkit-font-smoothing: antialiased; 20 | ``` 21 | 22 | ### CSS Ordering 23 | 24 | ```css 25 | .selector { 26 | /* Positioning */ 27 |  position: absolute; 28 |  z-index: 10; 29 |  top: 0; 30 |  right: 0; 31 | 32 |  /* Display & Box Model */ 33 |  display: inline-block; 34 |  overflow: hidden; 35 |  box-sizing: border-box; 36 |  width: 100px; 37 |  height: 100px; 38 |  padding: 10px; 39 |  border: 10px solid #333; 40 |  margin: 10px; 41 | 42 |  /* Color */ 43 |  background: #000; 44 |  color: #fff 45 |   46 |  /* Text */ 47 |  font-family: sans-serif; 48 |  font-size: 16px; 49 |  line-height: 1.4; 50 |  text-align: right; 51 | 52 |  /* Other */ 53 |  cursor: pointer; 54 | } 55 | ``` 56 | 57 | ### CSS Outline 58 | 59 | ```css 60 | outline: outline-color outline-style outline-width|initial|inherit; 61 | ``` 62 | 63 | ### CSS find active element 64 | 65 | ```javascript 66 | document.activeElement 67 | ``` 68 | 69 | ### CSS General 70 | 71 | Class String preceded by a period 72 | ID String preceded by a hash mark 73 | div Formats structure or block of text 74 | span Inline formatting 75 | color Foreground color 76 | cursor Appearance of the cursor 77 | display block; inline; list-item; none 78 | overflow How content overflowing its box is handled 79 | visible, hidden, scroll, auto 80 | visibility visible, hidden 81 | 82 | ### CSS Position 83 | 84 | clear Any floating elements around the element? 85 | both, left, right, none 86 | float Floats to a specified side 87 | left, right, none 88 | left The left position of an element 89 | auto, length values (pt, in, cm, px) 90 | top The top position of an element 91 | auto, length values (pt, in, cm, px) 92 | position static, relative, absolute 93 | z-index Element above or below overlapping elements? 94 | auto, integer (higher numbers on top) 95 | 96 | ### CSS Font 97 | 98 | font-style Italic, normal 99 | font-variant normal, small-caps 100 | font-weight bold, normal, lighter, bolder, integer (100-900) 101 | font-size Size of the font 102 | font-family Specific font(s) to be used 103 | 104 | ### CSS Background 105 | 106 | background-color Background color 107 | background-image Background image 108 | background-repeat repeat, no-repeat, repeat-x, repeat-y 109 | background-attachment Background image scroll with the element? 110 | scroll, fixed 111 | background-position (x y), top, center, bottom, left, right 112 | 113 | ### CSS List 114 | 115 | list-style-type Type of bullet or numbering in the list 116 | disc; circle; square; decimal; lower-roman; upper-roman; lower-alpha; upper-alpha; none 117 | list-style-position Position of the bullet or number in a list 118 | inside; outside 119 | list-style-image Image to be used as the bullet in a list 120 | 121 | ### CSS Text 122 | 123 | letter-spacing Space between letters 124 | line-height Vertical distance between baselines 125 | text-align Horizontal alignment 126 | text-decoration blink, line-through, none, overline, underline 127 | text-indent First line indentation 128 | text-transform capitalize, lowercase, uppercase 129 | vertical-align Vertical alignment 130 | word-spacing Spacing between words 131 | 132 | ### Box Model 133 | 134 | height; 135 | width; 136 | margin-top; 137 | margin-right; 138 | margin-bottom; 139 | margin-left; 140 | padding-top; 141 | padding-right; 142 | padding-bottom; 143 | padding-left; 144 | 145 | ### Border 146 | 147 | border-width Width of the border 148 | border-style dashed; dotted; double; groove; inset; outset; ridge; solid; none 149 | border-color Color of the border 150 | 151 | ### Setting a default browser outline 152 | 153 | outline 154 | 155 | ### CSS Hiding an element 156 | 157 | ```css 158 | .hidden { 159 | position:absolute; 160 | left:-10000px; 161 | top:auto; 162 | width:1px; 163 | height:1px; 164 | overflow:hidden; 165 | } 166 | ``` 167 | -------------------------------------------------------------------------------- /sass-cheat-sheet.scss: -------------------------------------------------------------------------------- 1 | ### Property Ordering 2 | 3 | ```css 4 | .selector { 5 | /* Positioning */ 6 |  position: absolute; 7 |  z-index: 10; 8 |  top: 0; 9 |  right: 0; 10 | 11 |  /* Display & Box Model */ 12 |  display: inline-block; 13 |  overflow: hidden; 14 |  box-sizing: border-box; 15 |  width: 100px; 16 |  height: 100px; 17 |  padding: 10px; 18 |  border: 10px solid #333; 19 |  margin: 10px; 20 | 21 |  /* Color */ 22 |  background: #000; 23 |  color: #fff 24 |   25 |  /* Text */ 26 |  font-family: sans-serif; 27 |  font-size: 16px; 28 |  line-height: 1.4; 29 |  text-align: right; 30 | 31 |  /* Other */ 32 |  cursor: pointer; 33 | } 34 | ``` 35 | 36 | // 37 | // 38 | // SASS Variables and Interpolation 39 | // 40 | // 41 | 42 | SASS 43 | 44 | $defaultLinkColor: #46EAC2; 45 | 46 | a { 47 | color: $defaultLinkColor; 48 | } 49 | 50 | $wk: -webkit-; 51 | 52 | .rounded-box { 53 | #{$wk}border-radius: 4px; 54 | } 55 | 56 | CSS 57 | 58 | a { 59 | color: #46EAC2; 60 | } 61 | 62 | .rounded-box { 63 | -webkit-border-radius: 4px; 64 | } 65 | 66 | // 67 | // 68 | // SASS Nesting 69 | // 70 | // 71 | 72 | SASS 73 | 74 | ul { 75 | list-style-type: none; 76 | li { 77 | border: { 78 | style: solid; 79 | left: { 80 | width: 1px; 81 | color: #999999; 82 | } 83 | } 84 | display: inline-block; 85 | margin: 0; 86 | padding: 0 5px; 87 | a { 88 | text-decoration: none; 89 | &:hover { text-decoration: underline; } 90 | } 91 | } 92 | } 93 | 94 | CSS 95 | 96 | ul { 97 | list-style-type: none; 98 | } 99 | ul li { 100 | border-style: solid; 101 | border-left-width: 1px; 102 | border-left-color: #999999; 103 | display: inline-block; 104 | margin: 0; 105 | padding: 0 5px; 106 | } 107 | ul li a { 108 | text-decoration: none; 109 | } 110 | ul li a:hover { 111 | text-decoration: underline; 112 | } 113 | 114 | // 115 | // 116 | // SASS Operations and Functions 117 | // 118 | // 119 | 120 | SASS 121 | 122 | $defaultWindowSize: 960px; 123 | 124 | #nav.side { 125 | float: right; 126 | width: $defaultWindowSize / 3; 127 | a { 128 | color: lighten($defaultLinkColor, 10%); 129 | } 130 | } 131 | 132 | CSS 133 | 134 | #nav.side { 135 | float: right; 136 | width: 320px; 137 | } 138 | #nav.side a { 139 | color: #74EFD1; 140 | } 141 | 142 | // 143 | // 144 | // SASS Mixins 145 | // 146 | // 147 | 148 | 149 | SASS 150 | 151 | 152 | @mixin default-box { 153 | $borderColor: #666; 154 | border: 1px solid $borderColor; 155 | clear: both; 156 | display: block; 157 | margin: 5px 0; 158 | padding: 5px 10px; 159 | } 160 | 161 | footer, header{ @include default-box; } 162 | 163 | 164 | CSS 165 | 166 | 167 | footer, header { 168 | border: 1px solid #666; 169 | clear: both; 170 | display: block; 171 | margin: 5px 0; 172 | padding: 5px 10px; 173 | } 174 | 175 | // 176 | // 177 | // SASS Arguments 178 | // 179 | // 180 | 181 | 182 | SASS 183 | 184 | @mixin default-box($color, $boxModel, $padding) { 185 | $borderColor: $color; 186 | border: 1px solid $borderColor; 187 | clear: both; 188 | display: $boxModel; 189 | margin: 5px 0; 190 | padding: 5px $padding; 191 | } 192 | 193 | header{ @include default-box(#666, block, 10px); } 194 | footer{ @include default-box(#999, inline-block, 5px); } 195 | 196 | 197 | CSS 198 | 199 | 200 | header { 201 | border: 1px solid #666; 202 | clear: both; 203 | display: block; 204 | margin: 5px 0; 205 | padding: 5px 10px; 206 | } 207 | 208 | footer { 209 | border: 1px solid #999; 210 | clear: both; 211 | display: inline-block; 212 | margin: 5px 0; 213 | padding: 5px 5px; 214 | } 215 | 216 | // 217 | // 218 | // SASS Inheritance 219 | // 220 | // 221 | 222 | 223 | SASS 224 | 225 | 226 | .error { 227 | border: 1px #F00; 228 | background: #FDD; 229 | } 230 | 231 | .badError { 232 | @extend .error; 233 | border-width: 3px; 234 | } 235 | 236 | 237 | CSS 238 | 239 | 240 | .error, .badError { 241 | border: 1px #F00; 242 | background: #FDD; 243 | } 244 | 245 | .badError { 246 | border-width: 3px; 247 | } 248 | 249 | // 250 | // 251 | // SASS Import 252 | // 253 | // 254 | 255 | 256 | SASS 257 | 258 | 259 | @import "partials/_vars"; 260 | 261 | body { 262 | color: $color; 263 | } 264 | 265 | /* content of _vars.scss */ 266 | $color: #333; 267 | 268 | 269 | CSS 270 | 271 | 272 | body { 273 | color: #333; 274 | } 275 | -------------------------------------------------------------------------------- /Testing-Cheat-Sheet.md: -------------------------------------------------------------------------------- 1 | ## Testing 2 | 3 | The test files are stored in the test folders and require the dev dependencies `sinonjs, jsdom, mocha, chai`. 4 | 5 | Run `npm test` to view the tests files that are written in that folder. 6 | 7 | Testing is still primitive and should be BDD (behaviour driven). Tests that are too specific will cause issues. 8 | 9 | __mocha and chai__ 10 | 11 | These two are used in tandem to assert/expect values. Check out the Chai documentation for relative examples. 12 | 13 | Tests consist of test suites and test specs. In order to recreate DOM elements if you are looking to test values etc. from functionality, you can use the `jsdom` library and import `jquery`. 14 | 15 | Below is a small example of a test set up. 16 | 17 | ```javascript 18 | import jsdom from 'jsdom-global'; 19 | import jQuery from '../bower_components/jquery/dist/jquery.min.js'; 20 | 21 | import ModuleToTest from 'path/to/module'l 22 | 23 | // require sinon/chai 24 | const sinon = require('sinon'); 25 | const expect = require('chai').expect; 26 | 27 | // Test suite 28 | describe('These tests are supposed to test some functionality', () => { 29 | 30 | let $; 31 | let ageGateFilters; 32 | jsdom(); 33 | 34 | // this function will run before every Test Spec 35 | before(function () { 36 | $ = jQuery; 37 | const params = ['param1', 'param2', 'param3'] 38 | 39 | // create instance 40 | const moduleToTest = new ModuleToTest(...params); 41 | }); 42 | 43 | // Test Spec (unit test) 44 | it('This test should return ok', () => { 45 | expect(true).to.be.ok; // returns ok 46 | }); 47 | 48 | // Test Spec (unit test) 49 | it('This test should return true for the ModuleToTest function', () => { 50 | expect(moduleToTest.func()).to.equal(true); // returns ok if result is true 51 | }); 52 | 53 | }); 54 | ``` 55 | 56 | __sinon.js__ 57 | 58 | This library is used to essentially stub data for functions that require things like ajax etc. No tests currently use this effectively. Examples will be added later if used. 59 | 60 | For now, I will show an example of a `spy` and a `stub` (as this may the most relevant): 61 | 62 | _For the Spy_ 63 | 64 | ``` 65 | // in module Example 66 | 67 | export default class Example { 68 | 69 | callout() { 70 | let a = 1; 71 | let b = 2; 72 | 73 | return target(a,b); 74 | } 75 | 76 | } 77 | 78 | // in a test file 79 | 80 | import Example from 'Example'; 81 | 82 | // Test suite 83 | describe('A test suite using sinon', () => { 84 | 85 | // this function will run before every Test Spec 86 | before(function () { 87 | $ = jQuery; 88 | const params = ['param1', 'param2', 'param3'] 89 | 90 | // create instance 91 | const example = new Example(...params); 92 | }); 93 | 94 | // Test spec (unit test) 95 | it('Should return that the async func was called', () => { 96 | 97 | let targetSpy = sinon.spy(example, 'target'); 98 | 99 | // Now, any time we call the function, the spy logs information about it 100 | example.callout(); 101 | 102 | assert(targetSpy.calledOnce); // returns true 103 | }); 104 | }); 105 | ``` 106 | 107 | _For the Stub_ 108 | 109 | ``` 110 | // in module Example 111 | 112 | export default class Example { 113 | 114 | callout(param, callback) { 115 | $.ajax({ 116 | // whatever it normally is 117 | }, callback); 118 | } 119 | 120 | } 121 | 122 | // in a test file 123 | 124 | import Example from 'Example'; 125 | 126 | // Test suite 127 | describe('A test suite using sinon', () => { 128 | 129 | // this function will run before every Test Spec 130 | before(function () { 131 | $ = jQuery; 132 | const params = ['param1', 'param2', 'param3'] 133 | 134 | // create instance 135 | const example = new Example(...params); 136 | }); 137 | 138 | // Test spec (unit test) 139 | it('Should call callback after saving', () => { 140 | 141 | //We'll stub $.post so a request is not sent 142 | const post = sinon.stub($, 'ajax'); 143 | post.yields(); 144 | 145 | //We can use a spy as the callback so it's easy to verify 146 | var callback = sinon.spy(); 147 | 148 | example.callout(param, callback); 149 | 150 | post.restore(); 151 | sinon.assert.calledOnce(callback); // returns true 152 | }); 153 | }); 154 | ``` 155 | 156 | __jsdom__ 157 | 158 | jsdom is a library that allows you to write a `innerHTML` var for the test to use if you want to test out the jQuery values for a test. 159 | 160 | For an example, checkout yt `test/agegate_test.js`. -------------------------------------------------------------------------------- /Dependency-Management-With-Gradle.md: -------------------------------------------------------------------------------- 1 | # Dependency Management with Gradle 2 | 3 | 4 | 5 | * [Dependency Management with Gradle](#dependency-management-with-gradle) 6 | * [GR-1: Gradle the build tool](#gr-1-gradle-the-build-tool) 7 | * [---- GR-1.1: build.gradle](#-----gr-11-buildgradle) 8 | * [---- GR-1.2: gradlew and gradlew.bat](#-----gr-12-gradlew-and-gradlewbat) 9 | * [GR-2: Adding Dependencies](#gr-2-adding-dependencies) 10 | * [GR-3: Source Code](#gr-3-source-code) 11 | 12 | 13 | 14 | ## GR-1: Gradle the build tool 15 | 16 | There are a lot of tasks when you want to build your project. 17 | 18 | Other build tools include Maven and Ant, and Gradle works well with these two. 19 | 20 | Gradle exposes a Domain Specific Language (DSL) that is based heavily on the [Groovy Programming Language](http://groovy-lang.org/) and is very similar to Groovy. 21 | 22 | Gradle has an opinionated way on how things should be done and laid out. 23 | 24 | If you want to use an IDE for this, the example uses `IntelliJ` and the Gradle template. 25 | 26 | From the main menu, select Gradle and select Java as the main language and create. 27 | 28 | From here, you will need to fill in: 29 | 30 | `GroupId`: General com.dennis.app 31 | `ArtifactId`: JAR file name eg. app 32 | 33 | Ensure you select the Java version you want to use as well - demo was 1.8. 34 | 35 | One you are in the files have been downloaded by Gradle, open up the project structure and it'll end up creating a build script called `build.gradle`. 36 | 37 | ### ---- GR-1.1: build.gradle 38 | 39 | This is the main file that is defining things like the structure etc. 40 | 41 | For now, you may have this as an example 42 | 43 | ``` 44 | group 'com.dennisokeeffe.intro' 45 | version '1.0-SNAPSHOT' 46 | 47 | apply plugin: 'java' 48 | 49 | sourceCompatibility = 1.5 50 | 51 | repositories { 52 | mavenCentral() 53 | } 54 | 55 | dependencies { 56 | testCompile group: 'junit', name: 'junit', version: '4.11' 57 | } 58 | ``` 59 | 60 | The `apply` is for things like folder structure etc. - you may notice that this is also the `Groovy` language. 61 | 62 | ### ---- GR-1.2: gradlew and gradlew.bat 63 | 64 | These files are the Gradle wrappers that makes sure that everyone can build and test the project the same way. 65 | 66 | --- 67 | 68 | ## GR-2: Adding Dependencies 69 | 70 | Transitive depencies are all handled through Gradle. This means it won't download version of dependencies it already has. 71 | 72 | Where does it download from? This is under control that is defined in the `repositories` section and by default uses `Maven Central` - you can also change this. 73 | 74 | ``` 75 | // dependencies uses a helper function mavenCentral() 76 | // anything in dependencies will look in the repos 77 | 78 | repositories { 79 | mavenCentral() 80 | } 81 | 82 | dependencies { 83 | testCompile group: 'junit', name: 'junit', version: '4.11' 84 | } 85 | ``` 86 | 87 | As an example, we can actually find packages that can be used as Maven depencies (XML) and add it such that Gradle can handle it. Eg Apache CSV package. 88 | 89 | ``` 90 | repositories { 91 | mavenCentral() 92 | } 93 | 94 | dependencies { 95 | compile group: ''org.apache.commons', name: 'commons-csv', version: '1.2' 96 | testCompile group: 'junit', name: 'junit', version: '4.11' 97 | } 98 | ``` 99 | 100 | Now we want to refresh the project. 101 | 102 | In IntelliJ, you can find the Gradle tool bar on the lefthand edge and then click on it and select refresh to rebuild. 103 | 104 | Now, the library will show up in the External Libraries section. If you had the `Auto import` setting selected or you have right-clicked on the project name in the LH edge Gradle bar and selected `Auto-import`, it will automatically do this for you. 105 | 106 | There is also a shorter form for writing dependencies. 107 | 108 | compile 'org.apache.commons:commons-csv:1.2' 109 | 110 | Transitive dependencies will also be downloaded automatically. If we want a better idea of what is going on, we can use the terminal. 111 | 112 | To do this, we can run `./gradlew dependencies` 113 | 114 | ## GR-3: Source Code 115 | 116 | Now, anyone who has that `gradle build` file we have, we can just insert all those depencies that we need and then from any computer we can just build that! 117 | 118 | Then we can import the packages that we need to the Java files and then use them as we expect. 119 | 120 | To find more packages, we can then go to something like Maven and search for packages. 121 | -------------------------------------------------------------------------------- /AWS/SysOps-Solutions-Architect.md: -------------------------------------------------------------------------------- 1 | # SysOps 2 | 3 | 4 | 5 | - [SysOps](#sysops) 6 | - [Networking](#networking) 7 | - [Networking Bottlenecks](#networking-bottlenecks) 8 | - [DNS 101](#dns-101) 9 | - [Top Level Domains](#top-level-domains) 10 | - [Domain Registrars](#domain-registrars) 11 | - [SOA Records](#soa-records) 12 | - [NS Records](#ns-records) 13 | - [A Records](#a-records) 14 | - [TTL Record](#ttl-record) 15 | - [CNAMES](#cnames) 16 | - [Alias records](#alias-records) 17 | - [Summary](#summary) 18 | - [Registering a Domain Name](#registering-a-domain-name) 19 | - [Definitions](#definitions) 20 | 21 | 22 | 23 | ## Networking 24 | 25 | ### Networking Bottlenecks 26 | 27 | Increase network performance = increase instance size. 28 | 29 | EBS Throughput != network throughput. This is writing to disk as opposed to EC2 talking to each other within the same subnet. 30 | 31 | ### DNS 101 32 | 33 | DNS is used to convert human friendly domains to an `Internet Protocol (IP)`. 34 | 35 | IPv4 is a 32 bit field and has 42 billion addresses. 36 | 37 | IPv6 has an address space of 128 bits. 340 undecillion addresses. 38 | 39 | The big issue at the moment is that everyone is still using IPv4 - this is driven by ISPs. 40 | 41 | Amazon previously did not have IPv6 support for backend systems. This changed around 2016. 42 | 43 | #### Top Level Domains 44 | 45 | The last word in the domain name is the top level eg. `.com`, `.edu`, `.gov` etc. 46 | 47 | These are controlled by the `Internet Assigne Numbers Authority (IANA)` in a root zone database which is essentially a database of all available top level domains. 48 | 49 | #### Domain Registrars 50 | 51 | As all of these need to be unique, the domain registrar is an authority that can assign domain names directly under one or more top-level domains. These domains are registered with InterNIC, a service of ICANN, which enforces the uniqueness of domain names across the internet. 52 | 53 | Each domain becomes registered in a central database known as the `WhoIS database`. 54 | 55 | #### SOA Records 56 | 57 | * `Start of Authority` 58 | * Name of the server that suppised the data for the zone. 59 | * The administrator of the zone. (The owner) 60 | * Current version of the data file 61 | * Number of seconds a secondary name server should wait before checking for updates etc. 62 | * Default TTL file on resource records 63 | 64 | #### NS Records 65 | 66 | * `Name Server records` - used by `Top Level Domain` servers to direct traffic to the Content DNS server which contains the authoritative DNS records. 67 | 68 | #### A Records 69 | 70 | The "A" record is the fundamental type of DNS record. It stands for "Address". The A record is use by a computer to translate the name of the domain to the IP address. 71 | 72 | #### TTL Record 73 | 74 | `Time to Live` - the length of time that the DNS server is cached either on the server or you PC. 75 | 76 | DNS records take time to propagate throughout the internet. Companies before a migration, they will drop the TTL down low. You may find that even two days later, at the time of the migration the DNS resolutions can head to the old or new server. 77 | 78 | #### CNAMES 79 | 80 | A `Canonical Name (CNAME)` can be used to resolve one domain name to another. For example, you may have a mobile website with the domain name `http://m.acloud.guru` that is used for when users browse to your domain name on their mobile devices. You may also want `http://mobile.acloud.guru` to resolve to the same address. 81 | 82 | #### Alias records 83 | 84 | AWS specific. It is used to map resource record sets in your hosted zone to things like ELBs, CF distributions or S3 buckets. 85 | 86 | The difference, a CNAME can't be used for naked domain names (zone apex). 87 | 88 | #### Summary 89 | 90 | * ELBs do not have a pre-defined IPv4 address - you need to resolve it using a DNS name. 91 | * Understand the difference between an Alias Record and a CNAME. 92 | * Given the choose, always choose an Alias Record over a CNAME. (No charge with Alias Record either) 93 | 94 | ### Registering a Domain Name 95 | 96 | Head to Route 53, select `Register a Domain` and go through the process of adding the domain to the cart and continue. 97 | 98 | Follow the process to go through with details for the SOA record and confirm the purchase. 99 | 100 | ## Definitions 101 | 102 | | | | 103 | | --- | ------------------------- | 104 | | ENI | Elastic Network Interface | 105 | | EBS | Elastic Block Store | 106 | | DNS | Domain Name System | 107 | -------------------------------------------------------------------------------- /th_oath_with_passport: -------------------------------------------------------------------------------- 1 | OAUTH AND PASSPORT FOR EXPRESS 2 | 3 | ///////////////////////////////////////////////////////// 4 | 5 | /**************************** 6 | * * 7 | 1. What is OAuth? 8 | * * 9 | ****************************/ 10 | 11 | It is authorization, not authentication. 12 | 13 | Authorization is used for what you can do. 14 | 15 | You usually get tokens... 16 | - Access Token 17 | - Refresh Token 18 | 19 | /**************************** 20 | * * 21 | 2. Setting up Passport 22 | * * 23 | ****************************/ 24 | 25 | // THE SETUP STRATERGY 26 | 27 | 1. Install Strategy 28 | 2. Create 'Application' on OAuth Provider 29 | 3. Configure Strategy 30 | 4. Create routes for the provider 31 | 32 | // installing Github auth 33 | 34 | npm install passport-github --save 35 | 36 | - from here you can register the application on Github in settings 37 | - grab tokens 38 | 39 | ||||||||||||||||||||||||||||||||||||||||||||| 40 | 41 | npm install passport --save 42 | npm install express-session --save 43 | 44 | We'll use persistent session store with mongoDB to keep the login persistent 45 | 46 | // in app.js 47 | 48 | var passport = require('passport'); 49 | var GitHubStrategy = require('passport-github').Strategy; 50 | var FacebookStrategy = require('passport-facebook').Strategy; 51 | var session = require('express-session'); 52 | var MongoStore = require('connect-mongo')(session); 53 | 54 | function generateOrFindUser (accessToken, refreshToken, profile, done) { 55 | User.findOneAndUpdate({ 56 | email: profile.emails[0].value 57 | }, { 58 | name: profile.displayName || profile.username, 59 | email: profile.emails[0].value, 60 | photo: profile.photos[0].value 61 | }, { 62 | upsert: true 63 | }, 64 | done); 65 | } else { 66 | var noEmailError = new Error("Your email privacy settings prevent you from signing into bookworm!"); 67 | done(noEmailError, null); 68 | } 69 | } 70 | 71 | // config the strategy 72 | passport.use(new GitHubStrategy({ 73 | // do not enter your actual ID and Key here! 74 | clientID: process.env.GITHUB_CLIENT_ID, 75 | clientSecret: process.env.GITHUB_CLIENT_SECRET, 76 | callbackURL: "http://localhost:3000/auth/github/return" 77 | }, generateOrFindUser)); 78 | 79 | passport.use(new FacebookStrategy({ 80 | // do not enter your actual ID and Key here! 81 | clientID: process.env.FACEBOOK_APP_ID, 82 | clientSecret: process.env.FACEBOOK_APP_SECRET, 83 | callbackURL: "http://localhost:3000/auth/facebook/return", 84 | profileFields: ['id', 'displayName', 'photos', 'email'] 85 | }), generateOrFindUser); 86 | 87 | 88 | passport.serializeUser(function (user, done) { 89 | done(null, user._id); 90 | }); 91 | 92 | passport.deserializeUser(function(userId, done) { 93 | User.findById(userId, done); // done is a callback function 94 | }); 95 | 96 | ... 97 | 98 | var auth = require('./routes/auth'); 99 | 100 | ... 101 | 102 | 103 | // after db connection 104 | // Session config for Passport and MongoDB 105 | 106 | var sessionOptions = { 107 | secret: "this is a super secret dadada", 108 | resave: true, 109 | saveUninitialized: true, 110 | store: new MongoStore({ 111 | mongooseConnection: db 112 | }) 113 | } 114 | 115 | app.use(session(sessionOptions)); 116 | 117 | // Init Passport 118 | app.use(passport.initialize()); 119 | 120 | // Restore Session 121 | app.use(passport.session()); 122 | 123 | app.use('/auth', auth); 124 | 125 | // in routes > auth.js 126 | 127 | var express = require('express'); 128 | var router = express.Router(); 129 | var passport = require('passport'); 130 | 131 | // Get /auth/login/github 132 | 133 | router.get('/login/github', 134 | passport.authenticate('github')); 135 | 136 | // Get /auth/github/return 137 | 138 | router.get('/github/return', 139 | passport.authenticate('github', {failedRedirect: '/'}), 140 | function(req, res) { 141 | //Succes Auth, redirect to page for now 142 | res.redirect('/profile'); 143 | }); 144 | 145 | // Get /auth/login/facebook 146 | 147 | router.get('/login/facebook', 148 | passport.authenticate('facebook', { scope: ["email"]})); 149 | 150 | // Get /auth/facebook/return 151 | 152 | router.get('/facebook/return', 153 | passport.authenticate('facebook', {failedRedirect: '/'}), 154 | function(req, res) { 155 | //Succes Auth, redirect to page for now 156 | res.redirect('/profile'); 157 | }); 158 | 159 | // GET /auth/logout 160 | 161 | router.get('/logout', function(req, res) { 162 | req.logout(); 163 | res.redirect('/'); 164 | }) 165 | 166 | module.exports = router; 167 | 168 | // to use vars in command line... 169 | 170 | > GITHUB_CLIENT_ID=123432 GITHUB_CLIENT_SECRET=892u3rw9u ./bin/www 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /Swift-3-Extensions.md: -------------------------------------------------------------------------------- 1 | # Swift 3 Extensions 2 | 3 | 4 | 5 | * [Swift 3 Extensions](#swift-3-extensions) 6 | * [Extensions](#extensions) 7 | * [---- Computed Properties](#-----computed-properties) 8 | * [---- Mutating Instance Methods](#-----mutating-instance-methods) 9 | * [---- Subscripts](#-----subscripts) 10 | * [---- Nested Types](#-----nested-types) 11 | 12 | 13 | 14 | --- 15 | 16 | ## Extensions 17 | 18 | Extensions add new functionality to an existing class, structure, enumeration, or protocol type. 19 | 20 | This includes the ability to extend types for which you do not have access to the original source code (known as retroactive modeling). Extensions are similar to categories in Objective-C. (Unlike Objective-C categories, Swift extensions do not have names.) 21 | 22 | Extensions in Swift can: 23 | 24 | * Add computed instance properties and computed type properties 25 | * Define instance methods and type methods 26 | * Provide new initializers 27 | * Define subscripts 28 | * Define and use new nested types 29 | * Make an existing type conform to a protocol 30 | 31 | ``` 32 | extension SomeType: SomeProtocol, AnotherProtocol { 33 | // implementation of protocol requirements goes here 34 | } 35 | ``` 36 | 37 |
38 | 39 | ### ---- Computed Properties 40 | 41 | ``` 42 | struct Size { 43 | var width = 0.0, height = 0.0 44 | } 45 | struct Point { 46 | var x = 0.0, y = 0.0 47 | } 48 | struct Rect { 49 | var origin = Point() 50 | var size = Size() 51 | } 52 | 53 | let defaultRect = Rect() 54 | let memberwiseRect = Rect(origin: Point(x: 2.0, y: 2.0), size: Size(width: 5.0, height: 5.0)) 55 | 56 | extension Rect { 57 | init(center: Point, size: Size) { 58 | let originX = center.x - (size.width / 2) 59 | let originY = center.y - (size.height / 2) 60 | self.init(origin: Point(x: originX, y: originY), size: size) 61 | } 62 | } 63 | 64 | let centerRect = Rect(center: Point(x: 4.0, y: 4.0), 65 | size: Size(width: 3.0, height: 3.0)) 66 | // centerRect's origin is (2.5, 2.5) and its size is (3.0, 3.0) 67 | ``` 68 | 69 | Extensions can add new instance methods and type methods to existing types. The following example adds a new instance method called repetitions to the Int type: 70 | 71 | ``` 72 | extension Int { 73 | func repetitions(task: () -> Void) { 74 | for _ in 0.. 89 | 90 | ### ---- Mutating Instance Methods 91 | 92 | ``` 93 | extension Int { 94 | mutating func square() { 95 | self = self * self 96 | } 97 | } 98 | var someInt = 3 99 | someInt.square() 100 | // someInt is now 9 101 | ``` 102 | 103 | ### ---- Subscripts 104 | 105 | Extensions can add new subscripts to an existing type. This example adds an integer subscript to Swift’s built-in Int type. This subscript [n] returns the decimal digit n places in from the right of the number: 106 | 107 | ``` 108 | 123456789[0] returns 9 109 | 123456789[1] returns 8 110 | ``` 111 | 112 | ``` 113 | extension Int { 114 | subscript(digitIndex: Int) -> Int { 115 | var decimalBase = 1 116 | for _ in 0.. 0: 150 | return .positive 151 | default: 152 | return .negative 153 | } 154 | } 155 | } 156 | 157 | // The nested enumeration can now be used with any Int value: 158 | 159 | func printIntegerKinds(_ numbers: [Int]) { 160 | for number in numbers { 161 | switch number.kind { 162 | case .negative: 163 | print("- ", terminator: "") 164 | case .zero: 165 | print("0 ", terminator: "") 166 | case .positive: 167 | print("+ ", terminator: "") 168 | } 169 | } 170 | print("") 171 | } 172 | printIntegerKinds([3, 19, -27, 0, -6, 0, 7]) 173 | // Prints "+ + - 0 - 0 + " 174 | ``` 175 | -------------------------------------------------------------------------------- /DevOps-Essentials.md: -------------------------------------------------------------------------------- 1 | # DevOps-Essentials 2 | 3 | 4 | 5 | * [DevOps-Essentials](#devops-essentials) 6 | * [1.0 Traditional Responsibility Silos](#10-traditional-responsibility-silos) 7 | * [Terminology](#terminology) 8 | * [2.0: IaaS - Infrastructure as a Service](#20-iaas---infrastructure-as-a-service) 9 | * [2.1: PaaS - Platform as a Service](#21-paas---platform-as-a-service) 10 | * [2.2: SaaS - Software as a Service](#22-saas---software-as-a-service) 11 | * [3.0: Build Automation](#30-build-automation) 12 | * [3.1: CI and CD](#31-ci-and-cd) 13 | * [4.0: Jenkins](#40-jenkins) 14 | 15 | 16 | 17 | **What is DevOps?** 18 | 19 | A software development method that stresses communication, collaboration, integration, automation and a measurement of cooperation between software devs and other IT professionals. 20 | 21 | It acknowledges the interdependence of software dev, quality assure and IT operations. 22 | 23 | You'll hear things like CI, build automation and treating the infrastructure like code. 24 | 25 | It addresses short comings and obstacles that we come across in our careers. 26 | 27 | ## 1.0 Traditional Responsibility Silos 28 | 29 | IT Operations are usually broken into the following: 30 | 31 | 1. Infrastructure and Monitoring 32 | 2. Architecture and Planning 33 | 3. Maintenence 34 | 4. Support 35 | 36 | This is the traditional operations stack. 37 | 38 | IT Dev is broken down into methodologies like the following: 39 | 40 | 1. Prototyping 41 | 2. Waterfall 42 | 3. Agile 43 | 4. Rapid 44 | 45 | Hardware and networking were not necessarily well understood by skilled software developers and vice versa. 46 | 47 | # Terminology 48 | 49 | ## 2.0: IaaS - Infrastructure as a Service 50 | 51 | * Setting up a service for using IT Infrastructure 52 | * "Stack" involved includes things from hardware to the operating system and applications that sit on top. 53 | * Virtualisation is almost indistinguishable in speed when compared to standard infrastructure is 54 | 55 | ## 2.1: PaaS - Platform as a Service 56 | 57 | Further down the rabbit hole! Next step in the redefinition of IT was looking at how the platform was provided. 58 | 59 | This delivers a "computer platform" for consumption. It generally includes all of IaaS + a few additions. 60 | 61 | In addition to before, this also addings in `runtime` and `middleware`. Services like `Azure` and `App Engine` were some of the first to offer the underlying computer and storage resources that could scale automatically to match application demand so manual allocation of resources was no longer necessary. 62 | 63 | It converged developer and operations skillsets even more. 64 | 65 | ## 2.2: SaaS - Software as a Service 66 | 67 | Skills needed in this area has completely converged. 68 | 69 | It is an important driving force behind DevOps. A ton of autoscaling code was written to deal with this. 70 | 71 | Here, we need traditional software AND hardware personnel that need the same skills to operate within this space. 72 | 73 | --- 74 | 75 | ## 3.0: Build Automation 76 | 77 | Historically, this referred to software development. The process of "building" or compiling software that can then be deployed via script or cron jobs to various environments, including production systems. 78 | 79 | It is about minimizing the deployment without manual intervention. 80 | 81 | Generally the entire stack will look like the flow from top to bottom: 82 | 83 | ``` 84 | Dev Environment 85 | | 86 | Source Repo 87 | | 88 | Build Server 89 | | 90 | Integration Server 91 | | 92 | Test Server 93 | | 94 | Production Server 95 | ``` 96 | 97 | It includes automated testing and rollback capabilities. This build is consistent and can reduce the troubleshooting when there are problems as a result. 98 | 99 | ## 3.1: CI and CD 100 | 101 | * CI means the practise of mergine dev working copies with the shared source main branch multiple times per day. 102 | * CD is an approach where valuable software is produced in small delivery cycles and ensures that those features can be reliably and consistenly released at any point in time. 103 | 104 | CI has more to do with how the software code is managed throughout the development lifecycle, whereas CD is how valuable and how quickly that software can be released when it is determined that the aggregate features are valuable enough. 105 | 106 | Although related, they are different in what they accomplish. 107 | 108 | DevOps uses each one and in term feeds the other in the chain. 109 | 110 | --- 111 | 112 | ## 4.0: Jenkins 113 | 114 | Jenkins is build automation on steroids. It can be considered a CI but often considered a CD tool as well. 115 | 116 | Used normally for build deployments, but can do anything from deploying scripts to launching virtual machines through VMWare or Vagrant to Docker. 117 | 118 | It helps create a basic build job to the custom direction of containers with unit testing etc. 119 | -------------------------------------------------------------------------------- /th_mean_stack: -------------------------------------------------------------------------------- 1 | BUILDING A MEAN APPLICATION 2 | 3 | ///////////////////////////////////////////////////////// 4 | 5 | PART 1: GETTING STARTED WITH MONGODB 6 | 7 | /**************************** 8 | * * 9 | 1. What MEAN means 10 | * * 11 | ****************************/ 12 | 13 | M - MongoDB 14 | E - Express 15 | A - Angular 16 | N - Node.js 17 | 18 | - data stored in MongoDB documents 19 | - Express.js deals with the data 20 | - Angular shows it to the user 21 | - MEAN is widely adopted 22 | - Powerful and flexible technologies 23 | - Well organised and lean 24 | 25 | THE APP 26 | 27 | 1. To do app using the MEAN stack 28 | 29 | - MEAN.js generator -> used for scaffolding. 30 | 31 | yo meanjs 32 | 33 | - yo from yeoman 34 | 35 | /**************************** 36 | * * 37 | 2. Setting up an 38 | Express Application 39 | * * 40 | ****************************/ 41 | 42 | create src 43 | npm init 44 | - set entry point: src/app.js 45 | 46 | Then add in Angular. 47 | 48 | ls .git 49 | rm .git 50 | 51 | touch src/app.js 52 | echo 'node_modules' >> .gitignore 53 | git init 54 | 55 | atom . //used for editing app.js 56 | 57 | QUESTIONS 58 | 59 | 1. Serves the public directory when the root of the site is requested? 60 | 61 | A: app.use('/', express.static('public')); 62 | OR app.use(express.static('public')); 63 | 64 | ///////////////////////////////////////////////////////// 65 | 66 | PART 2: Setting up the Express API 67 | 68 | /**************************** 69 | * * 70 | 3. Setting Up an Express 71 | API 72 | * * 73 | ****************************/ 74 | 75 | GET Routes 76 | 77 | app.get('/todos', function(req, res) { 78 | res.send('These are the todos'); 79 | }) 80 | 81 | var route = express.Router(); 82 | 83 | router.get('/todos', function(req, res) { 84 | res.json({todos:[]}); 85 | }); 86 | 87 | //these comments are examples of what was used in the Express app 88 | 89 | // TODO: Add POST route to create new entries 90 | 91 | // TODO: Add PUT route to update existing entries 92 | 93 | // TODO: Add DELETE route to drop existing entries 94 | 95 | app.use('/api', router); 96 | 97 | /**************************** 98 | * * 99 | 4. Create an API 100 | Controller 101 | * * 102 | ****************************/ 103 | 104 | // ./api/index.js 105 | 106 | 'use strict'; 107 | 108 | var express = require('express'); 109 | var Todo = require('../models/todo'); 110 | 111 | var router = express.Router(); 112 | 113 | router.get('/todos', function(req, res) { 114 | Todo.find({}, function(err, todos) { 115 | if (err) { 116 | return res.status(500).json({ message: err.message }); 117 | } 118 | res.json({ todos: todos }); 119 | }); 120 | }); 121 | 122 | router.post('/todos', function(req, res) { 123 | var todo = req.body; 124 | Todo.create(todo, function(err, todo) { 125 | if (err) { 126 | return res.status(500).json({ err: err.message }); 127 | } 128 | res.json({ 'todo': todo, message: 'Todo Created' }); 129 | }); 130 | }); 131 | 132 | router.put('/todos/:id', function(req, res) { 133 | var id = req.params.id; 134 | var todo = req.body; 135 | if (todo && todo._id !== id) { 136 | return res.status(500).json({ err: "Ids don't match!" }); 137 | } 138 | Todo.findByIdAndUpdate(id, todo, {new: true}, function(err, todo) { 139 | if (err) { 140 | return res.status(500).json({ err: err.message }); 141 | } 142 | res.json({ 'todo': todo, message: 'Todo Updated' }); 143 | }); 144 | }); 145 | 146 | router.delete('/todos/:id', function(req, res) { 147 | var id = req.params.id; 148 | Todo.findByIdAndRemove(id, function(err, result) { 149 | if (err) { 150 | return res.status(500).json({ err: err.message }); 151 | } 152 | res.json({ message: 'Todo Deleted' }); 153 | }); 154 | }); 155 | 156 | module.exports = router; 157 | 158 | /**************************** 159 | * * 160 | 4. Create mock data 161 | * * 162 | ****************************/ 163 | 164 | - Create mock data for testing. JSON. 165 | 166 | var todos = require('../../mock/todos.json'); 167 | 168 | - postman is the Chrome Extension. 169 | 170 | //IN THE GET 171 | 172 | 'use strict'; 173 | 174 | var express = require('express'); 175 | var Todo = require('../models/todo'); 176 | 177 | //dummy data 178 | var test_todos = require('../../mock/todos.json'); 179 | 180 | var router = express.Router(); 181 | 182 | router.get('/todos', function(req, res) { 183 | Todo.find({}, function(err, todos) { 184 | if (err) { 185 | return res.status(500).json({ message: err.message }); 186 | } 187 | res.json({ todos: test_todos }); //change to todos or test_todos 188 | }); 189 | }); 190 | 191 | ///////////////////////////////////////////////////////// 192 | 193 | PART 3: Angular Refresher 194 | 195 | /**************************** 196 | * * 197 | 5. Angular Refresher 198 | * * 199 | ****************************/ 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | -------------------------------------------------------------------------------- /docker-cheat-sheet.md: -------------------------------------------------------------------------------- 1 | # Docker Cheat Sheet 2 | 3 | ### 3 Parts of Docker 4 | 5 | 1. Docker Engine 6 | 2. Compose 7 | 3. Machine 8 | 9 | ``` 10 | // see versions in shell 11 | docker --version 12 | docker-compose --version 13 | docker-machine --version 14 | ``` 15 | 16 | ## Getting started 17 | 18 | Open a command-line terminal, and run some Docker commands to verify that Docker is working as expected. 19 | Some good commands to try are docker version to check that you have the latest release installed, and docker ps and docker run hello-world to verify that Docker is running. 20 | 21 | ``` 22 | docker version 23 | docker ps 24 | docker run hello-world 25 | ``` 26 | 27 | To start a Dockerized web server: 28 | 29 | ``` 30 | docker run -d -p 80:80 --name webserver nginx 31 | ``` 32 | 33 | Run `docker ps` while your web server is running to see details on the webserver container. 34 | 35 | ## Adding registries 36 | 37 | As an alternative to using Docker Hub to store your public or private images or Docker Trusted Registry, you can use Docker to set up your own insecure registry. Add URLs for insecure registries and registry mirrors on which to host your images. 38 | 39 | ## HTTP proxy settings 40 | 41 | Docker for Mac will detect HTTP/HTTPS Proxy Settings and automatically propagate these to Docker and to your containers. For example, if you set your proxy settings to http://proxy.example.com, Docker will use this proxy when pulling containers. 42 | 43 | ## File Sharing 44 | 45 | You can decide which directories on your Mac to share with containers. 46 | 47 | Add a Directory - Click + and navigate to the directory you want to add. 48 | 49 | Click Apply & Restart to make the directory available to containers using Docker’s bind mount (-v) feature. 50 | 51 | **There are some limitations on the directories that can be shared:** 52 | 53 | They cannot be a subdirectory of an already shared directory. 54 | They cannot already exist inside of Docker. 55 | 56 | ## Uninstalling 57 | 58 | Docker for Mac can also be uninstalled using a command-line terminal: 59 | 60 | ``` 61 | (mdfind Docker.app)/Contents/MacOS/Docker --uninstall 62 | ``` 63 | 64 | ## Autocompletion 65 | 66 | To activate bash completion, these files need to be copied or symlinked to your bash_completion.d directory. For example, if you use Homebrew: 67 | 68 | ``` 69 | cd /usr/local/etc/bash_completion.d 70 | ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion 71 | ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion 72 | ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion 73 | ``` 74 | 75 | # Get started with Docker tutorial 76 | 77 | ## Show all of your containers 78 | 79 | ``` 80 | docker ps -a 81 | ``` 82 | 83 | ## How to run images 84 | 85 | Breakdown of `docker run hello-world` 86 | 87 | An image is a filesystem and parameters to use at runtime. It doesn’t have state and never changes. A container is a running instance of an image. When you ran the command, Docker Engine: 88 | 89 | checked to see if you had the hello-world software image 90 | downloaded the image from the Docker Hub (more about the hub later) 91 | loaded the image into the container and “ran” it 92 | Depending on how it was built, an image might run a simple, single command and then exit. This is what Hello-World did. 93 | 94 | A Docker image, though, is capable of much more. An image can start software as complex as a database, wait for you (or someone else) to add data, store the data for later use, and then wait for the next person. 95 | 96 | Who built the hello-world software image though? In this case, Docker did but anyone can. Docker Engine lets people (or companies) create and share software through Docker images. Using Docker Engine, you don’t have to worry about whether your computer can run the software in a Docker image — a Docker container can always run it. 97 | 98 | ## Find and run the Whalesy Image 99 | 100 | ### Print random fortune cookie message 101 | $ docker run mendlik/docker-whalesay 102 | 103 | ### Print custom message 104 | $ docker run mendlik/docker-whalesay "Your message" 105 | 106 | ### Let's see what's inside the container 107 | $ docker run -it --entrypoint /bin/bash mendlik/docker-whalesay 108 | 109 | ## See all of your images 110 | 111 | ``` 112 | docker images 113 | ``` 114 | 115 | # Create your own image 116 | 117 | 1. Make directory - this serves as the `context` for the build. The context just means it contains all the things you need to build your image. 118 | 2. Change into your new directory 119 | 3. `touch Dockerfile` 120 | 121 | Open this file, and add... 122 | 123 | `FROM docker/whalesay:latest` 124 | 125 | The FROM keyword tells Docker which image your image is based on. Whalesay is cute and has the cowsay program already, so we’ll start there. 126 | 127 | Add `RUN apt-get -y update && apt-get install -y fortunes` 128 | 129 | Now, to build... 130 | 131 | `docker build -t docker-whale .` 132 | 133 | ## The build process 134 | 135 | The docker build -t docker-whale . command takes the Dockerfile in the current directory, and builds an image called docker-whale on your local machine. The command takes about a minute and its output looks really long and complex. 136 | 137 | Once it is built, you can run it using the `docker run ` command! 138 | -------------------------------------------------------------------------------- /linkedin-api-cheat-sheet.md: -------------------------------------------------------------------------------- 1 | # LinkedIn API Cheat Sheet 2 | 3 | ```php 4 | $_SESSION['expires_at'])) { 33 | // Token has expired, clear the state 34 | $_SESSION = array(); 35 | } 36 | if (empty($_SESSION['access_token'])) { 37 | // Start authorization process 38 | getAuthorizationCode(); 39 | } 40 | } 41 | 42 | // You have a valid token. Now fetch your profile. 43 | // I've just put in some dummy fields for now, but hopefully these should do it. 44 | $user = fetch('GET', '/v1/people/~:(first-name,last-name,email-address,phone-numbers,num-connections,picture-url,location,positions,summary,specialties,industry)'); 45 | 46 | // I've just shoved the responses into some variables from the $user dict response 47 | 48 | // STORE THE RESULTS IN AN ARRAY 49 | 50 | $res = array(); 51 | 52 | $res[] = $user->firstName; 53 | $res[] = $user->lastName; 54 | $res[] = $user->emailAddress; 55 | $res[] = $user->phoneNumbers; 56 | $res[] = $user->numConnections; 57 | $res[] = $user->pictureUrl; 58 | $res[] = $user->location->country->code; 59 | $res[] = $user->location->name; 60 | $res[] = $user->summary; 61 | $res[] = $user->specialties; 62 | $res[] = $user->industry; 63 | $res[] = $user->positions; 64 | 65 | echo nl2br("First name: ". $res[0] . "\n"); 66 | echo nl2br("Last name: ". $res[1] . "\n"); 67 | echo nl2br("Email Address: " . $res[2] . "\n"); 68 | echo nl2br("Phone Numbers: ". $res[3] . "\n"); 69 | echo nl2br("Num Connections: ". $res[4] . "\n"); 70 | echo nl2br("Picture Url: " . $res[5] . "\n"); 71 | echo nl2br("Location Country Code: " . $res[6]. "\n"); 72 | echo nl2br("Location Name: ". $res[7] . "\n"); 73 | echo nl2br("Summary: " . $res[8] . "\n"); 74 | echo nl2br("Specialties: ". $res[9] . "\n"); 75 | echo nl2br("Industry: ". $res[10] . "\n"); 76 | echo nl2br("Positions: " . $res[11] . "\n"); 77 | 78 | exit; 79 | 80 | function getAuthorizationCode() { 81 | $params = array('response_type' => 'code', 82 | 'client_id' => API_KEY, 83 | 'scope' => SCOPE, 84 | 'state' => uniqid('', true), // unique long string 85 | 'redirect_uri' => REDIRECT_URI, 86 | ); 87 | // Authentication request 88 | $url = 'https://www.linkedin.com/uas/oauth2/authorization?' . http_build_query($params); 89 | 90 | // Needed to identify request when it returns to us 91 | $_SESSION['state'] = $params['state']; 92 | // Redirect user to authenticate 93 | header("Location: $url"); 94 | exit; 95 | } 96 | 97 | function getAccessToken() { 98 | $params = array('grant_type' => 'authorization_code', 99 | 'client_id' => API_KEY, 100 | 'client_secret' => API_SECRET, 101 | 'code' => $_GET['code'], 102 | 'redirect_uri' => REDIRECT_URI, 103 | ); 104 | 105 | // Access Token request 106 | $url = 'https://www.linkedin.com/uas/oauth2/accessToken?' . http_build_query($params); 107 | 108 | // Tell streams to make a POST request 109 | $context = stream_context_create( 110 | array('http' => 111 | array('method' => 'POST', 112 | ) 113 | ) 114 | ); 115 | // Retrieve access token information 116 | $response = file_get_contents($url, false, $context); 117 | // Native PHP object, please 118 | $token = json_decode($response); 119 | // Store access token and expiration time 120 | $_SESSION['access_token'] = $token->access_token; // guard this! 121 | $_SESSION['expires_in'] = $token->expires_in; // relative time (in seconds) 122 | $_SESSION['expires_at'] = time() + $_SESSION['expires_in']; // absolute time 123 | 124 | return true; 125 | } 126 | 127 | // this fetch should be the main thing that you really need to add to what you already have! 128 | 129 | function fetch($method, $resource, $body = '') { 130 | $params = array('oauth2_access_token' => $_SESSION['access_token'], 131 | 'format' => 'json', 132 | ); 133 | 134 | // Need to use HTTPS 135 | $url = 'https://api.linkedin.com' . $resource . '?' . http_build_query($params); 136 | // Tell streams to make a (GET, POST, PUT, or DELETE) request 137 | $context = stream_context_create( 138 | array('http' => 139 | array('method' => $method, 140 | ) 141 | ) 142 | ); 143 | 144 | // Hocus Pocus 145 | $response = file_get_contents($url, false, $context); 146 | // Native PHP object, please 147 | return json_decode($response); 148 | } 149 | 150 | ?> 151 | ``` 152 | -------------------------------------------------------------------------------- /Enzyme-Testing.md: -------------------------------------------------------------------------------- 1 | # Testing with Enzyme 2 | 3 | React components allow unit tests in JS to be much easier. 4 | 5 | These exampes require `sinonjs`, `jsdom`, `enzyme`, `mocha`, `chai` 6 | 7 | These are examples of the three APIs that you get with Enzyme. Remember, that a majority of the test cases will need `shallow`. 8 | 9 | Testing lifecycle events, use `mount`. 10 | 11 | If you need to test a component that gets rendered or returns just HTML, you can use `render`. 12 | 13 | *File structure* 14 | 15 | - test 16 | - repository_test.spec.js 17 | - github_widget.spec.js 18 | - user_image.spec.js 19 | - scripts 20 | - mocha_runner.js 21 | - package.json 22 | - src 23 | - components 24 | - repositories.js 25 | 26 | ## ENZ-1: Testing with "Shallow" 27 | 28 | ``` 29 | // package.json 30 | ... 31 | 32 | Note: the --debug flag allows us to use the debugger statements and interact with the debugger through the command line 33 | 34 | Note: There is also a `node-intercept` that allows you to tap into Chrome Dev tools 35 | 36 | "scripts": { 37 | ... 38 | "test": "mocha --debug --require scripts/mocha_runner.js ./test/**/*.spec.js", 39 | ... 40 | } 41 | ... 42 | 43 | ``` 44 | 45 | ``` 46 | // reposity_test.js 47 | import React from 'react-native'; 48 | import { shallow } from 'enzyme'; 49 | import { expect } from 'chai'; 50 | 51 | // import a component 52 | import Repositories from '../src/components/repositories'; 53 | 54 | describe('', () => { 55 | it('should render one number of repos specified by top prop', () => { 56 | const wrapper = shallow(); 57 | expect(wrapper.find(Repository)).to.have.length(2); 58 | }); 59 | 60 | it('should display repos ordered by stargazers' () => { 61 | const sortedTestData = repos.sort((a, b) => b.stargazers_count - a.stargazers_count); 62 | const wrapper = shallow(); 63 | 64 | // find each child with 65 | const topRepos = wrapper.find(Repository); 66 | 67 | // for each found, test out correct values 68 | topRepos.forEach((repo, index) => { 69 | expect(repo.prop('url')).to.equal(sortedTestData[index.url]); 70 | expect(repo.prop('name')).to.equal(sortedTestData[index].name); 71 | expect(repo.prop('language')).to.equal(sortedTestData[index].language); 72 | expect(repo.prop('stars')).to.equal(sortedTestData[index].stars); 73 | }); 74 | }); 75 | }); 76 | ``` 77 | 78 | ## ENZ-2: Testing with "Mount" 79 | 80 | This requires use of `js-dom` 81 | 82 | ``` 83 | // mocha_runner.js 84 | 85 | var jsdom = require('jsdom').jsdom; 86 | 87 | var exposedProperties = ['window', 'navigator', 'document']; 88 | 89 | global.document = jsdom(''); 90 | global.window = document.defaultView; 91 | Object.keys(document.defaultView).forEach((property) => { 92 | if (typeof global[property] === 'undefined') { 93 | exposedProperties.push(property); 94 | global[property] = document.defaultView[property]; 95 | } 96 | }); 97 | 98 | global.navigator = { 99 | userAgent: 'node.js' 100 | }; 101 | 102 | documentRef = document; 103 | 104 | require('babel-core/register'); 105 | ``` 106 | 107 | ``` 108 | // github_widget.spec.js 109 | import React from 'react-native'; 110 | import { mount } from 'enzyme'; 111 | import { expect } from 'chai'; 112 | import sinon from 'sinon'; 113 | 114 | // js dom has also been used as an example for these headless browser testing 115 | 116 | // import a component 117 | import GithubWidget from '../src/components/GithubWidget'; 118 | import UserDetails from ... 119 | // import all the other components 120 | // found in the expect below 121 | ... 122 | 123 | describe('', () => { 124 | it('should render all sub-components', () => { 125 | const wrapper = mount(); 126 | 127 | expect(wrapper.containsAllMatchingElements([ 128 | , 129 | , 130 |
, 131 | , 132 |