Skip to content

Instantly share code, notes, and snippets.

@adamcrussell
adamcrussell / vision_ocr.pl
Created May 11, 2018 18:31
Google Vision API Annotate (OCR) from Perl
use strict;
use warnings;
use JSON;
use MIME::Base64;
use REST::Client;
use constant API_KEY => "KEY TEXT";
use constant URL => "https://vision.googleapis.com/v1/images:annotate?key=";
@adamcrussell
adamcrussell / 1.pl
Created April 2, 2019 17:09
Perl Weekly Challenge 001
use strict;
use warnings;
##
# Challenge #1
# Write a script to replace the character 'e' with 'E' in the string 'Perl Weekly Challenge'.
# Also print the number of times the character 'e' is found in the string.
##
my $challenge_string="Perl Weekly Challenge";
my $number=do{
$challenge_string=~tr/e/E/
@adamcrussell
adamcrussell / ch-1.pl
Last active April 4, 2019 15:08
Challenge-002
use strict;
use warnings;
##
# Write a script or one-liner to remove leading zeros from positive numbers.
##
use constant EXAMPLE => "000123";
print sprintf("%d", EXAMPLE)."\n";
@adamcrussell
adamcrussell / ch-1.pl
Last active April 14, 2019 23:06
Perl Weekly Challenge 003
use strict;
use warnings;
##
# Create a script to generate 5-smooth numbers, whose prime divisors are less or equal to 5.
# They are also called Hamming/Regular/Ugly numbers.
##
use boolean;
sub is_divisible{
my($divisor) = @_;
@adamcrussell
adamcrussell / ch-1.pl
Last active April 16, 2019 21:11
Perl Weekly Challenge 004
use strict;
use warnings;
##
# Write a script to output the same number of PI digits as the size of your script.
# Say, if your script size is 10, it should print 3.141592653.
##
use bignum;
sub pi{
my($max) = @_;
@adamcrussell
adamcrussell / ch-1.pl
Last active April 26, 2019 20:28
Perl Weekly Challenge 005
use strict;
use warnings;
##
# Write a program which prints out all anagrams for a given word.
##
use constant DICTIONARY => "/usr/share/dict/words";
my %word_product;
my %letter_factor = (
e => 2,
t => 3,
@adamcrussell
adamcrussell / fork-own.sh
Last active May 2, 2019 03:31
Fork A GitHub Repo You Own
# the initial clone of the repo we want to "fork"
git clone https://github.com/original
# clone from folder we just got from github to a new location (which will be
# created by this command)
git clone original my-fork
##
# [create new repo for my-fork on githubcom]
##
@adamcrussell
adamcrussell / ch-1.pl
Created May 6, 2019 00:59
Perl Weekly Challenge 006
use strict;
use warnings;
##
# Create a script which takes a list of numbers from command line and print
# the same in the compact form. For example, if you pass "1,2,3,4,9,10,14,15,16" then
# it should print the compact form like “1-4,9,10,14-16”.
##
use Data::Dump q/pp/;
my @a = split(/\,/, $ARGV[0]);
my $a = pp @a;
@adamcrussell
adamcrussell / ch-1.pl
Last active May 12, 2019 14:53
Perl Weekly Challenge 007
use strict;
use warnings;
##
# Print all the niven numbers from 0 to 50 inclusive, each on their own line.
# A niven number is a non-negative number that is divisible by the sum of its digits.
##
use constant NIVEN_COUNT => 50;
my $i = 1;
my $count = 0;
do{
@adamcrussell
adamcrussell / ch-1.pl
Last active May 15, 2019 03:29
Perl Weekly Challenge 008
use strict;
use warnings;
##
# Write a script that computes the first five perfect numbers.
# A perfect number is an integer that is the sum of its positive
# proper divisors (all divisors except itself).
##
use constant PERFECT_COUNT => 5;
sub factor{