Skip to content

Instantly share code, notes, and snippets.

@ianhoffman
ianhoffman / api_example.js
Last active February 16, 2021 22:34
Example of a frontend API client
// var songInfo = {
// songName: ''
// lyric: '',
// }
//
// A pseudo-genre is the artist and their related artists.
//
function getArtist(searchString) {
// Make API call to get the artist from the search string
@ianhoffman
ianhoffman / js_template_example.html
Created May 25, 2020 22:22
JS Template Example
<!DOCTYPE html>
<html>
<body>
<div><h1>Testing...</h1></div>
<div class="card-list" id="card-list"></div>
</body>
<script type="text/template" id="card-list-item">
<div class="card-list-item">
<h2 class="card-title"></h2>
@ianhoffman
ianhoffman / gist:2b19dc7596b6e981add8f8acf5ba634d
Created April 25, 2020 00:38
Maybe inserting into an array
userGuess = 'a' // Whatever
userGuesses = [] // Assume this is populated
shouldInsertGuess = true;
for (var i = 0; i < userGuesses.length; i++) {
if (userGuesseses[i] === userGuess) {
shouldInsertGuess = false;
break;
}
}
@ianhoffman
ianhoffman / singledispatchmethod.py
Last active December 27, 2017 04:49
The generic function pattern implemented for methods
from functools import singledispatch
class singledispatchmethod(object):
def __init__(self, method):
self.method = singledispatch(method)
def register(self, klass, method=None):
return self.method.register(klass, func=method)