Skip to content

Commit

Permalink
🐛 add sub modules
Browse files Browse the repository at this point in the history
  • Loading branch information
w3cj committed Aug 12, 2020
1 parent d2b9198 commit 13921ff
Show file tree
Hide file tree
Showing 60 changed files with 24,974 additions and 4 deletions.
1 change: 0 additions & 1 deletion intro-to-serverless-with-vercel
Submodule intro-to-serverless-with-vercel deleted from 1e3c17
116 changes: 116 additions & 0 deletions intro-to-serverless-with-vercel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
21 changes: 21 additions & 0 deletions intro-to-serverless-with-vercel/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Coding Garden with CJ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions intro-to-serverless-with-vercel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TMI API Proxy

A simple serverless proxy to demonstrate Vercel. Also demonstrates CORS.
1 change: 1 addition & 0 deletions intro-to-serverless-with-vercel/client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
33 changes: 33 additions & 0 deletions intro-to-serverless-with-vercel/client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1 id="viewCount"></h1>
<div id="chatters"></div>
<script>
// THE RIGHT WAY (actual select the elements):
// const viewCount = document.querySelector('#viewCount');
// const chatters = document.querySelector('#chatters');
async function getChattersOnTheFrontendCauseThatsWhereWeAre() {
// CORS ERROR!
// const response = await fetch('https://tmi.twitch.tv/group/user/codinggarden/chatters');

// Call our proxy instead!
const response = await fetch('https://tmi-proxy.vercel.app/api/chatters');
const json = await response.json();
viewCount.textContent = json.chatter_count;
chatters.textContent = json.chatters.viewers.join(', ');
}
getChattersOnTheFrontendCauseThatsWhereWeAre();
</script>
</body>
</html>
1 change: 1 addition & 0 deletions intro-to-serverless-with-vercel/server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
27 changes: 27 additions & 0 deletions intro-to-serverless-with-vercel/server/api/chatters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const axios = require('axios');

const API_URL = (channelName) => `https://tmi.twitch.tv/group/user/${channelName}/chatters`;

async function getChatters(req, res) {
// https://vercel.com/knowledge/how-to-enable-cors
res.setHeader('access-control-allow-origin', '*');
res.setHeader('access-control-allow-methods', 'GET,OPTIONS');
if (req.method === 'OPTIONS') {
res.status(200).end();
return;
}
try {
const { channelName = 'codinggarden' } = req.query;
const { data } = await axios.get(API_URL(channelName));
res.send(data);
} catch (error) {
res.status(500);
const response = error.response || {};
res.send({
message: error.message,
response,
});
}
}

module.exports = getChatters;
12 changes: 12 additions & 0 deletions intro-to-serverless-with-vercel/server/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://ez-css.now.sh">
</head>
<body>
<p>TMI Chatters Proxy make a request to /api/chatters?channelName=codinggarden</p>
</body>
</html>
37 changes: 37 additions & 0 deletions intro-to-serverless-with-vercel/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions intro-to-serverless-with-vercel/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "CJ R. <[email protected]> (https://w3cj.sh)",
"license": "MIT",
"dependencies": {
"axios": "^0.19.2"
}
}
1 change: 0 additions & 1 deletion jquery-from-scratch
Submodule jquery-from-scratch deleted from f8fdb6
21 changes: 21 additions & 0 deletions jquery-from-scratch/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Coding Garden with CJ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions jquery-from-scratch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Build a Simple jQuery from scratch

* Alca - Build jQuery from scratch - https://twitch.tv/alca

* [x] What is $
* [x] How can a function do different things with different params
* [ ] ~~Use a proxy to implement .css on an NodeList~~
* [x] http://youmightnotneedjquery.com/
21 changes: 21 additions & 0 deletions jquery-from-scratch/custom-jquery/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable */

$(() => {
console.log('DOCUMENT IS READY!');
$('h1').css('color', 'red');
$('h1').css({
fontFamily: 'sans-serif',
cursor: 'pointer',
});
$('h1').on('click', () => {
alert('WOUW');
});
$('li').css('font-family', 'sans-serif');
$('li').each(function(i) {
if (i % 2 === 0) {
$(this).css('color', 'green');
} else {
$(this).css('color', 'orange');
}
});
});
49 changes: 49 additions & 0 deletions jquery-from-scratch/custom-jquery/gardenQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable */

const makeNiceCollection = collection => {
collection.each = (callback) => {
collection.forEach((element, i) => {
const boundFn = callback.bind(element);
boundFn(i, element);
});
};
collection.on = (eventName, handler) => {
collection.forEach((element) => {
element.addEventListener(eventName, handler);
});
};
collection.css = (...cssArgs) => {
if (typeof cssArgs[0] === 'string') {
const [property, value] = cssArgs;
collection.forEach((element) => {
element.style[property] = value;
});
} else if (typeof cssArgs[0] === 'object') {
const cssProps = Object.entries(cssArgs[0]);
collection.forEach((element) => {
cssProps.forEach(([property, value]) => {
element.style[property] = value;
});
});
}
};
};

const $ = (...args) => {
if (typeof args[0] === 'function') {
// document ready listener
const readyFn = args[0];
document.addEventListener('DOMContentLoaded', readyFn);
} else if (typeof args[0] === 'string') {
// select an element!
const selector = args[0];
const collection = document.querySelectorAll(selector);
makeNiceCollection(collection);
return collection;
} else if (args[0] instanceof HTMLElement) {
// we have an element!
const collection = [args[0]];
makeNiceCollection(collection);
return collection;
}
};
Loading

0 comments on commit 13921ff

Please sign in to comment.