Skip to content

Instantly share code, notes, and snippets.

View aerrity's full-sized avatar

Andrew Errity aerrity

View GitHub Profile
@aerrity
aerrity / client.js
Last active April 9, 2024 21:33
Node, Express & MongoDB: Button click example
console.log('Client-side code running');
const button = document.getElementById('myButton');
button.addEventListener('click', function(e) {
console.log('button was clicked');
fetch('/clicked', {method: 'POST'})
.then(function(response) {
if(response.ok) {
console.log('click was recorded');
@aerrity
aerrity / bouncing-circles.js
Last active December 24, 2022 00:26
P5.js example using constructor functions and classical inheritance
// ----------------------------
// Parent class (or superclass)
// ----------------------------
function Circle(x = 50, y = 50, r = 100, col = '#f00') {
this.x = x;
this.y = y;
this.r = r;
this.col = col;
this.vx = random(-5,5);
this.vy = random(-5,5);
@aerrity
aerrity / app.js
Created February 1, 2019 16:47
React - Searching & sorting a list of random users
import React, { Component } from "react";
import axios from "axios";
class App extends Component {
constructor(props) {
super(props);
this.state = { users: [], searchTerm: '', alphabetical: 'az' };
this.handleChange = this.handleChange.bind(this);
@aerrity
aerrity / react-UserProfiles.js
Last active October 7, 2022 00:33
React example - fetch data from web API
import React from 'react';
class UserProfiles extends React.Component {
constructor(){
super();
this.state = {
name: {title: '', first: '', last: ''},
image: ''
};
// fix the this value
@aerrity
aerrity / client.js
Last active August 23, 2022 20:37
P5.js, Node, Express & MongoDB: Circle update demo
let myCircle;
function setup() {
createCanvas(400, 400);
background(0);
// retrieve the x, y coords from the DB
fetch('/circle', {method: 'GET'})
.then(function(response) {
if(response.ok) return response.json();
throw new Error('Request failed.');
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const server = express();
const port = 3000;
server.get('/', (req, res) => res.send('Hello World!'));
server.get('/api/users', (req, res) => {
MongoClient.connect('mongodb://localhost:27017/REACTCA2', function (err, client) {
if (err) throw err
@aerrity
aerrity / README.md
Last active January 28, 2021 10:08
Republic of Ireland Choropleth
@aerrity
aerrity / bouncing-circles-es6-classes.js
Last active January 20, 2021 07:18
P5.js example demonstrating ES6 classes, inheritance and method chaining
// ----------------------------
// Parent class (or superclass)
// ----------------------------
class Circle {
constructor(x = 50, y = 50, r = 100, col = '#f00') {
this.x = x;
this.y = y;
this.r = r;
this.col = col;
this.vx = random(-5,5);
import React from 'react';
import ReactDOM from 'react-dom';
class UserProfiles extends React.Component {
constructor(){
super();
this.state = {
users: []
};
}
@aerrity
aerrity / react-form-multiple.js
Last active November 20, 2020 10:39
React controlled component (form) with multiple inputs example
import React from 'react';
import ReactDOM from 'react-dom';
class SignUp extends React.Component {
constructor(props) {
super(props);
this.state = {
newsLetter: true,
email: ''
};