Skip to content

Instantly share code, notes, and snippets.

View SamuelDavis's full-sized avatar

Samuel Davis SamuelDavis

  • Stallings, NC, USA
View GitHub Profile
@SamuelDavis
SamuelDavis / RogueApplet.java
Last active September 27, 2017 01:29
Will Thimbleby's tiny roguelike (normal version): http://will.thimbleby.net/roguelike/
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D;
@SamuelDavis
SamuelDavis / StealthyRogueApplet.java
Last active September 27, 2017 01:29
Will Thimbleby's tiny roguelike (stealthy version): http://will.thimbleby.net/roguelike/
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D;
@SamuelDavis
SamuelDavis / square-screen.html
Created September 24, 2017 09:08
Perfect Square game canvas renderer
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
@SamuelDavis
SamuelDavis / autofill.js
Last active October 8, 2017 07:38
Super simple autofiller, run through http://bookmarklets.org/maker/
(function ($) {
function randInt(max, min) {
max = max || 1;
min = min || 0;
return parseInt(Math.random() * (max - min)) + min;
}
var letters = [
"a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p",
@SamuelDavis
SamuelDavis / bing-disavow.js
Last active February 16, 2018 23:45
Bing Quick Disavow Importer
var textArea = document.createElement('textarea');
textArea.setAttribute('id', 'disavow-quicklist');
document.body.appendChild(textArea);
var $textArea = $('#disavow-quicklist');
$textArea.css({
top: 100,
left: 0,
position: 'fixed',
@SamuelDavis
SamuelDavis / format.php
Created August 5, 2018 01:59
Pretty-print an array of objects
<?php
function format(array $data, string $type): string
{
$data = array_map(function ($obj) {
return array_map(function ($value) {
if ($value === null) {
return 'null';
}
if ($value === true) {
@SamuelDavis
SamuelDavis / lara_multi_url_to_html.php
Last active June 21, 2019 01:18
Implementation of async url fetching using curl (with laravel Cache-facade caching)
<?php
function urlToHtml(string ...$urls)
{
$cache = array_map('sha1', $urls);
$ttl = array_fill(0, count($urls), null);
$res = [];
$ch = [];
$mh = curl_multi_init();
$options = [
@SamuelDavis
SamuelDavis / spritesheet.js
Created August 15, 2019 03:34
roguelike dev spritesheet management
const spriteStyleSheet = buildSpriteStyleSheet('http://rogueliketutorials.com/images/arial10x10.png', 10, 10, [
[' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?'],
['@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'],
[],
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
])
function buildSpriteStyleSheet (url, width, height, charMap) {
return charMap
@SamuelDavis
SamuelDavis / NDimensionalArray.js
Last active August 28, 2019 11:23
automatically create arbitrarily nested arrays
class NDimensionalArray extends Array {
constructor (size, ...sizes) {
super(size)
super.fill(undefined)
if (sizes.length) {
size = sizes.shift()
this.forEach((_, i) => this[i] = new NDimensionalArray(size, ...sizes))
}
}
@SamuelDavis
SamuelDavis / nested_array.php
Created October 31, 2019 04:01
Extract a nested array structure from formatted text.
<?php
$list = <<<LIST
1 Introduction
1.1 Purpose
<Identify the product whose software requirements are specified in this document, including the revision or release number Describe the scope of the product that is covered by this SRS, particularly if this SRS describes only part of the system or a single subsystem.>
1.2 Document Conventions
<Describe any standards or typographical conventions that were followed when writing this SRS, such as fonts or highlighting that have special significance For example, state whether priorities for higher-level requirements are assumed to be inherited by detailed requirements, or whether every requirement statement is to have its own priority.>
1.3 Intended Audience and Reading Suggestions
<Describe the different types of reader that the document is intended for, such as developers, project managers, marketing staff, users, testers, and documentation writers Describe what the rest of this SRS contains and how it is organized Suggest a sequence for reading the document, b