Skip to content

Instantly share code, notes, and snippets.

View Nicknyr's full-sized avatar

Nick Kinlen Nicknyr

  • South Florida
View GitHub Profile
@Nicknyr
Nicknyr / Javascript Sounds
Last active November 1, 2017 01:22
Javascript: Function that uses Audio() to play a sound
// Uses Audio() to play an mp3
function sound() {
var audio = new Audio();
audio.src = "url to mp3";
audio.play();
}
@Nicknyr
Nicknyr / gist:1b90c37679b627d312a30b6a3e37973e
Last active December 6, 2017 21:27
Using Axios to make an AJAX request in React (uses Reddit API as an example)
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import axios from "axios";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
posts: []
@Nicknyr
Nicknyr / Compare arrays
Last active December 9, 2017 23:36
Javascript: Use .every() function to compare two arrays and determine if they have the same elements in the same order
// Compare two arrays and determine if they have the same values in the same order
var compare = arr1.length == arr2.length &&
arr1.every(function(element, index){
return element == arr2[index];
});
if(compare) {
// Arrays match, do this
}
@Nicknyr
Nicknyr / Generate Random Number
Last active December 9, 2017 23:41
Javascript: Generate random number and push it to an array
// Generates and logs a random number between 1 and 4, pushes it to an array, and logs it
var arr = [];
function randomNumber() {
var num = Math.floor((Math.random() * 4) + 1);
arr.push(num);
console.log(arr);
}
@Nicknyr
Nicknyr / Call function synchronously while iterating through array elements
Last active December 9, 2017 23:41
Javascript: Looping over an array and calling a function in a sychronous manner using setInterval
// loop over the array using the iteratee function at the specified interval
function intervalForEach(array, iteratee, delay) {
let current = 0
let interval = setInterval(() => {
if (current === array.length) {
clearInterval(interval)
} else {
@Nicknyr
Nicknyr / gist:f644e25dd5f84aaa3d6a2bfe1bf01d1e
Created December 17, 2017 04:00
Updating state in React with a form input box example
import React, { Component } from 'react';
import './App.css';
export default class ToDoList extends Component {
constructor(props) {
super(props);
this.state = {
userInput: '',
list: []
@Nicknyr
Nicknyr / gist:689a8923e2637865486cfc6775b53d53
Created December 17, 2017 04:25
Simple React To-Do list
import React, { Component } from 'react';
import './App.css';
export default class ToDoList extends Component {
constructor(props) {
super(props);
this.state = {
userInput: '',
list: []
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="spaceship_launch_illustration"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1400px" height="980px"
viewBox="0 0 1400 980" enable-background="new 0 0 1400 980" xml:space="preserve">
<g id="background">
<rect fill="#4A626E" width="1400" height="980"/>
<g>
<path fill="#405059" d="M1196.4,552.4C1196.4,278.2,974.1,56,700,56S203.6,278.2,203.6,552.4c0,182.1,98.1,341.3,244.3,427.6
h504.2C1098.3,893.6,1196.4,734.5,1196.4,552.4z"/>
@Nicknyr
Nicknyr / gist:3154be7f02e388653063aeb644431819
Created August 11, 2018 02:42
React pass state to child component as a prop - FreeCodeCamp example
class MyApp extends React.Component {
constructor(props) {
super(props);
this.state = {
name: 'CamperBot'
}
}
render() {
return (
<div>
@Nicknyr
Nicknyr / gist:9c8fc56a41ea6b5bcb623530b3e8aa27
Created September 30, 2018 20:55
Iterate through 2D array in React
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
constructor(props) {
super(props);
this.state = {
data: [[1,1,0,1,1,1],[1,1,1]]