Skip to content

Instantly share code, notes, and snippets.

David Pennington Xeoncross

Block or report user

Report or block Xeoncross

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
Xeoncross / zaplog.go
Created Jan 22, 2020
Example helper for creating a new zap.Logger instance that logs to stderr without the caller/stacktrace.
View zaplog.go
package zaplog
import (
// For testing use
Xeoncross / logger.js
Last active Jan 21, 2020
Expressjs Server Monitoring with Winston + Morgan
View logger.js
const { createLogger, format, transports } = require("winston");
// { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }
const level = process.env.LOG_LEVEL || "debug";
function formatParams(info) {
const { timestamp, level, message, ...args } = info;
const ts = timestamp.slice(0, 19).replace("T", " ");
Xeoncross / domdocument_encoding.php
Last active Jan 20, 2020
Fix HTML encoding errors with PHP DOMDocument
View domdocument_encoding.php
// Ignore errors
libxml_use_internal_errors(true) AND libxml_clear_errors();
// original input (unknown encoding)
Xeoncross / fingerprint.php
Last active Jan 17, 2020
Generate a fingerprint from and RSA SSH public key
View fingerprint.php
print "\n";
$rsa = file_get_contents('');
$ssh = file_get_contents('');
// For reference
print $rsa . "\n\n";
print $ssh . "\n\n";
Xeoncross / clean_html.php
Created Mar 8, 2013
Sanitize HTML using PHP and the DOMDocument
View clean_html.php
* Clean HTML string removing all element attributes and elements which are
* not in the provided whitelist (but keeping their allowed children).
* @see
* @param string $html to clean
* @param array $whitelist
function clean_html($html, array $whitelist)
Xeoncross / timezone.php
Created Sep 8, 2011
The perfect TimeZone selectbox list for PHP 5.3+
View timezone.php
$regions = array(
'Africa' => DateTimeZone::AFRICA,
'America' => DateTimeZone::AMERICA,
'Antarctica' => DateTimeZone::ANTARCTICA,
'Aisa' => DateTimeZone::ASIA,
'Atlantic' => DateTimeZone::ATLANTIC,
'Europe' => DateTimeZone::EUROPE,
'Indian' => DateTimeZone::INDIAN,
'Pacific' => DateTimeZone::PACIFIC
View Every possible TypeScript

Hasse diagram of every possible TypeScript type

  • any: magic, ill-behaved type that acts like a combination of never (the proper [bottom type]) and unknown (the proper [top type])
    • Anything at all is assignable to any, and any is assignable to anything at all.
    • Identities: any & AnyTypeExpression = any, any | AnyTypeExpression = any
    • Key TypeScript feature that allows for [gradual typing].
  • unknown: proper, well-behaved [top type]
    • Anything at all is assignable to unknown. unknown is only assignable to itself (unknown) and any.
    • Identities: unknown & AnyTypeExpression = AnyTypeExpression, unknown | AnyTypeExpression = unknown
    • Prefer over any whenever possible. Anywhere in well-typed code you're tempted to use any, you probably want unknown.
Xeoncross / traverse_node.go
Created Jan 5, 2017
Simple DOM node traversal in golang using a very useful collector/matcher function
View traverse_node.go
package main
import (
Xeoncross /
Created Nov 5, 2012
Git - calculate how many lines of code were added/changed by someone
# Run this in the project repo from the command-line
git log --shortstat --author "Xeoncross" --since "2 weeks ago" --until "1 week ago" | grep "files changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'
Xeoncross /
Last active Jan 7, 2020
Ideas for an authentication library in Go to handle login, sessions, and request protection for HTML forms as well as single-page apps (or other clients)

Login / Auth System

Protect against:

  • DoS
  • Lock accounts after failed attempts
  • forgotten password tokens (or remeber me, CSRF, etc..) being used as logins (hash them all)
  • someone faking a login attempt and that action loging out valid user sessions
You can’t perform that action at this time.