Skip to content

Instantly share code, notes, and snippets.

View MidnightLightning's full-sized avatar

Brooks Boyd MidnightLightning

View GitHub Profile
@MidnightLightning
MidnightLightning / index.html
Created August 13, 2010 17:39
A local file to generate complex passwords based on a more user-friendly seed
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Password-generating sidebar</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="content-style-type" content="text/css" />
<style type="text/css">
body { font-size:10pt; }
@MidnightLightning
MidnightLightning / nest.php
Last active September 26, 2015 00:37
Nested Substrings
<?php
/**
* Return a substring, honoring nested strings
*
* Find from "start" to "end" in a given "haystack" string,
* but if a second "start" is encountered before the first "end",
* skip over the nested repetition and return all the way up to the proper "end" for the outer "start"
*
* @author Brooks Boyd <[email protected]>
@MidnightLightning
MidnightLightning / README.md
Last active September 26, 2015 00:38
Javascript popups

The "target" attribute in links is now only used for pages using framesets (reference), so how do you pop up a new browser window for links you want to have people navigate to without leaving your page?

Using the current W3 standard for anchor tags anchor tags can be given a rel attribute that describes what relation the linked-to page has to this current page. It also provides a standard list of available relationships. Many other groups added to this list and there are many widely-used values for the rel tag, including "external".

With this method, give links to be made popups a rel attribute of "external", and include the following file in the head of the document.

@MidnightLightning
MidnightLightning / growler.php
Created June 8, 2011 16:55
PHP Growl notifier interface
<?php
/**
* Interface with the growlnotify notification client
*
* The Growl notification system for Mac includes a command-line utility for scripts to send notifications through.
* 'growlnotify' needs to be explicitly installed from the "Extras" folder of the Growl installation disk before it can be used
*
* @author Brooks Boyd <[email protected]>
* @link http://growl.info/documentation/developer/growlnotifier.php Growlnotifier documentation
*/
@MidnightLightning
MidnightLightning / linesofcode.sh
Created August 22, 2011 14:15
Count lines of text
#!/bin/bash
# Count lines of text files of specified file types:
# Base command from http://www.commandlinefu.com/commands/view/5518/count-lines-of-code-across-multiple-file-types-sorted-by-least-amount-of-code-to-greatest
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` match1 [match2, ...]"
echo "Search the current directory for files matching any of the 'match1', 'match2', etc. parameters, and count number of lines"
echo "Eg: `basename $0` '*.php' '*.html' '*.js' '*.css' # <-- Lines of code in a website"
exit
@MidnightLightning
MidnightLightning / sitecheck.py
Created December 7, 2011 20:53
Website monitoring script
import httplib, smtplib, sys
from email.mime.text import MIMEText
# Determine if we're online
sites = ['www.google.com', 'www.amazon.com', 'www.ebay.com']
online = False
for s in sites:
conn = httplib.HTTPConnection(s)
conn.request("GET", "/")
<!DOCTYPE html>
<html>
<head>
<title>HTML5 with Twitter Bootstrap</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="content-style-type" content="text/css" />
<link rel="shortcut icon" href="img/favicon.png" />
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
</head>
@MidnightLightning
MidnightLightning / lib_raw.php
Created December 21, 2011 15:40
Phar as an Include
<?php
function foobar($msg) {
echo "Hello $msg!\n";
return true;
}
@MidnightLightning
MidnightLightning / README.md
Last active October 7, 2015 10:48
ASCII encoding container

Representing binary data as Hex numbers has been a standard for a while, but using only sixteen printable characters when there's many more "safe" ASCII characters possible has lead to other sorts of numbering systems. This class allows you to define your own "number" progression and encode/decode integers through it. The Radix of the conversion used is the length of the string passed to the class, making it very customizable. Several standard character sets (many from RFC 4648) are included, or pass your own custom character string.

This implementation uses the BC Math PHP extension if it's installed to convert very large integers successfully.

<?php
// Hex to Base64
echo radix_convert(Radix::HEX_UPPER, Radix::DECIMAL, 'FF')."\n";

// Hex test