Skip to content

Instantly share code, notes, and snippets.

View kitsune7's full-sized avatar
🦊
Having fun programming ^_^

Christopher Bradshaw kitsune7

🦊
Having fun programming ^_^
View GitHub Profile
const http = require('http')
const port = process.env.PORT || 8080
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'})
response.end('Hello World\n')
}).listen(port)
console.log(`Server running at http://localhost:/${port}`)
@kitsune7
kitsune7 / siblings.js
Last active July 29, 2018 06:42
Functions for getting siblings of a target node
function getSiblings (target) {
return [
...getUntilNull(target, 'previousElementSibling'),
...getUntilNull(target, 'nextElementSibling')
]
}
/**
* Collects HtmlElements until null is return from the provided property on target
*
@kitsune7
kitsune7 / HelloWorld.js
Last active August 15, 2018 06:19
Web component using html imports
class HelloWorld extends HTMLElement {
createdCallback () {
console.log('RUNNING -- createdCallback')
const templates = document.getElementById('templates').import
const template = templates.getElementById('hello-world-template')
this.attachShadow({ mode: 'open' })
.appendChild(template.content.cloneNode(true))
}
@kitsune7
kitsune7 / jsonHasProperties.js
Created September 26, 2018 05:08
A function that checks whether or not a JSON object has all the properties that were passed to it.
/**
* @param object json
* @param string[] properties
* @returns boolean
*/
function jsonHasProperties (json, properties) {
return properties.every(prop => json.hasOwnProperty(prop))
}
@kitsune7
kitsune7 / type.js
Last active December 12, 2018 23:00
/*
* @param variable The variable you want to get the type of
* @returns 'string', 'number', 'array', 'function', or 'object'
*/
function type (variable) {
return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase()
}
@kitsune7
kitsune7 / arraysEqual.js
Created December 12, 2018 22:30
Checks if two arrays are equal
/**
* @param a First array
* @param b Second array
* @returns boolean; true if a and b are equal, false otherwise
*/
function arraysEqual (a, b) {
if (a.length !== b.length) {
return false
}
@kitsune7
kitsune7 / get-post.js
Created December 13, 2018 22:32
Functions for making a GET or POST request on the client.
async function post (url, data) {
let request = {
body: JSON.stringify(data),
method: 'post',
headers: { 'Content-Type': 'application/json' }
}
return fetch(url, request)
.then(async (response) => {
return response.json()
@kitsune7
kitsune7 / errorHandling.js
Created December 14, 2018 07:59
Utility functions for displaying errors in vanilla.js (Relies on having a hidden attribute set on element at start state)
/*
* Displays in error in the first matched CSS selector given.
* This relies on having a hidden attribute set on element at start state.
* @param error: string The error message
* @param selector: string A CSS selector that matches the element displaying the error
*/
function displayError (error, selector) {
const errorElement = document.querySelector(selector)
errorElement.innerHTML = error
errorElement.removeAttribute('hidden')
/**
* Returns a number that will have up to `max` decimal places.
*/
function maxToFixed (num, max) {
return parseFloat(num.toFixed(max))
}
; My first linux assembly program (runs on 64 bit linux)
; Compile with `nasm -felf64 hello.asm && ld hello.o -o hello`
global _start
section .text
_start:
; Call 'write' system call
mov rax, 1