Skip to content

Instantly share code, notes, and snippets.

@zorgnax
zorgnax / ftpsync
Last active August 29, 2015 13:59
Sync directories from and to FTP
#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
use Data::Dump::Color;
get_opts();
my $src = parse_ref_spec($ARGV[0]);
my $dest = parse_ref_spec($ARGV[1]);
@zorgnax
zorgnax / clmn
Created March 17, 2014 17:14
Displays data in columns best fit for terminal. Like ls. Ignores ANSI escape sequences.
#!/usr/bin/perl
use strict;
use warnings;
use Term::Size;
my ($max_chars) = Term::Size::chars(\*STDOUT);
my $delimiter = qr/\n/;
my $rows_first = 0;
my $columns;
my @args;
@zorgnax
zorgnax / gist:2423441
Created April 19, 2012 19:25
Bash prompt with color, shortened path, git branch, and retval
PS1='\u@\h \w \$ '
reduce-path() {
local path=${1-$PWD} target=${2-33} IFS=/
[[ "$path" =~ ^$HOME(/|$) ]] && path="~${path#$HOME}"
[[ ${#path} -le $target ]] && echo "$path" && return
local order=$((i=0; for e in $path; do echo ${#e} $i; ((i++)); done) |
head -n-1 | sort -rn | cut -d " " -f 2)
local elements=($path)
IFS=$'\n'
for i in $order; do
@zorgnax
zorgnax / ansicolor
Created June 10, 2011 20:09
Lists ANSI color codes
#!/bin/bash
# bash script that prints out ansi codes for different colors
function name {
local bold=$1 color=$2
test -z $bold || echo -ne "bold "
case $color in
30) echo black ;;
31) echo red ;;
32) echo green ;;
33) echo yellow ;;
@zorgnax
zorgnax / c
Last active September 5, 2015 05:44
C one liners
#!/usr/bin/perl
use strict;
use warnings;
my $script = "#include <stdio.h>\n";
my $main = "";
my @args = @ARGV;
@ARGV = ();
while ($_ = shift @args) {
@zorgnax
zorgnax / colormake
Created June 19, 2010 03:06
colormake
#!/usr/bin/perl
use Term::ANSIColor;
my $make_color = 'cyan';
my $cmd_color = 'cyan';
my $trace_color = 'green';
my $file_color = 'bold green';
my $line_color = 'bold yellow';
my $warning_color = 'bold red';
@zorgnax
zorgnax / lostinorder.pl
Created June 2, 2010 03:27
Lost in Order
#!/usr/bin/perl
use Data::Dumper;
use Term::ANSIColor;
# plays lost files in order
#
# B jacob and smokey
# black rock
# |