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
# Standard Python | |
try: | |
os.remove('somefile.tmp') | |
except FileNotFoundError: | |
pass | |
# Improved Python | |
import contextlib | |
with contextlib.suppress(FileNotFoundError): | |
os.remove('somefile.tmp') |
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature 'say'; | |
# To extend this to infinity, read: | |
# https://medium.com/cantors-paradise/the-ramanujan-summation-1-2-3-1-12-a8cc23dea793 | |
# For loop |
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature 'say'; | |
sub oops { | |
die "It happened"; | |
} |
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
#!/usr/bin/perl | |
# Converts a gitlog file to a list of edges in an undirected weighted graph | |
# Author: Aron Lurie | |
# Date: 2018-08-15 | |
# Usage: git log --pretty=oneline --name-only | perl git.pl > mylogfile.txt | |
my @files = (); | |
my %adjacent = (); | |
while (<STDIN>) { |
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
{ | |
package Brand; | |
use Moo::Role; | |
has name => ( | |
is => 'rw', | |
lazy => 1, | |
default => sub { die "name is required" } | |
); |
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
./car-03.pl | |
Use of uninitialized value in concatenation (.) or string at ./car-03.pl line 15. | |
This is a nice |
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
{ | |
package Brand; | |
use Moo::Role; | |
has name => ( is => 'rw', required => 1 ); # made rw | |
sub description { "This is a nice ". shift->name } | |
} | |
{ |
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
has name => ( is => 'ro', required => 1 ); | |
# This will die: my $car = Car->new; |
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
> ./car-02.pl | |
This is a nice Peugeot | |
Missing required arguments: name at (eval 12) line 49. |
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
> ./car-01.pl | |
This is a nice Peugeot | |
Use of uninitialized value in concatenation (.) or string at ./car-01.pl line 15. | |
This is a nice |
NewerOlder