Skip to content

Instantly share code, notes, and snippets.

View brettvaida's full-sized avatar

Brett Vaida brettvaida

View GitHub Profile
@brettvaida
brettvaida / server
Created July 20, 2020 21:00
The most basic Node server
let http = require("http")
let app = http.createServer((req, res) => {
if (req.url == "/") {
res.end("Hello World")
} else {
res.end("Page Not Found")
}
})
app.listen(3000)
@brettvaida
brettvaida / todo.html
Last active June 2, 2020 19:43
Basic to-do app
<h1>To-Do App</h1>
<form id="form">
<input id="input" type="text" autocomplete="off">
<button>Create Item</button>
</form>
<h3>Things To Do</h3>
<ul id="list"></ul>
@brettvaida
brettvaida / copyright.js
Created February 7, 2019 19:49
Display a copyright symbol and the current year
@brettvaida
brettvaida / ajax-fetch-post.js
Created November 26, 2017 00:10
AJAX POST request boilerplate using fetch(). May require polyfill from https://github.com/github/fetch
fetch('https://api-to-call.com/endpoint', {
method: 'POST',
body: JSON.stringify({id: '200'})
}).then(response => {
if (response.ok) {
return response.json();
} throw new Error('Request failed!');
}, networkError => console.log(networkError.message)
).then(jsonResponse => jsonResponse)
@brettvaida
brettvaida / ajax-fetch-get.js
Last active November 26, 2017 00:09
AJAX GET request boilerplate using fetch(). May require polyfill from https://github.com/github/fetch
fetch('https://api-to-call.com/endpoint').then(response => {
if (response.ok) {
return response.json();
} throw new Error('Request failed!');
}, networkError => console.log(networkError.message)
).then(jsonResponse => jsonResponse);
@brettvaida
brettvaida / ajax-post-jquery.js
Created November 25, 2017 20:43
AJAX POST request boilerplate with jQuery
$.ajax({
url: 'https://api-to-call.com/endpoint',
type: 'POST',
data: JSON.stringify({id: 200}),
dataType: 'json',
success(response) {
console.log(response);
},
error(jqXHR, status, errorThrown) {
console.log(jqXHR);
@brettvaida
brettvaida / ajax-get-jquery.js
Created November 25, 2017 20:30
AJAX GET request boilerplate using jQuery
$.ajax({
url: 'https://api-to-call.com/endpoint',
type: 'GET',
dataType: 'json',
success(response) {
console.log(response);
},
error(jqXHR, status, errorThrown) {
console.log(jqXHR);
}
@brettvaida
brettvaida / ajax-post.js
Created November 25, 2017 20:00
AJAX POST request boilderplate
const xhr = new XMLHttpRequest;
const url = 'https://api-to-call.com/endpoint';
const data = JSON.stringify({id: '200'});
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
console.log(xhr.response);
}
};
@brettvaida
brettvaida / ajax-get.js
Created November 25, 2017 17:51
AJAX GET request boilerplate
const xhr = new XMLHttpRequest();
const url = 'https://api-to-call.com/endpoint';
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
console.log(xhr.response);
}
};
@brettvaida
brettvaida / scrollNav.js
Created October 26, 2017 21:38
Smooth scroll to anchor links
function scrollNav() {
$('.nav a').click(function(){
//Toggle active class
$(".active").removeClass("active");
$(this).closest('li').addClass("active");
var theClass = $(this).attr("class");
$('.' + theClass).parent('li').addClass('active');
//Animate scroll
$('html, body').stop().animate({
scrollTop: $( $(this).attr('href') ).offset().top - 70 //Offset top