Skip to content

Instantly share code, notes, and snippets.

@ynonp
ynonp / case.sh
Created June 3, 2012 09:02
Case bash example
#!/usr/bin/env bash
#
# show
# Hello Mr. Anonymous. You work at UNKNOWN COMPANY
#
# show -name Mike
# Hello Mr. Mike. You work at UNKNOWN COMPANY
#
# show -job Intel
# Hello Mr. Anonymous. You work at Intel
use strict;
use warnings;
package RoleMaker;
use Moose;
use File::Slurp qw/write_file/;
has 'name', is => 'ro', required => 1;
has 'methods' => (
is => 'rw',
@ynonp
ynonp / bashex.md
Created June 28, 2012 08:10
Bash Syntax Exercises

Bash Syntax Exercises

  1. Write a program that reads 10 numbers from the user and prints the largest of them

  2. Write a program that randomizes 7 numbers and prints their sum. If that sum is divisable by 7, it should also print 'Boom !'. (You can use the % operator that means modulus).

  3. Write a program that randomizes a number and calculates the sum total of its digits.

  4. Write a program that reads lines from a user. When input ends, the program should print every other line.

package Pet;
use Moose;
has 'name', is => 'ro', isa => 'Str', default => 'Nemo';
has 'past_owners', is => 'ro', isa => 'ArrayRef[Str]';
package main;
my $dog = Pet->new( past_owners => ['James', 'Mike'] );
package Pet;
use Moose;
has 'name', is => 'ro', isa => 'Str', default => 'Nemo';
has 'past_owners', is => 'ro', isa => 'ArrayRef[Str]';
package main;
my $dog = Pet->new( past_owners => ['James', 'Mike'] );
package Starship;
use Moose;
has 'captain', is => 'ro', isa => 'Str', required => 1;
has 'crew', is => 'rw', isa => 'ArrayRef[Str]', required => 1;
package main;
# Pass a hash ref to prevent copying
my $enterprise = Starship->new( {
package Pet;
use Moose;
has 'name', is => 'ro', isa => 'Str', default => 'Nemo';
has 'past_owners', is => 'ro', isa => 'ArrayRef[Str]';
package main;
my $dog = Pet->new( past_owners => ['James', 'Mike'] );
package Starship;
use Moose;
has 'captain', is => 'ro', isa => 'Str', required => 1;
has 'crew', is => 'rw', isa => 'ArrayRef[Str]', required => 1;
sub BUILD {
my $self = shift;
if ( $self->captain ~~ $self->crew ) {
my $captain = $self->captain;
package Foo;
use Moose;
sub DEMOLISH { warn 'Foo::Demolish' }
sub BUILD { warn 'Foo::Build' }
package Bar;
use Moose;
extends 'Foo';
package MultipleFileUploader;
use Moose::Role;
requires 'upload_file';
sub upload_files {
my $self = shift;
my @success;