Skip to content

Instantly share code, notes, and snippets.

@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 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.

# 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
@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|
@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 / basic_pkgs
Last active December 9, 2016 16:03
Quickly install some basic packages on a Ubuntu machine.
#!/bin/bash
sudo apt-get update && sudo apt-get install -y htop tmux vim man nmap curl git-core sysstat bwm-ng iotop ipcalc sl mtr dnsutils
@snarlysodboxer
snarlysodboxer / zero_disk.sh
Last active June 19, 2020 10:32
Write zeros over all of the free space on your disk. Afterwards, remove a small file before removing the big file to help the system be more responsive in the meantime.
#!/bin/sh
dd if=/dev/zero of=$HOME/zero.small.file iflag=nocache oflag=direct bs=1024 count=102400
dd if=/dev/zero of=$HOME/zero.file iflag=nocache oflag=direct bs=4096
rm $HOME/zero.small.file
rm $HOME/zero.file
@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() {

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

@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