Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / index.php
Created March 8, 2012 17:31
Tiny, SMTP client in PHP
<?php
/*
This is a very tiny proof-of-concept SMTP client. Currently it's over 320 characters (if the var names are compressed). Think you can build one smaller?
*/
ini_set('default_socket_timeout', 3);
$user = 'you@gmail.com';
$pass = '';
$host = 'ssl://smtp.gmail.com';
@xeoncross
xeoncross / http_accept_language.php
Last active October 19, 2023 12:46
Parse the HTTP except language header
<?php
function prefered_language($available_languages, $http_accept_language) {
$available_languages = array_flip($available_languages);
$langs = array();
preg_match_all('~([\w-]+)(?:[^,\d]+([\d.]+))?~', strtolower($http_accept_language), $matches, PREG_SET_ORDER);
foreach($matches as $match) {
@xeoncross
xeoncross / templates.go
Created October 24, 2018 22:49
Creative use of yeld and custom filepath walking to load templates with inheritance. https://www.kylehq.com/2017/05/golang-templates---what-i-missed/
// Note that the templateFuncs refer to my apps helper package, left here
// in this example to help.
// Heavily inspired by the book https://www.sitepoint.com/premium/books/level-up-your-web-apps-with-go
// https://gitlab.com/snippets/1662623
// https://www.kylehq.com/2017/05/golang-templates---what-i-missed/
package templates
import (
"bytes"
@xeoncross
xeoncross / kindle.md
Created July 8, 2023 19:24
Moving books and PDF's onto your Amazon Kindle

I'm not sure if who might need this information, but man it's hard to find. Kindles aren't as user-friendly as one would expect.

If you need to move books and documents onto the kindle using your computer or mac (via USB) you need to put the .epub .mobi or .pdf files into the "documents" folder.

The kindle will create a ton of "[book name]_[hash].sdr" folders to match and store metadata like your place in the book.

@xeoncross
xeoncross / ajax.js
Last active August 3, 2023 06:06
Simple, cross-browser Javascript POST/GET xhr request object. Supports request data and proper AJAX headers.
/**
* IE 5.5+, Firefox, Opera, Chrome, Safari XHR object
*
* @param string url
* @param object callback
* @param mixed data
* @param null x
*/
function ajax(url, callback, data, x) {
try {
@xeoncross
xeoncross / the_future_of_go.md
Last active August 2, 2023 16:47
The future of fast MVP's using Go and Typescript using code generation

The future of fast MVP's using Go and React

As Go matures, no-code (if you squint) solutions are making their way into the ecosystem. This means faster MVP's and less errors writing out the same CRUD project-after-project.

  1. Starting with just your sql statements, you use sqlc to generate the models and entities
  2. Write your actual service/business logic using the entities and interfaces sqlc generated (wish list: skip this step)
  3. Use goa to generate your OpenAPI HTTP or gRPC webserver
  4. Have openapi-generator produce the Typescript SDK you're UI will use to call it
  5. Build out your interface
  6. Publish (web, app store, etc..)
@xeoncross
xeoncross / domdocument_encoding.php
Last active July 8, 2023 14:46
Fix HTML encoding errors with PHP DOMDocument
<?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 / net_ws_client.go
Last active June 29, 2023 06:49
A simple benchmark client for a websocket server written in go. It can hammer the server.
package main
import (
//"code.google.com/p/go.net/websocket"
"fmt"
"github.com/gorilla/websocket"
"io"
"math/rand"
"net/http"
"os"
@xeoncross
xeoncross / wordlist.py
Created February 6, 2016 23:06 — forked from samuraisam/wordlist.py
A wordlist for python. 67k words, with "bad words" filtered out. Use responsibly :)
This file has been truncated, but you can view the full file.
import random
def random_words(num, separator='-'):
"""
Return `num`-random concatinated to each other.
They will be joined by `separator`
"""
words = []
@xeoncross
xeoncross / top-cms-projects
Created November 5, 2012 03:04 — forked from abpin/top-cms-projects
List of top 1200 CMS systems
1. Joomla!
2. Drupal
3. Mambo
4. TYPO3 Enterprise CMS
5. WebGUI
6. WordPress
7. Plone
8. Xoops
9. PHP Nuke
10. eZ Publish