Skip to content

Instantly share code, notes, and snippets.

View jaywon's full-sized avatar

Jason Sewell jaywon

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function List(){
(function() {
var STAGE_HEIGHT = 480;
var STAGE_WIDTH = 800;
// var GROUND_Y = 450;
var GAME_ASSET = {
IMAGES: {
blah: '/assets/images/mario.png',
// bg: '/assets/images/bg32_32.png',
//get a reference to the main element in your HTML document(DOM)
var mainElement = document.getElementById('main');
for (var i = 0; i < window.geemails.length; i++) {
var x = document.createElement("P");
var t = document.createTextNode(window.geemails[i].sender + " " + window.geemails[i].subject + " " + window.geemails[i].date);
x.appendChild(t);
//append to the main element to attach new element as a child of main instead of document.body
mainElement.appendChild(x);
}
//generate new messages - need to append
//just pass the name of a function you created and an interval, this is just a reference to what function you want to execute
//at the specified interval
var newMessage = setInterval(getNewMessage, 5000);
//this is the actual function that will get called and execute at the configued interval in setInterval above.
function getNewMessage() {
console.log('get new message');
}
@jaywon
jaywon / gist:c76abc57dc33e1679c02
Last active March 8, 2024 06:00
Circular String Brain Bender

###Good Morning Agents

Your challenge this morning is to create a function that implements an algorithm using the concepts we've covered this week.

###Challenge

  1. Write an algorithm that takes in 2 strings as parameters (source, find).
  2. Your function should return true if the string passed in as the find parameter is found in the source parameter if source were circular in nature. Meaning there is no end to the source string.
  3. Important: A match would be true if the word to find is partially at the end of the word and at the beginning in sequence.

Ex.

@jaywon
jaywon / stack-challenge.md
Last active March 26, 2021 19:57
Use a Linked List to simulate a stack trace

###Console History Sim Stack Trace Challenge

Using a linked list, we are going to demonstrate a use case for a linked list and simulate a stack like you see in a stack trace (similar to what you see in your console when an error occurs), that replays the history of what we typed.

  1. Add a text box to an HTML page and add 2 buttons, save and dump.
  2. Every time the user clicks the first button to save, we are going to save the text input to our linked list as the most recent node or head.
  3. Whenever someone clicks the dump button we are going to dump out all of the input they've typed in to that point from most recent to oldest. This should be written as HTML to the page.
@jaywon
jaywon / Ruh-Roh.md
Last active March 8, 2024 06:00
Email Hell

###Email Hell

We just found out that there is a bug in production that our e-mail function was iterating errantly and sending duplicate e-mails to many users. We need to fix this quickly but we don't want to send out a mass apology letter to all of our users.

Our sysadmin gave us the SMTP logs and we need to process the logs and identify which users received multiple e-mails so that we can directly send them a follow up e-mail explaining the situation and offer super cool swag to keep them on as customers.

Also, the boss wants this done ASAP, we don't have time to do this manually...HAAALLLLPPP!

###The Fix

@jaywon
jaywon / README.md
Last active May 16, 2019 02:01
JavaScript OOP Reflector

Your Challenge

Reflection is a common utility in Object Oriented languages for inspecting classes and deriving information about what properties/methods they expose and other classes they inherit from. We will be writing our own JavaScript reflector today!

We are going to write a simple utility that will inspect a given object, and tell us about the object and it's inheritance chain.

Your Tasks

  1. Create 3 classes:
  • User
  • GroupUser
  • SuperUser
@jaywon
jaywon / README.md
Last active February 11, 2019 19:05
Memoize Me

Memoize Me

We are going to be building an in-memory cache to improve performance and extend the getElementById() and querySelector() functions of the DOM. Querying the DOM for elements can be an inefficient operation and if we are finding elements in the DOM repeatedly we would like to improve performance but we also don't want to clutter our codebase with many variables to hold references to the various elements we will use and to keep things a bit more dynamic.

Your Challenge

Write a module that anyone can add to their project and call your module's functions instead of the native DOM functions.

  1. Use good naming conventions for the module as well as the methods you're exposing. This is subjective to you but put yourself in someone elses shoes of what would make sense to them.
  2. Use memoization to cache elements if they have not been retrieved before from the DOM and return the element just as the above functions would do normally by calling them directly.
  3. If the element has bee