Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / Positive-Adjective-List.txt
Created February 23, 2016 19:19
Positive Adjective List
Positive Adjective List
abundant
accessible
accommodative
accomplished
accurate
achievable
adaptable
adaptive
@xeoncross
xeoncross / logger.js
Last active April 21, 2024 00:26
Expressjs Server Monitoring with Winston + Morgan
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 / Dockerfile1
Last active April 9, 2024 05:20
Examples of using multi-stage builds with docker and Go to reduce the final image size / attack surface.
# Sample from @citizen428 https://dev.to/citizen428/comment/6cmh
FROM golang:alpine as build
RUN apk add --no-cache ca-certificates
WORKDIR /build
ADD . .
RUN CGO_ENABLED=0 GOOS=linux \
go build -ldflags '-extldflags "-static"' -o app
FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt \
@xeoncross
xeoncross / Requests.php
Created April 11, 2012 21:44
cURL asynchronous requests using curl_multi and callbacks
<?php
/**
* Make asynchronous requests to different resources as fast as possible and process the results as they are ready.
*/
class Requests
{
public $handle;
public function __construct()
{
@xeoncross
xeoncross / pop.php
Created September 28, 2012 19:47
POP email server in PHP
<?php
/*
http://stackoverflow.com/a/11973533/99923
Well, just to show that it is in fact possible to write a POP3 server in PHP, here it is. The server does no authentication--or pretty much anything else. It just keep sending the same message over and over. But it works. Thunderbird was able to retrieve messages from it. Totally useless, but sort of cool.
My setup is Apache 2 on Windows with PHP 5.2.
*/
// echo something so fopen() would return
@xeoncross
xeoncross / composer.md
Last active March 26, 2024 02:59
How composer actually works

Composer

the missing quick-start guide

We will assume we have a package/project called https://github.com/foo/bar

Most redistributable packages are hosted on a version control website such as Github or Bitbucket. Version control repositories often have a tagging system where we can define stable versions of our application. For example with git we can use the command:

git tag -a 1.0.0 -m 'First version.'

With this we have created version 1.0.0 of our application. This is a stable release which people can depend on. If we wanted to include "foo/bar" then we could create a composer.json and specify the tagged release we wanted:

@xeoncross
xeoncross / splitByStrings.go
Created March 20, 2024 20:08
Split code into chunks (processing args, coloring syntax, etc..) based on if strings exist while taking escape characters into account. Golang rune parsing supports UTF8.
// Run at: https://go.dev/play/p/oFUYPNRZiBp
package main
import "fmt"
// Suppose you have a piece of code you want to split into chunks based on if you're in a string or not.
// You also want to respect escape characters.
var input = `fmt.Println("Hello, \"世界\"")`
@xeoncross
xeoncross / bookmarked.php
Created February 23, 2016 19:26
Simple, PHP-based bookmark system so you can save internet pages. Uses HTTP Digest for Auth and PDO-SQLite extension (built-in).
<?php
// Place the DB files outside of the public web directory so people don't download it!
define('DB', 'links.sq3');
// Number of seconds a user must wait to post another link (false to disable)
define('WAIT', false);
// Should we enforce IP checking? (false to disable)
define('IP_CHECK', false);
@xeoncross
xeoncross / timezone.php
Created September 8, 2011 18:43
The perfect TimeZone selectbox list for PHP 5.3+
<?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
@xeoncross
xeoncross / compress.js
Created March 25, 2015 19:35
Simple functions to compress/uncompress javascript unicode strings using repeating patterns
// Compress/Uncompress javascript unicode strings using repeating patterns
// Copyright 2015 davidpennington.me
function compress(str) {
var original = str;
// We don't allow newlines
str = str.replace(/(\r\n|\n|\r)/gm,"");