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 / README.md
Last active April 12, 2016 21:04
A ruby script to check if wifi AP authentication details are correct

Wifi Auth Test Script

This script will attempt to check the authentication details for an AP to see if they are correct. It should be called like so:

$ ruby wpa_auth_test.rb "FBISurveillanceVan4" "stingrays 4 eva"
I, [2000-01-02T02:36:27.925647 #14255]  INFO -- : Starting WPA Supplicant
I, [2000-01-02T02:36:28.097044 #14255]  INFO -- : Searching WPA log for authentication state
I, [2000-01-02T02:36:37.943307 #14255]  INFO -- : Found authentication state in 10.02 seconds
I, [2000-01-02T02:36:37.947201 #14255]  INFO -- : Killing WPA on PID 14268

E, [2000-01-02T02:36:37.961020 #14255] ERROR -- : Authentication failed

@penguinpowernz
penguinpowernz / nwinfo.rb
Created February 28, 2016 03:33
Ruby network interface information parser
#!/usr/bin/env ruby
require 'json'
ifaces = []
whitelist = [ "eth", "wlan", "en" ]
names = `ip link sh`.scan(/^\d+: (.*):/).flatten.select do |name|
whitelist.any? {|pattern| name.start_with?(pattern) }
end
@penguinpowernz
penguinpowernz / leaseinfo.rb
Created February 28, 2016 03:33
Ruby dhclient.leases parser
#!/usr/bin/env ruby
require 'json'
file = ARGV[0] || "/var/lib/dhcp/dhclient.leases"
lines = File.read(file).lines
leases = []
newlease = {"interface" => "", "options" => {}}
@penguinpowernz
penguinpowernz / README.md
Last active January 13, 2016 02:31
An easy way to set your go env when switching between projects

GOSET

I've probably reinvented the wheel, but I had an itch to scratch so hacked up this little script. Make it executable and put it somewhere where it will get in your $PATH variable, then run it like this:

source `goenv.rb`

But take it a step even futher and put it in an alias:

componentDidMount: function() {
if ( typeof window.gc === 'function' ) {
setInterval(hackityHack.bind(this), 600000);
}
},
// filthy hack to fix gauge memory leak
hackityHack: function() {
this.setState({showGauges: false });
console.log('doing garbage collection')
@penguinpowernz
penguinpowernz / webpack.config.js
Created December 8, 2015 20:39
Webpack config
/***********************************************************************
*
* WEBPACK CONFIGURATION FILE
*
* Built with recommendations from http://survivejs.com/webpack_react/
*
***********************************************************************/
var path = require('path');
var webpack = require('webpack');
@penguinpowernz
penguinpowernz / README.md
Created December 2, 2015 22:32
A hacky script for counting code in your project

codecount.rb

This is a really hacky script for showing you percentages of code in your project. I like to keep it at ~/bin/codecount so it's accessible from wherever.

Here's an example of calling it:

$ codecount
PERCENTAGE BY FILETYPE:
 TYPE FILES 
@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
@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.

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);