Skip to content

Instantly share code, notes, and snippets.

View sstelfox's full-sized avatar

Sam Stelfox sstelfox

View GitHub Profile
@sstelfox
sstelfox / pw.rb
Created July 14, 2012 06:09
Quick password generator
#!/usr/bin/env ruby
ambiguous_characters = %w{ O 0 l I 1 |}
special_characters = %w{ ! @ # $ % ^ & * ( ) - _ + = [ ] | ; : " , < . > / ? ~ }
character_set = [('a'..'z'), ('A'..'Z'), (0..9), special_characters].map do |item|
item.to_a
end
character_set.flatten!.map(&:to_s)
@sstelfox
sstelfox / html_clenser.rb
Created October 11, 2012 20:11
Quick Way to make Minified HTML readable
#!/usr/bin/env ruby
SOURCE_PAGE="http://google.com/"
DEST_FILE="formatted-google-homepage.html"
require "nokogiri"
require "open-uri"
pretty_print_xsl = <<-EOS
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
@sstelfox
sstelfox / gist:4709573
Created February 4, 2013 20:40
Linux version of the imagesnap post-commit git hooks. To use create the file .git/hooks/post-commit in any repository you commit in often. Requires you have fswebcam installed (most distros have a package for it). Snapshots are stored in ~/.gitshots.
#!/usr/bin/env ruby
#
require 'fileutils'
fswebcam_path = `which fswebcam`.strip
exit 0 if fswebcam_path.empty?
print "Snapshotting your pretty mug..."
@sstelfox
sstelfox / safe_parse.rb
Created March 27, 2013 19:27
Safely parse JSON in ruby.
require 'json'
unsafe_json = <<-EOS
{
"json_class": "DangerousClass",
"command": "sudo rm -rf /"
}
EOS
# OH GOD WHERE DID MY SYSTEM GO!?
@sstelfox
sstelfox / Rakefile
Last active December 15, 2015 19:49
This is my version of the Rails rake routes task for Sinatra. I've found this to be endlessly useful in debugging route ordering.
require 'sinatra_app'
# This comes from the sinatra-contrib gem
require 'sinatra/decompile'
# This will print all of the configured routes for the sinatra application in
# the order that the route was first specified. All of the methods will be
# combined together and it will format the output into neat columns. Very useful
# for debugging when an incorrect route is being hit.
desc "List all of the routes configured"
@sstelfox
sstelfox / cookie_clicker_cheater.rb
Last active June 24, 2023 22:31
Got bored, wrote a generator for the cookie clicker exported save format.
@sstelfox
sstelfox / config.rb
Created November 15, 2013 03:02
Simple DSL pattern for configuration
require 'singleton'
Config = Struct.new(:a, :b)
class Config
include Singleton
def self.[](arg)
instance.public_send(arg.to_sym)
end
@sstelfox
sstelfox / idn.rb
Created January 2, 2014 15:17
A random script I wrote to look up short potentially available domain names that are 'real' words including the TLD. This was a random script I pulled out a laptop that I was cleaning up and I'm saving for posterity.
#!/usr/bin/env ruby
require 'socket'
# cc.cc, cu.cc, cz.cc, co.nr, dot.tk -> Free domain services
# Pity can't do .ie, .it as they're common word endings
# This is a list of the ASCII internationalized TLDs that allow second level
# domain registrations and do not require any form of physical presence of
# citizenship within their country as reported by Wikipedia.
@sstelfox
sstelfox / format_card.sh
Created January 2, 2014 15:21
This was a helper for formatting SD cards in a very specific way. Cleaned this off of a laptop and shared here for posterity.
#!/bin/bash
if [[ "$1" == "" ]]; then
echo "You need to provide the device to operate on"
exit 1
fi
echo 'Blowing away any partition tables...'
#dd if=/dev/zero of=$1 bs=1k count=1024
@sstelfox
sstelfox / enum_hosts.html
Created January 2, 2014 16:13
Copy of a localhost enumeration using WebRTC. I can't take credit for writing this though I don't know where I originally got this from.
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Anonymous+Pro:400,700|Droid+Sans+Mono|Open+Sans:400,700|Linden+Hill|Quattrocento:400,700|News+Cycle:400,700|Antic+Slab|Cabin+Condensed:400,700">
<style>
body {
font-family: 'Open Sans', Helvetica, Arial, FreeSans;
font-size: 12pt;
color: #666;
margin-top: 40px;
text-align: center;