Skip to content

Instantly share code, notes, and snippets.

@b4hand
b4hand / merge_uniq_output.pl
Created February 15, 2016 19:50
Merges multiple sets of output from the `uniq` command into a single output
#!/usr/bin/env perl
use strict;
use warnings;
use List::Util qw(max);
my %counts;
sub log10 {
@b4hand
b4hand / clear_ssh_host_keys
Last active December 3, 2015 19:50
Clears out old ssh keys in ~/.ssh/known_hosts
#!/usr/bin/env bash
hostname=$1
ip=`host $hostname | head -1 | awk '{print $4}'`
ssh-keygen -R $hostname
ssh-keygen -R $ip
@b4hand
b4hand / yaml_extract.py
Created March 11, 2014 01:07
Extract a single value from a YAML file
#!/usr/bin/env python
from __future__ import print_function
import sys, yaml
if len(sys.argv) < 3:
print("usage: %s file key ... " % (sys.argv[0]), file=sys.stderr)
exit(1)
#!/usr/bin/perl
# We want all of our time computations to be made in UTC
BEGIN { $ENV{TZ} = 'UTC'; }
use strict;
use warnings;
use Date::Format;
@b4hand
b4hand / stop-hadoop-hbase
Created December 18, 2013 00:39
Stops all of the services needed by HBase in a pseudo-distributed environment.
#!/bin/sh
service hbase-regionserver stop
service hbase-master stop
service zookeeper-server stop
service hadoop-0.20-mapreduce-tasktracker stop
service hadoop-0.20-mapreduce-jobtracker stop
service hadoop-hdfs-datanode stop
service hadoop-hdfs-secondarynamenode stop
service hadoop-hdfs-namenode stop
@b4hand
b4hand / start-hadoop-hbase
Last active December 31, 2015 16:39
Starts all of the services needed by HBase in a pseudo-distributed environment.
#!/bin/sh
service hadoop-hdfs-namenode start
service hadoop-hdfs-secondarynamenode start
service hadoop-hdfs-datanode start
service hadoop-0.20-mapreduce-jobtracker start
service hadoop-0.20-mapreduce-tasktracker start
service zookeeper-server start
service hbase-master start
service hbase-regionserver start
@b4hand
b4hand / wipe-localhost-hbase
Last active December 22, 2015 16:59
Completely wipes a pseudo-distributed HBase environment.
#!/bin/sh
service hbase-regionserver stop
service hbase-master stop
echo -e "rmr /hbase\nquit" | hbase zkcli
sudo -u hdfs hadoop fs -rm -r /hbase
sudo -u hdfs hadoop fs -mkdir /hbase
sudo -u hdfs hadoop fs -chown hbase /hbase
@b4hand
b4hand / ip_to_name
Last active December 20, 2015 18:49
Do an IP to name resolution from the command line
perl -e 'use Socket qw(getnameinfo inet_aton pack_sockaddr_in NI_NUMERICSERV); my $ip = inet_aton($ARGV[0]); my $addr = pack_sockaddr_in(80, $ip); my ($err, $hostname) = getnameinfo($addr, NI_NUMERICSERV); print "$hostname\n"'
@b4hand
b4hand / name_to_ip
Last active June 12, 2019 00:43
Resolve a hostname to all IPs via command line (IPv4 or IPV6)
perl -e 'use Socket qw(getaddrinfo getnameinfo NI_NUMERICSERV NI_NUMERICHOST); my ($err, @res) = getaddrinfo($ARGV[0], "www", {socktype => SOCK_STREAM}); for my $r (@res) { my ($err, $ip) = getnameinfo($r->{addr}, NI_NUMERICHOST | NI_NUMERICSERV); print "$ip\n";}'