Simple Perl variables are called scalars
. Examples of scalar values are
$number = 123;
$string = "String";
$file_handle = open "<filename";
$null_value = undef;
$instance = MyClass->new;
#!/bin/bash | |
# Inspired by http://blog.fiveruns.com/2008/9/24/rails-automation-at-slicehost | |
apt-get update | |
apt-get upgrade -y | |
apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev | |
apt-get -y install mysql-server libmysqlclient15-dev mysql-client | |
apt-get -y install ruby ruby1.8-dev irb ri rdoc libopenssl-ruby1.8 | |
RUBYGEMS="rubygems-1.3.0" |
#!/bin/bash | |
# Update the system first | |
sudo ntpdate ntp.ubuntu.com | |
sudo apt-get update | |
sudo apt-get upgrade | |
# Ubuntu stuff | |
sudo apt-get -y install git-core openssh-server openssh-client build-essential wget ntp-simple | |
# be aware: vim vim-ruby installed x crap :( |
require 'active_support' | |
class MyLogger < ActiveSupport::BufferedLogger | |
SEVERITY_NAME = %w( DEBUG INFO WARN ERROR FATAL UNKNOWN ) | |
def custom_line(severity, message) | |
# Customized Log Format! | |
message = [Time.now.strftime("%Y-%m-%d %H:%M:%S"), ENV['BL_JOB_ID']||$$, SEVERITY_NAME[severity], message].join("\t") | |
end | |
def add(severity, message = nil, progname = nil, &block) |
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'nokogiri' | |
class Cleaner | |
def read | |
f = File.open("nelson.xml") | |
@doc = Nokogiri::XML(f) | |
f.close | |
end |
# http://avdi.org/talks/confident-code-2010-01-12/confident-code.html | |
# Narrative structure: Four Parts | |
#========================================================== | |
# Gather input: | |
# Coerce | |
param.to_s #to_i #to_sym Array() ... use liberally! | |
messages = Array(messages) | |
# Decorators |
##---------------------------------------------------------------- | |
## HSTORE: PostgreSQL key-value store column type | |
##---------------------------------------------------------------- | |
# Double-quotes the value, escaping embedded double-quotes. This is NOT the | |
# same as db quoting (which uses apostrophes), and any value here must also | |
# be quote()'ed before sending to the database. | |
sub double_quote { | |
my ($self, $v) = @_; | |
$v =~ s/"/\\"/g; |
require 'resolv' | |
class Domain | |
def mxers(domain) | |
mxs = Resolv::DNS.open do |dns| | |
ress = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) | |
ress.map { |r| [r.exchange.to_s, IPSocket::getaddress(r.exchange.to_s), r.preference] } | |
end | |
return mxs |
#!/usr/bin/env bash | |
# | |
# Script to initiate (or connect to) a rails project | |
# tmux session. | |
if [[ "$1" != "" ]]; then | |
app=$1 | |
APPDIR=$HOME/src/$app | |
cd $APPDIR | |
else |
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
############################################################################### | |
# Ruby 1.9 Unicode Demonstration | |
############################################################################### | |
require 'rubygems' | |
require 'unicode' # gem unicode | |
require 'unicode_utils' # gem unicode_utils | |
require 'rchardet19' # gem rchardet19 |