Skip to content

Instantly share code, notes, and snippets.

View mattantonelli's full-sized avatar

Matt Antonelli mattantonelli

  • 07:26 (UTC -05:00)
View GitHub Profile
@mattantonelli
mattantonelli / test_generator.rb
Created May 27, 2014 16:39
assertEquals() Test Generator
input_path = "input.txt"
output = File.open("output.txt", "w")
File.readlines(input_path).each do |line|
if(line.include?("testGet"))
output.puts line
get_method = line[/Get.*\(\)/]
get_method[0] = get_method[0].downcase
@mattantonelli
mattantonelli / iptables
Created July 7, 2014 14:16
CentOS iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
@mattantonelli
mattantonelli / low_free_space_tbs.sql
Created July 8, 2014 14:28
All datafiles of tablespaces that are more than 85% full
select df.tablespace_name "Tablespace",
df.file_name "File",
df.status "Status",
df.autoextensible "Auto Extend?",
round((df.bytes / 1073741824), 2) "Used GB",
round((df.maxbytes / 1073741824), 2) "Max GB",
round(100 * (df.bytes / df.maxbytes), 2) "% Used",
round((df.increment_by * (df.bytes / df.blocks)) / 1073741824, 2) "Extent Size GB",
round((df.maxbytes - df.bytes) / (df.increment_by * (df.bytes / df.blocks))) "Remaining Extensions",
round(pu."pct_used", 2) "% Tablespace Used"
@mattantonelli
mattantonelli / logfile_switches.sql
Last active August 29, 2015 14:04
/* View average # of log file switches per hour for a month */
/* View average # of log file switches per hour for a month */
select month "Month",
case
when month = to_char(sysdate, 'Month') then
/* divide by hours since start of the month when looking at current month*/
round(log_switches / (24 * ((to_number(to_char(sysdate, 'dd'))) - 1) +
(to_number(to_char(sysdate, 'hh'))) ), 1)
else
/* otherwise divide by total # hours in month */
round(log_switches / (24 * to_number(to_char(last_day(to_date(month, 'Month')), 'dd'))), 1)
@mattantonelli
mattantonelli / csv_to_table.rb
Last active August 29, 2015 14:06
Converts CSV to Github table markdown
#!/usr/bin/env ruby
# encoding: utf-8
input = "a,b,c\nd,e,f\ng,h,i"
num_cols = input[0..input.index("\n")].scan(',').count
puts input.split("\n").map { |l| l.gsub(/ *, */, ' | ') }.insert(1, '---|' * num_cols + '---')
@mattantonelli
mattantonelli / listToArray.java
Created September 16, 2014 13:28
Comparing the time to convert a List to an Array versus remaining as an Array.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestListToArrayConversion {
public static void main(String[] args) {
Map<String, Object> testMap = new HashMap<String, Object>();
@mattantonelli
mattantonelli / ego_stroker.rb
Last active August 29, 2015 14:06
A Ruby script to stroke your ego! Or not!
#!/usr/bin/env ruby
# encoding: utf-8
ego_level = ARGV[0].to_i
if ego_level == 0
puts "You're pretty average."
else
puts "You are s#{'o' * ego_level.abs} #{ego_level < 0 ? 'un' : ''}cool!!!"
end
#!/usr/bin/env bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root!"
exit 1
fi
echo "Syncing with NTP server"
ntpdate north-america.pool.ntp.org
@mattantonelli
mattantonelli / find_ranges.rb
Last active August 29, 2015 14:07
Take an array of numbers and condense it into a list of ranges using recursion.
def find_range(a, str = '')
return str[2..-1] if a.empty?
start_val = end_val = a[0]
a.each do |val|
break if val > end_val + 1
end_val = val
end
if start_val == end_val
@mattantonelli
mattantonelli / rangencount.rb
Created October 20, 2014 22:48
Generate a link to a related model with text indicating the range from the objects' names and a total count of the objects. Will generate multiple ranges as necessary, intended for numeric names.
def range_and_count_link(network_elements, path, with_link, unique)
ranges = generate_name_ranges(network_elements)
count = unique ? network_elements.uniq.size : network_elements.size
count_str = with_link && count > 0 ? link_to(count, path) : count.to_s
"#{ranges} (#{count_str})".html_safe
end
def range_and_count(network_element, element_to_count, with_link = true, unique = false)
poly_route = with_link ? [network_element, element_to_count] : network_element
range_and_count_link(network_element.send(element_to_count), polymorphic_url(poly_route), with_link, unique)