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
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 (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// https://github.com/uber-go/zap/blob/master/config.go#L40-L127
// For testing use https://godoc.org/go.uber.org/zap#NewNop
@Xeoncross
Xeoncross / logger.js
Last active Jan 21, 2020
Expressjs Server Monitoring with Winston + Morgan
View logger.js
const { createLogger, format, transports } = require("winston");
// https://github.com/winstonjs/winston#logging
// { 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
Xeoncross / domdocument_encoding.php
Last active Jan 20, 2020
Fix HTML encoding errors with PHP DOMDocument
View domdocument_encoding.php
<?php
// Ignore errors
libxml_use_internal_errors(true) AND libxml_clear_errors();
// http://stackoverflow.com/q/10237238/99923
// http://stackoverflow.com/q/12034235/99923
// http://stackoverflow.com/q/8218230/99923
// original input (unknown encoding)
@Xeoncross
Xeoncross / fingerprint.php
Last active Jan 17, 2020
Generate a fingerprint from and RSA SSH public key
View fingerprint.php
<?php
print "\n";
$rsa = file_get_contents('rsa.pub');
$ssh = file_get_contents('ssh.pub');
// For reference
print $rsa . "\n\n";
print $ssh . "\n\n";
@Xeoncross
Xeoncross / clean_html.php
Created Mar 8, 2013
Sanitize HTML using PHP and the DOMDocument
View clean_html.php
<?php
/**
* Clean HTML string removing all element attributes and elements which are
* not in the provided whitelist (but keeping their allowed children).
*
* @see https://github.com/alixaxel/phunction/blob/master/phunction/HTML.php
* @param string $html to clean
* @param array $whitelist
*/
function clean_html($html, array $whitelist)
@Xeoncross
Xeoncross / timezone.php
Created Sep 8, 2011
The perfect TimeZone selectbox list for PHP 5.3+
View timezone.php
<?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 type.md

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
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 (
"bytes"
"fmt"
"io"
"strings"
"unicode"
"golang.org/x/net/html"
@Xeoncross
Xeoncross / gitstats.sh
Created Nov 5, 2012
Git - calculate how many lines of code were added/changed by someone
View gitstats.sh
# Run this in the project repo from the command-line
# http://stackoverflow.com/a/4593065/99923
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
Xeoncross / go_auth_library.md
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)
View go_auth_library.md

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.