Skip to content

Instantly share code, notes, and snippets.

View MidnightLightning's full-sized avatar

Brooks Boyd MidnightLightning

View GitHub Profile
@MidnightLightning
MidnightLightning / README.md
Last active December 30, 2015 23:28
Experimenting with Typed Arrays in Node.js

Node Buffer objects say:

A Buffer object can also be used with typed arrays. The buffer object is cloned to an ArrayBuffer that is used as the backing store for the typed array. The memory of the buffer and the ArrayBuffer is not shared.

NOTE: Node.js v0.8 simply retained a reference to the buffer in array.buffer instead of cloning it.

While more efficient, it introduces subtle incompatibilities with the typed arrays specification. ArrayBuffer#slice() makes a copy of the slice while Buffer#slice() creates a view."

@MidnightLightning
MidnightLightning / btc.html
Created March 3, 2013 23:08
Use AJAX to drop in a price in BTC on page load. If javascript fails, the page just displays the USD amount. It needs a PHP file to proxy the blockchain.info ticker, since it does not have Cross-Origin headers.
<html>
<head><title>BTC prices</title></head>
<body>
<p>Buy this widget for $10<span id="btc"></span>.</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.ajax({
url: 'btc.php',
@MidnightLightning
MidnightLightning / README.md
Created July 27, 2012 01:50
Steganography tools

Steganography: the art of hiding in plain sight. Messages specifically. These are a series of tools that aid in embedding messages in digital files.

While steganography provides obscurity, it does not strictly provide security. Before hiding your message using any of these scripts, it's suggested you encode your message (try PGP/GnuPG encryption or put it in a TrueCrypt container if you're at a loss).

pngload.py

The PNG file format divides the image data into 'chunks', and allows for additional, private chunks to be added by image editors. This script takes the message you wish to embed and saves it as binary data in such an ancillary chunk.

The files being embedded are compressed with bzip2 compression if they're not already a bzip2 archive. This is different from the `

@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
@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;
}
<!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 / 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", "/")
@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 / 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
*/