Skip to content

Instantly share code, notes, and snippets.

View princebot's full-sized avatar

princebot princebot

View GitHub Profile
@princebot
princebot / rebuild_key.py
Created November 6, 2016 03:02
Convert private keys saved in LastPass as SSH Key Secure Notes back to a usable format
#!/usr/bin/env python
"""Convert private keys saved in LastPass back to a usable format.
1. Copy-paste key from Secure Note to a local file.
2. Run this script passing the file as an argument.
3. Formatted key prints to stdout.
Example:
python rebuild_key.py ~/.ssh/keys/why_lastpass_why > ~/.ssh/keys/fixed
"""
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Create Ubuntu 16 machine and do the following provision actions:
# - Update all packages.
# - Install git.
# - Install curl and wget.
# - Install apt-transport-https and ca-certificates.
@princebot
princebot / sigil.rb
Last active January 5, 2017 18:37
Exploring Ruby's black magic #1
# This Enumerator#sum example from the Ruby docs is pure black magic to me:
#
# "a\nb\nc".each_line.lazy.map(&:chomp).sum("") #=> "abc"
#
# So I’mma figure out how and why it works by implementing a version of it.
# Sigils are Symbol-like objects that can be converted to Procs.
class Sigil
def initialize(name)
@name = name
@princebot
princebot / file.go
Last active January 6, 2017 07:58
General difference between `stat` and `open` for files.
// This demonstrates a little bit of how Unix directories work, re late-night chat with Bujol about Facebook Haystack.
//
// (Go makes this clearer than languages like Python or Ruby generally do.)
package main
import (
"bytes"
"fmt"
"go/doc"
"log"
@princebot
princebot / wrap.go
Created March 27, 2017 14:31
Wrap text to fixed length using Go's standard library,
// Wrap text to fixed length with Go (demo).
package main
import (
"go/doc"
"os"
)
const lorem = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`
@princebot
princebot / selecta.py
Created May 11, 2017 02:16
Editing a friend's script for Python style.
#!/usr/bin/env python
"""
Parse RideAustin data from https://data.world/andytryba/rideaustin/file/RideAustin_Weather.csv
"""
import argparse
import pandas
from dateutil import parser
@princebot
princebot / command-injection.sh
Last active July 28, 2017 10:14
A command injection example.
# This is my stream-of-consciousness attempt to figure out why
# https://twitter.com/asdizzle_/status/890496680495374336 works.
#
# As the tweet says, many validator techniques (filters and WAFs?) prohibit
# spaces, $, {, or } and such. This uses shell-fu to get around that by using
# command substitution (the backticks).
#
# Basically, everything in backticks is evaluated before the shell executes
# the "real" command, uname.
#
@princebot
princebot / install_wormhole.bat
Created July 29, 2017 17:44
Install Python magic-wormhole on Windows.
::
:: This script installs wormhole (https://github.com/warner/magic-wormhole) and
:: its prerequisites. Run this as an administrator.
::
:: Install chocolatey.
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
:: Install Python 3.
choco install -y python