Skip to content

Instantly share code, notes, and snippets.

View Announcement's full-sized avatar
💭
Looking for work!

Jacob Francis Powers Announcement

💭
Looking for work!
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Announcement
Announcement / get-substrings.js
Last active May 10, 2018 00:13
optimizations needed
function getSubstrings (string) {
var map = new Map
for (let n = 1; n < string.length; n++) {
for (let i = 0; i < string.length - n; i++) {
const item = string.substring(i, i + n)
if (!map.has(item))
map.set(item, new Set)
function InsertionSort (array, swap, compare) {
if (compare === null || compare === undefined)
compare = (a, b) => {
return a < b }
if (swap === null || swap === undefined)
swap = (a, b, c) => {
const [ x, y ] = [ a[b], a[c] ]
a[b] = y
a[c] = x; return a }
@Announcement
Announcement / sed.js
Created April 15, 2018 08:26
echo "foo bar" | node sed 's/foo/[$0]/g'
const replacementExpression = /^s\/((?:\\.|[^\/\\])+)\/((?:\\.|[^\/\\])*)\/([gimuy]{0,5})$/
const replacementExpressionCompiled = replacementExpression.exec(process.argv[2])
function getReplacement (input, source, flags, replacement) {
const expression = new RegExp(source, flags)
return input.replace(expression, function (matched/*, ...captures, index, fulltext, groups? */) {
const parameters = Array.from(arguments)
const [index, fulltext, groups] =
@Announcement
Announcement / bot.js
Last active April 5, 2018 23:13
The Official regular expression IRC bot.
const env = this
module.exports = function* addMessage ({ who, what, when, where }) {
const command = (/^(?:official|\:)\:\s*(\S+)\s*(.*)/i).exec(what)
if (command === null) return
if (command[1].toLowerCase() === 'run') {
const expression = command[2].match(/\/((?:\\.|[^\/])+)\/([a-z]*)\s*(.+)/)
const compiled = new RegExp(expression[1], expression[2])
const string = expression[3]
function * getProperties (object) {
for (const [key, value] of Object.entries(object)) {
yield [key]
if (typeof value === 'object')
for (const each of getProperties(value))
yield [key, ...each]
}
}
@Announcement
Announcement / yaclient-generated.html
Created April 2, 2018 23:38
heres a little sample of the currently generated html
<form name="message">
<input autofocus="" placeholder="type a message..." name="what" maxlength="510" minlength="1">
<input type="submit" name="why" value="Send">
</form>
<nav>
<a href="#localhost">localhost</a>
<section id="localhost">
<a href="#localhost-#chat">#chat</a>
<a href="#localhost-yaclient">yaclient</a>
</section>
@Announcement
Announcement / a_stickfigure.js
Last active April 1, 2018 04:10
what percent math is this
let canvas;
let context;
let styles = [];
canvas = document.createElement('canvas');
context = canvas.getContext('2d');
function getDistance(point1, point2) {
return Math.sqrt(Math.pow(point2.y - point1.y, 2) + Math.pow(point2.x - point1.x, 2));
}
@Announcement
Announcement / example.js
Last active March 28, 2018 03:49
parse FormData
const expression = {}
expression.header_content_type = header_content_type: /(?<mimetype>(?<mimetype_type>[a-z]+|\*)\/(?<mimetype_subtype>[a-z][a-z0-9]*(?:\-[a-z0-9]+)*|\*))(?:\s*;\s*charset=(?<charset>\S+))?(?:\s*;\s*boundary=(?<boundary>\S+))?/
expression.header_content_type.exec(request.headers['content-type'])
if (method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE') {
let data
if ((/(?:text|application)\/json/).test(request_contentType.groups.mimetype)) {
data = JSON.parse(packet.toString('utf8'))
const { performance } = require('perf_hooks')
const cluster = require('cluster')
const os = require('os')
const MAXIMUM_N_VALUE = 1000000000
process.nextTick(main)
function main () {