Skip to content

Instantly share code, notes, and snippets.

@snarlysodboxer
snarlysodboxer / sshportforward2.go
Last active April 4, 2016 15:50
pile of go ssh port forward attempt
package main
import (
"code.google.com/p/go.crypto/ssh"
//"net/http"
"io/ioutil"
"net"
)
func main() {
@snarlysodboxer
snarlysodboxer / find_duplicates.rb
Created January 30, 2016 01:23
Find (and optionally delete) duplicate files in directories using md5sum
#!/usr/bin/env ruby
# Usage:
# `./find_duplicates.rb 'directory to search*'` for a dry run, and
# `./find_duplicates.rb 'directory to search*' --delete` to actually delete the duplicates.
find_path = ARGV[0]
delete = false
delete = true if ARGV[1] == "--delete"
files = `find #{find_path} -type f`.split "\n"
@snarlysodboxer
snarlysodboxer / white_space_police.sh
Created December 21, 2015 21:44
White space police for Ruby files
#!/bin/bash
# remove trailing whitespace
find ./ -name '*.rb' -exec sed -i "s/\s\+$//g" {} +
# switch tabs for two spaces
find ./ -name '*.rb' -exec sed -i "s/\t/ /g" {} +
# auto indent with Vim
# open any file in Vim, then:
:args ~/code/myproject/**/*.rb | argdo execute "normal gg=G" | update
@snarlysodboxer
snarlysodboxer / rbenv_ruby.sh
Last active December 18, 2015 04:18
Install rbenv, rbenv-build, and ruby idempotently for use in bash.Works for Ubuntu and Mac.
#!/bin/bash
if test -f $HOME/.profile
then
PROFILE_FILE="$HOME/.profile"
elif test -f $HOME/.bash_profile
then
PROFILE_FILE="$HOME/.bash_profile"
else
echo "Creating a new .bash_profile file."
@snarlysodboxer
snarlysodboxer / log_count.rb
Last active December 17, 2015 14:09
This is just a spike for demonstration. It could be re-written better in many ways.
#!/usr/bin/env ruby
file_string = File.read('mail.redact.small')
line_array = Array.new
file_string.each_line { |line| line_array << line }
uid_array = Array.new
line_array.each do |line|
# The version of Ruby to be installed
ruby_ver="1.9.3-p429"
# The base path to the Ruby
ruby_home="/usr/local"
# Enable truly non interactive apt-get installs
export DEBIAN_FRONTEND=noninteractive
apt-get update

This script shows ruby 1.8.7's strange behavior relating to the order of a returned array after setting certain unrelated hashes.

a = { :a => nil } running this code first causes the below to return in reverse order. b = { :a => nil } running this code first causes the below to return in correct order. { :y => true, :s => true }.collect { |k, v| k } is the code that returns the array. It is run the same way every iteration.

For this bug to manifest, irb must be restarted between tests. Once an irb session has returned the array in a particular direction, it will continue to return it in that direction no matter what is done until you exit and restart irb. (Thus, this bash script to automate starting and using irb.) This bug does not happen in ruby 1.9.3, meaning no matter what you do, you will always get the array returned in the same direction. The results are repeatably reliable.

The test_ruby_bug.txt file is the output of this script.

@snarlysodboxer
snarlysodboxer / de_kernel.rb
Last active December 16, 2015 10:08
A little script to help with removing old kernels when they have built up over time. NOTE: This gained too many files for a gist, the gist repo was merged to the following active repo: https://github.com/snarlysodboxer/deKernel
class DeKernel
def self.run
system "clear"
puts "It's generally recommended to leave at least three of your latest kernels"
all_kernels = Kernels.find_all_kernels
installed_kernels = Kernels.find_installed_kernels(all_kernels)
kernels_to_remove = Kernels.ask_which_to_remove(installed_kernels)
Kernels.purge_packages_from_kernels_list(kernels_to_remove)
Kernels.print_other_kernels_message
end

this:

FROM localhost:5000/ubuntu/base-12.04:latest
MAINTAINER The CTI Solutions Inc. Team

ADD delete_me_code/ /var/www/current/

RUN mkdir /var/www/current/log
RUN mkdir /var/www/current/tmp

RUN mkdir /var/www/current/var