This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub trim($) { | |
my $string = shift; | |
$string =~ s/^\s+//; | |
$string =~ s/\s+$//; | |
return $string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub current_date{ | |
my ($d,$m,$y) = (localtime)[3,4,5]; | |
# Normalise dates | |
($m+=1,$y+=1900); | |
# Check prefix with zero | |
$m = "0$m" if ($m < 10); | |
$d = "0$d" if ($d < 10); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd `ls -1t | sed -n 1p` # cd to latest dir | |
unzip *.zip -d deploydir/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.roseindia.net/java/example/java/io/java-write-to-file.shtml | |
// Tidy up the syntax by writting it this way... | |
// Check if fd can be a File obj or the textual name of the file | |
// http://docs.oracle.com/javase/1.4.2/docs/api/java/io/FileOutputStream.html | |
BufferredWriter buffWrite = new BufferredWriter(new FileOutputStream(fd)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Argument = -t test -r server -p password -v | |
usage() | |
{ | |
cat << EOF | |
usage: $0 options | |
This script run the test1 or test2 over a machine. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/125171/passing-a-regex-substitution-as-a-variable-in-perl | |
$pattern = qr/foo/; | |
print "match!\n" if $text =~ $pattern; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin` | |
# Be sure to have rails and thin installed. | |
require "rubygems" | |
# We are not loading Active Record, nor the Assets Pipeline, etc. | |
# This could also be in your Gemfile. | |
gem "actionpack", "~> 3.2" | |
gem "railties", "~> 3.2" | |
# The following lines should come as no surprise. Except by |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For internal code | |
module Kernel | |
def capture_stdout &block | |
out = StringIO.new | |
$stdout = out | |
yield | |
return out | |
ensure | |
$stderr = STDOUT | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1 | |
def file_read(filename) | |
file = File.new(filename,'r') | |
yield file # file is the variable passed into the block (anything between do and end is a block) f is the variable used the access this in example 1 usage. | |
file.close | |
end | |
# Example 1 usage | |
file_read('temp.rb') do |f| # f is the file descriptor for accessing methods on the file | |
puts f.read # reads the whole file as a string puts is essentially println in java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File.open('data.txt','r') do |f| | |
data = f.read | |
puts data.gsub(/(.+)\n/){$1+"\t"} | |
end |
OlderNewer