2012/10/31

UTF8

# flags source code as UTF8
use utf8;

# flags STDOUT as UTF8
binmode(STDOUT, ":encoding(utf-8)");

2012/10/23

Stop "sshd" in Ubuntu

Internet says this one works: 
sudo update-rc.d -f sshd remove

but  it isn't.
It does NOT work.
The following works: 
sudo apt-get remove openssh-server

2012/10/18

Real UID vs Effective UID

If you think about a large company where employees have different levels of access to different locations, you could compare the Real User ID to the name badges people wear, and the Effective User ID to the set of keys they've been given.

2012/10/12

Perl module version

perl -MDateTime -le 'print DateTime->VERSION'

OR:

pmvers DateTime

Perl - read in a whole file at once

use Perl6::Slurp;
my $data = slurp 'path/to/file';

OR

use File::Slurp;
my $text = read_file( 'filename' );
my $lines = read_file( 'filename', array_ref => 1 );
my $lines = read_file( 'filename', array_ref => 1, chomp => 1 );

OR

use File::Slurper;

OR

my $body = do { local( @ARGV, $/ ) = $filename; <> };

OR (if the file is under __DATA__)

my $body = join( '', <DATA> );

Permissions

(not optimised for performance, but does the job):

find . -name '.svn' -prune -o -type d -exec chown www-data:www-data {} \;
-exec chmod 700 {} \; -o -type f -exec chown www-data:www-data {} \; -exec chmod 600 {} \;

List all users

List all users:
awk -F: '{ print $1 }' /etc/passwd

List all members of a group:
awk -F: '/^groupname/ {print $4;}' /etc/group

Where is the package in Ubuntu?

dpkg-query -L package
dpkg -l | grep package

Server in colors

.bashrc:

# PS1='\[\e[1;34m\]\u\[\e[0m\]@\[\e[1;31m\]\h:\[\e[1;32m\]\w\[\e[1;34m\]\njobs:\j\[\e[0m\]\$ '

PS1='\[\e[0;37m\][\[\e[1;94m\]\[\e[1;94m\]\u\[\e[0m\]@\[\e[1;31m\]\H: \[\e[1;32m\]\w\[\e[1;94m\]\[\e[0;37m\]]\n\[\e[0m\]\$ '

Brian's Guide to Solving Any Perl Problem

http://www.perlmonks.org/?node_id=376075

INSERT into SELECT from

insert into TABLE1
(field1, field2, field3, field4)
select 'value1', 'value2', field3, field4
from TABLE1 where field5 = 'value5' limit 1;

Exuberant ctags in FreeBSD

1. install exuberant ctags into "somewhere"
2. point "/home/me/bin/ctags" to "somewhere/ctags.exe"
3. run in vim (add to .vimrc):

:filetype plugin on
map <F1> <esc>:TlistToggle<cr>
:let Tlist_Ctags_Cmd='/home/me/bin/ctags'

4. Install Taglist plugin for Vim.
Debianaptitude install exuberant-ctags
Macbrew install ctags-exuberant

2012/10/09

Citates

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live

Perl will protect its internals from your race conditions, but it won't protect you from you

If you feel the urge to shoot yourself in the foot by using multiple inheritance, Perl is not going to stop you

Perl is a language for getting your job done

P is for Practical