Skip to content

Instantly share code, notes, and snippets.

View trueheart78's full-sized avatar
💖

Josh Mills trueheart78

💖
View GitHub Profile
#!/usr/bin/env ruby
# Helpful link: http://httpd.apache.org/docs/2.4/logs.html
require 'date'
line_count = 0
File.open(ARGV[0]).readlines.each do |line|
line_count += 1
result = /^(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}).*\[(.*)\].*(GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT)\s(.*)\"\s(\d+)\s(\d+)(.*)$/.match(line)
// ==UserScript==
// @name SludgeHammer
// @namespace gamerswithjobs
// @description Replaces marketing speak with English
// @exclude /github/
// @author Chris Doggett
// ==/UserScript==
// Special thanks to Jeremy Banks at http://stackoverflow.com/a/6834930/64203
var load,execute,loadAndExecute;load=function(a,b,c){var d;d=document.createElement("script"),d.setAttribute("src",a),b!=null&&d.addEventListener("load",b),c!=null&&d.addEventListener("error",c),document.body.appendChild(d);return d},execute=function(a){var b,c;typeof a=="function"?b="("+a+")();":b=a,c=document.createElement("script"),c.textContent=b,document.body.appendChild(c);return c},loadAndExecute=function(a,b){return load(a,function(){return execute(b)})};
@trueheart78
trueheart78 / fs-monitor.rb
Last active August 29, 2015 14:08
A simple ruby script to monitor filesizes during a large transfer. Setup to run through cron. Requires the mandrill-api gem to be installed, as well as a mandrill API key in your enviroment in MANDRILL_APIKEY
require 'mandrill'
files = ["mh-files-wo-lb-20141026_0009.tar.gz","mh-files-lb-only-20141026_0009.tar.gz"]
files.each do |f|
if File.exist?(f)
size = File.stat(f).size
gb = 1024 ** 3
mb = 1024 ** 2
status = "#{size / gb} gb (#{size / mb} mb)"
puts "File #{f} - as of #{Time.now}:\n"
@trueheart78
trueheart78 / issue-puller.rb
Last active August 29, 2015 14:17
Github Issue Retriever for a particular user (exercism)
require 'json'
require 'open-uri'
OAUTH_TOKEN = ''
class Github
def auth_token
"access_token="+OAUTH_TOKEN unless OAUTH_TOKEN.empty?
end
end
#!/bin/bash
for f in `find ~/.ssh -perm 600 -type f`
do
add_key=true
for k in `ssh-add -l`
do
if [[ "$k" = "$f" ]]
then
add_key=false
fi
@trueheart78
trueheart78 / chruby-ruby-setup.sh
Last active August 31, 2016 20:13
Chruby + Ruby Install Setup
#!/usr/bin/env bash
# chruby - https://github.com/postmodern/chruby
wget -O chruby-0.3.9.tar.gz https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz
tar -xzvf chruby-0.3.9.tar.gz
cd chruby-0.3.9/
sudo make install
echo "Add to you shellrc file: source /usr/local/share/chruby/chruby.sh"
# ruby-install - https://github.com/postmodern/ruby-install
@trueheart78
trueheart78 / rubo_copper.rb
Last active May 9, 2017 18:22
RuboCopper
class RuboCopper
def analyze
system 'rubocop', '--display-cop-names', *files
end
def autofix
system 'rubocop', '--auto-correct', '--display-cop-names', *files
end
def valid?
@trueheart78
trueheart78 / 01_session_security.rb
Created December 12, 2017 14:23
64 Digit Session ID for Rails
# config/initializers/01_session_security.rb
module SessionSecurity
def generate_sid
sid = SecureRandom.hex(32)
sid.encode!(Encoding::UTF_8)
sid
end
end
@trueheart78
trueheart78 / download_recent_stable_kernel.rb
Last active February 4, 2018 06:27
Detect and download the most recent stable Ubuntu kernel version
require 'nokogiri'
require 'net/http'
require 'uri'
require 'byebug'
require 'open-uri'
class LinuxKernel
OFFICIAL_KERNEL_URL = 'https://www.kernel.org/'.freeze
UBUNTU_KERNEL_BASE_URL = 'http://kernel.ubuntu.com/~kernel-ppa/mainline/'.freeze
@trueheart78
trueheart78 / zsh-history-parser.rb
Last active November 7, 2022 19:57
A Z Shell History Parser - Now a git repo! https://github.com/trueheart78/zsh-history-parser
#!/usr/bin/env ruby
require 'etc'
commands = {}
File.readlines(File.join(Etc.getpwuid.dir, '.zsh_history')).each do |l|
l = l.encode('utf-8', 'binary', :undef => :replace)
next if l == ''
next unless l.match(/: \d+:/)
l = l.sub(';','[SPLIT]').split('[SPLIT]')
key = l.last.split.first