Skip to content

Instantly share code, notes, and snippets.

View raduGaspar's full-sized avatar

Radu B. Gaspar raduGaspar

View GitHub Profile
/* ... */
class Vector2D { /* ... */ }
let showTracer = true
let vectorCount = 4
let initState = []
let vectors = []
const handleInit = (arr) => { /* ... */ }
@raduGaspar
raduGaspar / epicycle-initialization.js
Created May 8, 2019 11:52
Main logic for initializing the epicycle mechanism
const background = document.querySelector('#background')
const canv = document.querySelector('#canvas')
const bgCtx = background.getContext('2d')
const canvMidX = canv.width * 0.5
const canvMidY = canv.height * 0.5
class Vector2D { /* ... */ }
const randomInRange = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)
@raduGaspar
raduGaspar / epicycle-vector.js
Last active May 8, 2019 11:20
The Vector2D definition for an epicycle
class Vector2D {
constructor(sx=10, sy=10, size=50, angle=0) {
this.sx = sx
this.sy = sy
this.size = size
this.angle = angle
this.rotation = angle
this.rotationStep = 0
this.color = '#000'
this.isPencil = false
class Person {
constructor (firstName, lastName, birthday) {
this.firstName = firstName
this.lastName = lastName
this.birthday = birthday
}
sayHello () {
return `My name is ${this.firstName}`
}
}
class Person {
constructor (firstName, lastName, birthday) {
this.firstName = firstName
this.lastName = lastName
this.birthday = birthday
}
sayHello () {
return `My name is ${this.firstName}`
}
}
class API {
#url
#handleError (res) {
return res.ok ? res : Promise.reject(res.statusText)
}
constructor () {
this.#url = 'https://purelyawespme.com/api'
}
get (endpoint) {
return window.fetch(this.#url + endpoint, {
const API = (function () {
const url = 'https://purelyawespme.com/api'
const handleError = (res) => res.ok ? res : Promise.reject(res.statusText)
const doGet = (endpoint) => window.fetch(url + endpoint, {
method: 'GET',
headers: new Headers({
'Accept': 'application/json'
})
})
.then(handleError)
const firstName = 'John'
const lastName = 'Doe'
let sleepCounter = 0
function sleep (firstName) {
return `${firstName} is asleep for the ${++sleepCounter} time`
}
@raduGaspar
raduGaspar / encapsulation.js
Last active April 1, 2019 16:55
A grouping of related properties and methods
const user = {
firstName: "John",
lastName: "Doe",
sleepCounter: 0,
eat: function() {},
sleep: function() {
return `${this.firstName} is asleep for the ${++this.sleepCounter} time`;
},
code: function() {},
repeat: function() {},
@raduGaspar
raduGaspar / httpsRedirect.js
Created March 18, 2018 13:42
HTTPS Redirect Express Middleware
const server = express()
server.use(function (req, res, next) {
if (req.host !== 'localhost' && req.get('X-Forwarded-Proto') === 'http') {
res.redirect(`https://${req.hostname}${req.url}`)
return
}
next()
})