Skip to content

Instantly share code, notes, and snippets.

@takus
takus / IPC-Cmd-Sample.pl
Created October 8, 2011 23:47
Execute external openssl command by using IPC::Cmd
use IPC::Cmd qw/can_run run/;
our $OPENSSL = can_run('openssl') or die 'openssl is not installed!';
my $ok = run(
verbose => 0,
command => [
"openssl", "enc",
"-e", "-aes256",
"-in", $input,
@takus
takus / find-all-files-in-directory.pl
Created October 9, 2011 09:32
Find all files in a directory
opendir DH, $dir or die "Error: can't open $dir : $!";
while (my $file = readdir DH) {
next if $file =~ /^\.{1,2}$/;
print $file, "\n";
}
closedir DH;
@takus
takus / sample-File-Find.pl
Created October 9, 2011 10:17
Sample code of File::Find
use File::Find;
my $dir = '/home/takus';
find(\&print_file, $dir);
sub print_file {
print $File::Find::name, "\n";
}
@takus
takus / find_all_files_recursively.pl
Created October 9, 2011 12:27
Find all files under a base directory recursively
#!/usr/bin/env perl
my $base_dir = shift;
my $ref_files = &get_file_paths($base_dir);
for (@$ref_files) {
print "$_\n";
}
@takus
takus / copy_to_temp_file.pl
Created October 9, 2011 14:37
Create temp file from existing file
#!/usr/bin/env perl
use strict;
use warnings;
use File::Temp;
use File::Copy;
my $origin_file = shift;
@takus
takus / rm-with-trash.sh
Created October 11, 2011 02:06
hook script of rm
#!/bin/sh
# hook script of rm
#
# Setup
# alias rm="foo/bar/rm-with-trash.sh"
trash=$HOME/.trash
if [ ! -d $trash ]
@takus
takus / xargs-cp.sh
Created October 13, 2011 15:34
Give multi arguments to cp when using xargs
#!/bin/sh
find . -name '*.pdf' | xargs -i cp {} /tmp
@takus
takus / build.xml
Created October 25, 2011 05:00
ant example of building executable jar
<?xml version="1.0" encoding="UTF-8"?>
<project name="make_exec_jar" default="jar" basedir="." >
<target name="jar">
<jar basedir="../classes" jarfile="hello.jar">
<manifest>
<attribute name="Main-Class" value="me.takus.sample.Hello"/>
</manifest>
</jar>
</target>
</project>
@takus
takus / gist:1311351
Created October 25, 2011 05:01
ssh to remote host & execute command & stay at remote server after executing
ssh -t user@host "cd /path/to/dir && /bin/bash"
@takus
takus / output.gnu
Created October 28, 2011 04:42
Show realtime graph by gnuplot
plot "output"
pause 0.1
reread
watch