From 53a04f3d73bb59473b7edec76802fa4a12060310 Mon Sep 17 00:00:00 2001 From: puskin94 Date: Mon, 23 Feb 2015 19:19:45 +0100 Subject: [PATCH 01/51] Continue Rc4 Encryption --- lib/DDG/Goodie/Rc4.pm | 66 +++++++++++++++++++++++++++++++++++++++++++ t/Rc4.t | 32 +++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 lib/DDG/Goodie/Rc4.pm create mode 100644 t/Rc4.t diff --git a/lib/DDG/Goodie/Rc4.pm b/lib/DDG/Goodie/Rc4.pm new file mode 100644 index 000000000..5a1e8f0b4 --- /dev/null +++ b/lib/DDG/Goodie/Rc4.pm @@ -0,0 +1,66 @@ +package DDG::Goodie::Rc4; +# ABSTRACT: This goddie provides a simple encription/decryption service +# using RC4 algorithm and a key provided by the user. + +use DDG::Goodie; +use strict; +use warnings; +use Crypt::RC4; +use MIME::Base64; + +zci answer_type => "rc4"; +zci is_cached => 1; + +name "DDG::Goodie::Rc4.pm"; +description "Encrypt or decrypt a text using a key provided by the user"; +primary_example_queries "crypto encrypt key string", "crypto decrypt key string"; +secondary_example_queries "crypto en key string", "crypto de key string"; +category "computing_tools"; +topics "cryptography"; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Rc4.pm"; +attribution github => ["https://github.com/puskin94", "puskin94"], + github => ["diegojuan", "JD"], + web => "sysadminjd.com"; + +# Triggers +triggers startend => "rc4"; + +# Handle statement + +handle remainder => sub { + + (my $type, my $key, my $plaintext) = split / /; + + return unless $type && $key && $plaintext; + + if ($type eq "encrypt" || $type eq "en" || $type eq "enc") { + # To encrypt we receive the plaintext as is and pass it to the RC4 function. + my $encrypted = RC4($key, $plaintext); + # To avoid problems with non printable characters, we transform the result using encode_base64() + my $result = encode_base64($encrypted); + chomp $result; + + return $result, + structured_answer => { + input => [], + operation => "Rc4 Encryption", + result => $result + }; + + } elsif ($type eq "decrypt" || $type eq "de" || $type eq "dec") { + #To decrypt we do the reverse process, we take the plaintext, transform it using decode_base64() + my $decoded = decode_base64($plaintext); + # Then we pass it to the RC4 funcion to be decrypted. + my $result = RC4($key, $decoded); + # No need to encode again, this result is show as is. + return $result, + structured_answer => { + input => [], + operation => "Rc4 Decryption", + result => $result + }; + } + +}; + +1; diff --git a/t/Rc4.t b/t/Rc4.t new file mode 100644 index 000000000..5a71a0e90 --- /dev/null +++ b/t/Rc4.t @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => "rc4"; +zci is_cached => 1; + +ddg_goodie_test( + [qw( + DDG::Goodie::Rc4 + )], + 'rc4 en mysecretkey hello' => test_zci("grYU1K8=", + structured_answer => { + input => [], + operation => "Rc4 Encryption", + result => "grYU1K8=" + }), + 'rc4 de duck yWrJniG/nNg=' => test_zci("DdgRocks", + structured_answer => { + input => [], + operation => "Rc4 Decryption", + result => "DdgRocks" + }), + 'rc4 ' => undef, + 'rc4 enc missing' => undef, + 'rc4 no operation' => undef +); + +done_testing; \ No newline at end of file From 201881df2f664619ef7fb5daf81916644f93861c Mon Sep 17 00:00:00 2001 From: puskin94 Date: Mon, 23 Feb 2015 19:26:31 +0100 Subject: [PATCH 02/51] little fix --- t/Rc4.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/Rc4.t b/t/Rc4.t index 5a71a0e90..9ee71083a 100644 --- a/t/Rc4.t +++ b/t/Rc4.t @@ -29,4 +29,4 @@ ddg_goodie_test( 'rc4 no operation' => undef ); -done_testing; \ No newline at end of file +done_testing; From 29590ee594ac66963ef5945d835609d13f0a0827 Mon Sep 17 00:00:00 2001 From: puskin94 Date: Mon, 23 Feb 2015 21:15:17 +0100 Subject: [PATCH 03/51] fixed code --- lib/DDG/Goodie/Rc4.pm | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/DDG/Goodie/Rc4.pm b/lib/DDG/Goodie/Rc4.pm index 5a1e8f0b4..952c8b946 100644 --- a/lib/DDG/Goodie/Rc4.pm +++ b/lib/DDG/Goodie/Rc4.pm @@ -30,6 +30,8 @@ triggers startend => "rc4"; handle remainder => sub { (my $type, my $key, my $plaintext) = split / /; + my $operation; + my $result; return unless $type && $key && $plaintext; @@ -37,30 +39,26 @@ handle remainder => sub { # To encrypt we receive the plaintext as is and pass it to the RC4 function. my $encrypted = RC4($key, $plaintext); # To avoid problems with non printable characters, we transform the result using encode_base64() - my $result = encode_base64($encrypted); + $result = encode_base64($encrypted); chomp $result; - - return $result, - structured_answer => { - input => [], - operation => "Rc4 Encryption", - result => $result - }; + $operation = "Rc4 Encryption"; } elsif ($type eq "decrypt" || $type eq "de" || $type eq "dec") { #To decrypt we do the reverse process, we take the plaintext, transform it using decode_base64() my $decoded = decode_base64($plaintext); # Then we pass it to the RC4 funcion to be decrypted. - my $result = RC4($key, $decoded); + $result = RC4($key, $decoded); # No need to encode again, this result is show as is. - return $result, - structured_answer => { - input => [], - operation => "Rc4 Decryption", - result => $result - }; + $operation = "Rc4 Decryption"; } + return $result, + structured_answer => { + input => [], + operation => $operation, + result => $result + }; + }; 1; From f72a49a1d147a657f4f94e9fff73fd84fa01423d Mon Sep 17 00:00:00 2001 From: puskin94 Date: Mon, 23 Feb 2015 21:16:37 +0100 Subject: [PATCH 04/51] if statement --- lib/DDG/Goodie/Rc4.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/Rc4.pm b/lib/DDG/Goodie/Rc4.pm index 952c8b946..538e651bb 100644 --- a/lib/DDG/Goodie/Rc4.pm +++ b/lib/DDG/Goodie/Rc4.pm @@ -43,7 +43,8 @@ handle remainder => sub { chomp $result; $operation = "Rc4 Encryption"; - } elsif ($type eq "decrypt" || $type eq "de" || $type eq "dec") { + } + if ($type eq "decrypt" || $type eq "de" || $type eq "dec") { #To decrypt we do the reverse process, we take the plaintext, transform it using decode_base64() my $decoded = decode_base64($plaintext); # Then we pass it to the RC4 funcion to be decrypted. From f29f4e6a57d04a43f88767b27e29010154a5a809 Mon Sep 17 00:00:00 2001 From: Zach Thompson Date: Mon, 23 Feb 2015 19:35:37 -0500 Subject: [PATCH 05/51] DDG::Goodie::CheatSheets: Load cheat sheets from YAML files --- lib/DDG/Goodie/CheatSheets.pm | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/DDG/Goodie/CheatSheets.pm diff --git a/lib/DDG/Goodie/CheatSheets.pm b/lib/DDG/Goodie/CheatSheets.pm new file mode 100644 index 000000000..e302506ec --- /dev/null +++ b/lib/DDG/Goodie/CheatSheets.pm @@ -0,0 +1,42 @@ +package DDG::Goodie::CheatSheets; +# ABSTRACT: Load basic cheat sheets from YAML files + +use YAML::XS 'LoadFile'; +use DDG::Goodie; + +zci answer_type => 'cheat_sheet'; +zci is_cached => 1; + +name 'CheatSheet'; +description 'Cheat sheets'; +code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/CheatSheets.pm'; +category 'cheat_sheets'; +topics qw'computing geek programming sysadmin'; + +primary_example_queries 'help', 'cheat sheet', 'example'; + +triggers startend => ( + 'cheat sheet', + 'cheatsheet', + 'guide', + 'help', + 'quick reference', + 'reference', + 'example', + 'examples', + 'example', + 'examples' +); + +attribution github => [zachthompson => 'Zach Thompson']; + +handle remainder => sub { + # If needed we could jump through a few more hoops to check + # terms against file names. + my $yml_path = share(join('-', split /\s+/o, lc($_) . '.yml'); + my $yml; + eval { $yml = LoadFile($yml_path) } or do { return }; + return structured_answer => $yml; +}; + +1; From 4ef94b3c71bb1c3fee18028a73bd2a03fad858fb Mon Sep 17 00:00:00 2001 From: puskin94 Date: Tue, 24 Feb 2015 08:54:43 +0100 Subject: [PATCH 06/51] mod and add dist.ini --- lib/DDG/Goodie/Rc4.pm | 7 +- share/goodie/rc4/dist.ini | 141 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 share/goodie/rc4/dist.ini diff --git a/lib/DDG/Goodie/Rc4.pm b/lib/DDG/Goodie/Rc4.pm index 538e651bb..579f608f4 100644 --- a/lib/DDG/Goodie/Rc4.pm +++ b/lib/DDG/Goodie/Rc4.pm @@ -35,7 +35,7 @@ handle remainder => sub { return unless $type && $key && $plaintext; - if ($type eq "encrypt" || $type eq "en" || $type eq "enc") { + if ($type =~ m/en(c|crypt)?/) { # To encrypt we receive the plaintext as is and pass it to the RC4 function. my $encrypted = RC4($key, $plaintext); # To avoid problems with non printable characters, we transform the result using encode_base64() @@ -43,14 +43,15 @@ handle remainder => sub { chomp $result; $operation = "Rc4 Encryption"; - } - if ($type eq "decrypt" || $type eq "de" || $type eq "dec") { + } elsif ($type =~ m/de(c|crypt)?/) { #To decrypt we do the reverse process, we take the plaintext, transform it using decode_base64() my $decoded = decode_base64($plaintext); # Then we pass it to the RC4 funcion to be decrypted. $result = RC4($key, $decoded); # No need to encode again, this result is show as is. $operation = "Rc4 Decryption"; + } else { + return; } return $result, diff --git a/share/goodie/rc4/dist.ini b/share/goodie/rc4/dist.ini new file mode 100644 index 000000000..4471a41d3 --- /dev/null +++ b/share/goodie/rc4/dist.ini @@ -0,0 +1,141 @@ +name = DDG-GoodieBundle-OpenSourceDuckDuckGo +author = Gabriel Weinberg +author = Torsten Raudssus +author = Michael Smith +author = Hunter Lang +license = Apache_2_0 +copyright_holder = DuckDuckGo, Inc. L +copyright_year = 2013 + +[PromptIfStale] +index = http://duckpan.org +module = Dist::Zilla::Plugin::UploadToDuckPAN + +[Prereqs] +Time::Duration = 1.1 +MIME::Base64 = 3.13 +MIME::Types = 0 +Roman = 1.23 +Fortune = 0.2 +Math::Int2Base = 1.00 +Data::GUID = 0.046 +IO::All = 0.44 +File::ShareDir::ProjectDistDir = 0.2.0 +Text::FIGlet = 2.19.3 +Text::Unidecode = 0.04 +Date::Calc = 6.3 +Date::Hijri = 0.02 +Date::Jalali2 = 0.04 +Date::Leapyear = 1.72 +; Dates role, et. al. +DateTime = 0.74 +DateTime::Format::HTTP = 0 +Devel::StackTrace = 0 +Package::Stash = 0 +Try::Tiny = 0 +Lingua::EN::Numericalize = 1.52 +Lingua::PigLatin = 0.01 +Locale::SubCountry = 1.47 +; causing problems because not pp: HTML::Barcode::QRCode = 0.09 +Unicode::Char = 0.02 +Number::UN = 0.002 +Locale::Codes = 3.30 +Gravatar::URL = 1.06 +CGI = 3.60 +Email::Valid = 1.192 +Net::Domain::TLD = 1.70 +Convert::Pluggable = 0.026 +YAML = 0 +Encode = 2.62 +; ParseCron +Schedule::Cron::Events = 0 +; ColorCodes +Color::Library = 0 +Convert::Color = 0.08 +Convert::Color::Library = 0.03 +Convert::Braille = 0.05 +Math::Round = 0.06 +Convert::Morse = 0.05 +Net::IDN::Encode = 2.003 +Astro::MoonPhase = 0 +Acme::rafl::Everywhere = 0.008 +Lingua::EN::Numbers::Ordinate = 1.02 +; Hashes +Digest::SHA = 5.82 +Digest::MD5 = 2.53 +; Factors +Math::Prime::Util = 0.43 +Games::Sudoku::Component = 0.02 +Data::RandomPerson = 0.4 +Lingua::EN::Words2Nums = 0 +Locale::Currency::Format = 1.30 +Net::IP = 0 +Math::BaseConvert = 0 +Telephony::CountryDialingCodes = 1.04 +URI::Escape::XS = 0.12 +DateTime::Calendar::Chinese = 1.00 +DateTime::Event::Chinese = 1.00 +DateTime::Event::Sunrise = 0 +Geo::Coordinates::DecimalDegrees = 0.09 +Math::SigFigs = 1.09 +Bit::Vector = 7.3 +List::MoreUtils = 0 +; FlipText +Text::UpsideDown = 1.22 +; Parser BinaryLogic +Marpa::R2 = 0 +; For pre-fetch Goodies only. +LWP::Simple = 0 +Business::CUSIP = 1.03 +; Added for SimpleEncryptionService +Crypt::RC4 + +[Prereqs / TestRequires] +Test::EOL = 0 +Test::MockTime = 0 +Test::More = 0.98 +Test::Most = 0 +Test::Dirs = 0.03 +File::Temp = 0.22 + +[GatherDir] +[PruneCruft] +[ManifestSkip] +[ExtraTests] +[ExecDir] +[ShareDir] +[MakeMaker] +[Manifest] +[TestRelease] +[ConfirmRelease] +[UploadToDuckPAN] +[MetaJSON] +[MetaYAML] + +[AutoModuleShareDirs] +scan_namespaces = DDG::Goodie,DDG::Spice +sharedir_method = module_share_dir + +[Git::NextVersion] +version_regexp = ^(.+)$ +[PkgVersion] +[PodSyntaxTests] +[GithubMeta] +[Test::EOL] +trailing_whitespace = 0 +[@Git] +tag_format = %v + +[PodWeaver] + +[Git::Push] +push_to = origin master + +[TravisCI] +perl_version = 5.16 +perl_version = 5.18 +extra_dep = App::DuckPAN +extra_dep = autodie +after_install = duckpan DDG +before_install = sudo apt-get update -qq +before_install = sudo apt-get install -y libmpfr-dev From c4b178b90a321e2f114b21815ae45b179cc7b3de Mon Sep 17 00:00:00 2001 From: puskin94 Date: Tue, 24 Feb 2015 10:45:02 +0100 Subject: [PATCH 07/51] travis failed... dist.ini error... fixed? Idk --- share/goodie/rc4/dist.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/goodie/rc4/dist.ini b/share/goodie/rc4/dist.ini index 4471a41d3..6f07f7614 100644 --- a/share/goodie/rc4/dist.ini +++ b/share/goodie/rc4/dist.ini @@ -88,7 +88,7 @@ Marpa::R2 = 0 LWP::Simple = 0 Business::CUSIP = 1.03 ; Added for SimpleEncryptionService -Crypt::RC4 +Goodie::Rc4 [Prereqs / TestRequires] Test::EOL = 0 From d704cec23c7509d37c9721490efb32a8d0b4b9a4 Mon Sep 17 00:00:00 2001 From: puskin94 Date: Tue, 24 Feb 2015 11:08:45 +0100 Subject: [PATCH 08/51] last try... moollaza help me --- share/goodie/rc4/dist.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/goodie/rc4/dist.ini b/share/goodie/rc4/dist.ini index 6f07f7614..505e4307b 100644 --- a/share/goodie/rc4/dist.ini +++ b/share/goodie/rc4/dist.ini @@ -88,7 +88,7 @@ Marpa::R2 = 0 LWP::Simple = 0 Business::CUSIP = 1.03 ; Added for SimpleEncryptionService -Goodie::Rc4 +; Goodie::Rc4 [Prereqs / TestRequires] Test::EOL = 0 From f1f28c684f5bd3210789f644b6b30f96646eec16 Mon Sep 17 00:00:00 2001 From: puskin94 Date: Tue, 24 Feb 2015 18:17:21 +0100 Subject: [PATCH 09/51] oooh I understand dist.ini now --- dist.ini | 3 + share/goodie/rc4/dist.ini | 141 -------------------------------------- 2 files changed, 3 insertions(+), 141 deletions(-) delete mode 100644 share/goodie/rc4/dist.ini diff --git a/dist.ini b/dist.ini index 814c99be3..417a52cbd 100644 --- a/dist.ini +++ b/dist.ini @@ -91,6 +91,9 @@ Marpa::R2 = 0 LWP::Simple = 0 Business::CUSIP = 1.03 Lingua::Any::Numbers = 0 +; For Rc4 +Crypt::RC4 = 2.02 +MIME::Base64 = 3.15 [Prereqs / TestRequires] Test::EOL = 0 diff --git a/share/goodie/rc4/dist.ini b/share/goodie/rc4/dist.ini deleted file mode 100644 index 505e4307b..000000000 --- a/share/goodie/rc4/dist.ini +++ /dev/null @@ -1,141 +0,0 @@ -name = DDG-GoodieBundle-OpenSourceDuckDuckGo -author = Gabriel Weinberg -author = Torsten Raudssus -author = Michael Smith -author = Hunter Lang -license = Apache_2_0 -copyright_holder = DuckDuckGo, Inc. L -copyright_year = 2013 - -[PromptIfStale] -index = http://duckpan.org -module = Dist::Zilla::Plugin::UploadToDuckPAN - -[Prereqs] -Time::Duration = 1.1 -MIME::Base64 = 3.13 -MIME::Types = 0 -Roman = 1.23 -Fortune = 0.2 -Math::Int2Base = 1.00 -Data::GUID = 0.046 -IO::All = 0.44 -File::ShareDir::ProjectDistDir = 0.2.0 -Text::FIGlet = 2.19.3 -Text::Unidecode = 0.04 -Date::Calc = 6.3 -Date::Hijri = 0.02 -Date::Jalali2 = 0.04 -Date::Leapyear = 1.72 -; Dates role, et. al. -DateTime = 0.74 -DateTime::Format::HTTP = 0 -Devel::StackTrace = 0 -Package::Stash = 0 -Try::Tiny = 0 -Lingua::EN::Numericalize = 1.52 -Lingua::PigLatin = 0.01 -Locale::SubCountry = 1.47 -; causing problems because not pp: HTML::Barcode::QRCode = 0.09 -Unicode::Char = 0.02 -Number::UN = 0.002 -Locale::Codes = 3.30 -Gravatar::URL = 1.06 -CGI = 3.60 -Email::Valid = 1.192 -Net::Domain::TLD = 1.70 -Convert::Pluggable = 0.026 -YAML = 0 -Encode = 2.62 -; ParseCron -Schedule::Cron::Events = 0 -; ColorCodes -Color::Library = 0 -Convert::Color = 0.08 -Convert::Color::Library = 0.03 -Convert::Braille = 0.05 -Math::Round = 0.06 -Convert::Morse = 0.05 -Net::IDN::Encode = 2.003 -Astro::MoonPhase = 0 -Acme::rafl::Everywhere = 0.008 -Lingua::EN::Numbers::Ordinate = 1.02 -; Hashes -Digest::SHA = 5.82 -Digest::MD5 = 2.53 -; Factors -Math::Prime::Util = 0.43 -Games::Sudoku::Component = 0.02 -Data::RandomPerson = 0.4 -Lingua::EN::Words2Nums = 0 -Locale::Currency::Format = 1.30 -Net::IP = 0 -Math::BaseConvert = 0 -Telephony::CountryDialingCodes = 1.04 -URI::Escape::XS = 0.12 -DateTime::Calendar::Chinese = 1.00 -DateTime::Event::Chinese = 1.00 -DateTime::Event::Sunrise = 0 -Geo::Coordinates::DecimalDegrees = 0.09 -Math::SigFigs = 1.09 -Bit::Vector = 7.3 -List::MoreUtils = 0 -; FlipText -Text::UpsideDown = 1.22 -; Parser BinaryLogic -Marpa::R2 = 0 -; For pre-fetch Goodies only. -LWP::Simple = 0 -Business::CUSIP = 1.03 -; Added for SimpleEncryptionService -; Goodie::Rc4 - -[Prereqs / TestRequires] -Test::EOL = 0 -Test::MockTime = 0 -Test::More = 0.98 -Test::Most = 0 -Test::Dirs = 0.03 -File::Temp = 0.22 - -[GatherDir] -[PruneCruft] -[ManifestSkip] -[ExtraTests] -[ExecDir] -[ShareDir] -[MakeMaker] -[Manifest] -[TestRelease] -[ConfirmRelease] -[UploadToDuckPAN] -[MetaJSON] -[MetaYAML] - -[AutoModuleShareDirs] -scan_namespaces = DDG::Goodie,DDG::Spice -sharedir_method = module_share_dir - -[Git::NextVersion] -version_regexp = ^(.+)$ -[PkgVersion] -[PodSyntaxTests] -[GithubMeta] -[Test::EOL] -trailing_whitespace = 0 -[@Git] -tag_format = %v - -[PodWeaver] - -[Git::Push] -push_to = origin master - -[TravisCI] -perl_version = 5.16 -perl_version = 5.18 -extra_dep = App::DuckPAN -extra_dep = autodie -after_install = duckpan DDG -before_install = sudo apt-get update -qq -before_install = sudo apt-get install -y libmpfr-dev From 2be1b0d5b81e91e4d7ef3482ba0f64e52db8c361 Mon Sep 17 00:00:00 2001 From: puskin94 Date: Tue, 24 Feb 2015 21:16:51 +0100 Subject: [PATCH 10/51] removed MIME duplicate --- dist.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/dist.ini b/dist.ini index 417a52cbd..eea34a2a5 100644 --- a/dist.ini +++ b/dist.ini @@ -93,7 +93,6 @@ Business::CUSIP = 1.03 Lingua::Any::Numbers = 0 ; For Rc4 Crypt::RC4 = 2.02 -MIME::Base64 = 3.15 [Prereqs / TestRequires] Test::EOL = 0 From b047aacaf3fb164d40eb2b0720a19ad7bbe2e4ef Mon Sep 17 00:00:00 2001 From: Zach Thompson Date: Wed, 25 Feb 2015 16:35:35 -0500 Subject: [PATCH 11/51] DDG::Goodie::CheatSheets: Update to use JSON --- lib/DDG/Goodie/CheatSheets.pm | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/DDG/Goodie/CheatSheets.pm b/lib/DDG/Goodie/CheatSheets.pm index e302506ec..0b0cb0431 100644 --- a/lib/DDG/Goodie/CheatSheets.pm +++ b/lib/DDG/Goodie/CheatSheets.pm @@ -1,7 +1,6 @@ package DDG::Goodie::CheatSheets; # ABSTRACT: Load basic cheat sheets from YAML files -use YAML::XS 'LoadFile'; use DDG::Goodie; zci answer_type => 'cheat_sheet'; @@ -24,8 +23,6 @@ triggers startend => ( 'reference', 'example', 'examples', - 'example', - 'examples' ); attribution github => [zachthompson => 'Zach Thompson']; @@ -33,10 +30,22 @@ attribution github => [zachthompson => 'Zach Thompson']; handle remainder => sub { # If needed we could jump through a few more hoops to check # terms against file names. - my $yml_path = share(join('-', split /\s+/o, lc($_) . '.yml'); - my $yml; + my $json_path = share(join('-', split /\s+/o, lc($_) . '.yml'); + open my $fh, $json_path or return; + my $json = do { local $/; <$fh> }; eval { $yml = LoadFile($yml_path) } or do { return }; - return structured_answer => $yml; + return structured_answer => { + id => 'cheat_sheets', + name => 'Cheat Sheet', + data => $json, + templates => { + group => 'base', + options => { + content => 'DDH.cheat_sheets.content', + moreAt => true + } + } + }; }; 1; From 4af73204b7d6f6530055cb08de7e93c2bf255b8b Mon Sep 17 00:00:00 2001 From: Zach Thompson Date: Wed, 25 Feb 2015 21:27:24 -0500 Subject: [PATCH 12/51] DDG::Goodie::CheatSheets: Remove yaml vestiges; decode JSON so it's not double encoded content.handlebars, vimng.json: These are for testing (others may need to use) --- lib/DDG/Goodie/CheatSheets.pm | 9 +++++---- share/goodie/cheat_sheets/content.handlebars | 15 +++++++++++++++ share/goodie/cheat_sheets/vimng.json | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 share/goodie/cheat_sheets/content.handlebars create mode 100644 share/goodie/cheat_sheets/vimng.json diff --git a/lib/DDG/Goodie/CheatSheets.pm b/lib/DDG/Goodie/CheatSheets.pm index 0b0cb0431..c9e469191 100644 --- a/lib/DDG/Goodie/CheatSheets.pm +++ b/lib/DDG/Goodie/CheatSheets.pm @@ -1,6 +1,7 @@ package DDG::Goodie::CheatSheets; -# ABSTRACT: Load basic cheat sheets from YAML files +# ABSTRACT: Load basic cheat sheets from JSON files +use JSON::XS; use DDG::Goodie; zci answer_type => 'cheat_sheet'; @@ -30,11 +31,11 @@ attribution github => [zachthompson => 'Zach Thompson']; handle remainder => sub { # If needed we could jump through a few more hoops to check # terms against file names. - my $json_path = share(join('-', split /\s+/o, lc($_) . '.yml'); + my $json_path = share(join('-', split /\s+/o, lc($_) . '.json')); open my $fh, $json_path or return; my $json = do { local $/; <$fh> }; - eval { $yml = LoadFile($yml_path) } or do { return }; - return structured_answer => { + my $data = decode_json($json); + return 'Vim Cheat Sheet', structured_answer => { id => 'cheat_sheets', name => 'Cheat Sheet', data => $json, diff --git a/share/goodie/cheat_sheets/content.handlebars b/share/goodie/cheat_sheets/content.handlebars new file mode 100644 index 000000000..4f26b2078 --- /dev/null +++ b/share/goodie/cheat_sheets/content.handlebars @@ -0,0 +1,15 @@ +
+{{#each section_order}} +

{{this}}

+ {{#withItem ../sections key=this}} + + {{#table-each this}} + + + + + {{/table-each}} +
{{key}}:{{ellipsis val 350}}
+ {{/withItem}} +{{/each}} +
diff --git a/share/goodie/cheat_sheets/vimng.json b/share/goodie/cheat_sheets/vimng.json new file mode 100644 index 000000000..bb27abdca --- /dev/null +++ b/share/goodie/cheat_sheets/vimng.json @@ -0,0 +1 @@ +{"name":"Vim","section_order":["Cursor movement","Insert mode - inserting/appending text","Editing","Marking text (visual mode)","Visual commands","Cut and paste","Exiting","Search and replace","Working with multiple files","Tabs"],"sections":{"Tabs":[{"val":"open a file in a new tab","key":":tabnew filename, :tabn filename"},{"val":"move the current split window into its own tab","key":"Ctrl+wt"},{"val":"move to the next tab","key":"gt, :tabnext, :tabn"},{"val":"move to the previous tab","key":"gT, :tabprev, :tabp"},{"val":"move to tab number #","key":"#gt"},{"val":"move current tab to the #th position (indexed from 0)","key":":tabmove #"},{"val":"close the current tab and all its windows","key":":tabclose/:tabc"},{"val":"close all tabs except for the current one","key":":tabonly/:tabo"}],"Editing":[{"val":"replace a single character","key":"r"},{"val":"join line below to the current one","key":"J"},{"val":"change (replace) entire line","key":"cc"},{"val":"change (replace) to the end of the word","key":"cw"},{"val":"change (replace) to the end of the line","key":"c$"},{"val":"delete character and substitute text","key":"s"},{"val":"delete line and substitute text (same as cc)","key":"S"},{"val":"transpose two letters (delete and paste)","key":"xp"},{"val":"undo","key":"u"},{"val":"redo","key":"Ctrl+r"},{"val":"repeat last command","key":"."}],"Exiting":[{"val":"write (save) the file, but don't exit","key":":w"},{"val":"write (save) and quit","key":":wq"},{"val":"write (save) and quit","key":":x"},{"val":"quit (fails if there are unsaved changes)","key":":q"},{"val":"quit and throw away unsaved changes","key":":q!"}],"Insert mode - inserting/appending text":[{"val":"insert before the cursor","key":"i"},{"val":"insert at the beginning of the line","key":"I"},{"val":"insert (append) after the cursor","key":"a"},{"val":"insert (append) at the end of the line","key":"A"},{"val":"append (open) a new line below the current line","key":"o"},{"val":"append (open) a new line above the current line","key":"O"},{"val":"insert (append) at the end of the word","key":"ea"},{"val":"exit insert mode","key":"Esc"}],"Cut and paste":[{"val":"yank (copy) a line","key":"yy"},{"val":"yank (copy) 2 lines","key":"2yy"},{"val":"yank (copy) word","key":"yw"},{"val":"yank (copy) to end of line","key":"y$"},{"val":"put (paste) the clipboard after cursor","key":"p"},{"val":"put (paste) before cursor","key":"P"},{"val":"delete (cut) a line","key":"dd"},{"val":"delete (cut) 2 lines","key":"2dd"},{"val":"delete (cut) word","key":"dw"},{"val":"delete (cut) to the end of the line","key":"D"},{"val":"delete (cut) to the end of the line","key":"d$"},{"val":"delete (cut) character","key":"x"}],"Marking text (visual mode)":[{"val":"start visual mode, mark lines, then do a command (like y-yank)","key":"v"},{"val":"start linewise visual mode","key":"V"},{"val":"move to other end of marked area","key":"o"},{"val":"start visual block mode","key":"Ctrl+v"},{"val":"move to other corner of block","key":"O"},{"val":"mark a word","key":"aw"},{"val":"a block with ()","key":"ab"},{"val":"a block with {}","key":"aB"},{"val":"inner block with ()","key":"ib"},{"val":"inner block with {}","key":"iB"},{"val":"exit visual mode","key":"Esc"}],"Working with multiple files":[{"val":"edit a file in a new buffer","key":":e filename"},{"val":"go to the next buffer","key":":bnext/:bn"},{"val":"go to the previous buffer","key":":bprev/:bp"},{"val":"delete a buffer (close a file)","key":":bd"},{"val":"open a file in a new buffer and split window","key":":sp filename"},{"val":"open a file in a new buffer and vertically split window","key":":vsp filename"},{"val":"split window","key":"Ctrl+ws"},{"val":"switch windows","key":"Ctrl+ww"},{"val":"quit a window","key":"Ctrl+wq"},{"val":"split window vertically","key":"Ctrl+wv"},{"val":"move cursor to next buffer (right)","key":"Ctrl+wh"},{"val":"move cursor to previous buffer (left)","key":"Ctrl+wl"}],"Cursor movement":[{"val":"move cursor left","key":"h"},{"val":"move cursor down","key":"j"},{"val":"move cursor up","key":"k"},{"val":"move cursor right","key":"l"},{"val":"jump forwards to the start of a word","key":"w"},{"val":"jump forwards to the start of a word (words can contain punctuation)","key":"W"},{"val":"jump forwards to the end of a word","key":"e"},{"val":"jump forwards to the end of a word (words can contain punctuation)","key":"E"},{"val":"jump backwards to the start of a word","key":"b"},{"val":"jump backwards to the start of a word (words can contain punctuation)","key":"B"},{"val":"jump to the start of the line","key":"0"},{"val":"jump to the first non-blank character of the line","key":"^"},{"val":"jump to the end of the line","key":"$"},{"val":"go to the last line of the document","key":"G"},{"val":"go to line 5","key":"5G"},{"val":"To the position before the latest jump, or where the last \"m'\" or \"m`\" command was given.","key":"''"}],"Visual commands":[{"val":"shift text right","key":">"},{"val":"shift text left","key":"<"},{"val":"yank (copy) marked text","key":"y"},{"val":"delete marked text","key":"d"},{"val":"switch case","key":"~"}],"Search and replace":[{"val":"search for pattern","key":"/pattern"},{"val":"search backward for pattern","key":"?pattern"},{"val":"repeat search in same direction","key":"n"},{"val":"repeat search in opposite direction","key":"N"},{"val":"replace all old with new throughout file","key":":%s/old/new/g"},{"val":"replace all old with new throughout file with confirmations","key":":%s/old/new/gc"}]},"description":"Text Editor"} \ No newline at end of file From 67571f2b087fe59fd73c1a07a3f1f98a1427d441 Mon Sep 17 00:00:00 2001 From: Zach Thompson Date: Wed, 25 Feb 2015 21:31:58 -0500 Subject: [PATCH 13/51] cheat_sheets.js: Helper for indexing into JSON data structure --- share/goodie/cheat_sheets/cheat_sheets.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 share/goodie/cheat_sheets/cheat_sheets.js diff --git a/share/goodie/cheat_sheets/cheat_sheets.js b/share/goodie/cheat_sheets/cheat_sheets.js new file mode 100644 index 000000000..2dfc3c543 --- /dev/null +++ b/share/goodie/cheat_sheets/cheat_sheets.js @@ -0,0 +1,3 @@ +Handlebars.registerHelper('withItem', function(object, options) { + return options.fn(object[options.hash.key]); +}); From 161a579081c2480155afff20566f7d2533a8216e Mon Sep 17 00:00:00 2001 From: puskin94 Date: Thu, 26 Feb 2015 08:53:03 +0100 Subject: [PATCH 14/51] different changes about structured answer --- lib/DDG/Goodie/Rc4.pm | 18 +++++++++--------- t/Rc4.t | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/DDG/Goodie/Rc4.pm b/lib/DDG/Goodie/Rc4.pm index 579f608f4..0709d2638 100644 --- a/lib/DDG/Goodie/Rc4.pm +++ b/lib/DDG/Goodie/Rc4.pm @@ -11,7 +11,7 @@ use MIME::Base64; zci answer_type => "rc4"; zci is_cached => 1; -name "DDG::Goodie::Rc4.pm"; +name "DDG::Goodie::RC4.pm"; description "Encrypt or decrypt a text using a key provided by the user"; primary_example_queries "crypto encrypt key string", "crypto decrypt key string"; secondary_example_queries "crypto en key string", "crypto de key string"; @@ -35,30 +35,30 @@ handle remainder => sub { return unless $type && $key && $plaintext; - if ($type =~ m/en(c|crypt)?/) { + if ($type =~ m/^en(c|crypt)?$/) { # To encrypt we receive the plaintext as is and pass it to the RC4 function. my $encrypted = RC4($key, $plaintext); # To avoid problems with non printable characters, we transform the result using encode_base64() $result = encode_base64($encrypted); chomp $result; - $operation = "Rc4 Encryption"; + $operation = "Rc4 Encrypt"; - } elsif ($type =~ m/de(c|crypt)?/) { + } elsif ($type =~ m/^de(c|crypt)?$/) { #To decrypt we do the reverse process, we take the plaintext, transform it using decode_base64() my $decoded = decode_base64($plaintext); # Then we pass it to the RC4 funcion to be decrypted. $result = RC4($key, $decoded); # No need to encode again, this result is show as is. - $operation = "Rc4 Decryption"; + $operation = "Rc4 Decrypt"; } else { return; } - return $result, - structured_answer => { - input => [], + return "$operation: $plaintext, with key: $key is $result", + structured_answer => { operation => $operation, - result => $result + input => [html_enc($plaintext) . ", Key: $key"], + result => $result }; }; diff --git a/t/Rc4.t b/t/Rc4.t index 9ee71083a..dbebda086 100644 --- a/t/Rc4.t +++ b/t/Rc4.t @@ -12,16 +12,16 @@ ddg_goodie_test( [qw( DDG::Goodie::Rc4 )], - 'rc4 en mysecretkey hello' => test_zci("grYU1K8=", + 'rc4 en mysecretkey hello' => test_zci("Rc4 Encrypt: hello, with key: mysecretkey is grYU1K8=", structured_answer => { - input => [], - operation => "Rc4 Encryption", + input => ['hello, Key: mysecretkey'], + operation => "Rc4 Encrypt", result => "grYU1K8=" }), - 'rc4 de duck yWrJniG/nNg=' => test_zci("DdgRocks", + 'rc4 de duck yWrJniG/nNg=' => test_zci("Rc4 Decrypt: yWrJniG/nNg=, with key: duck is DdgRocks", structured_answer => { - input => [], - operation => "Rc4 Decryption", + input => ['yWrJniG/nNg=, Key: duck'], + operation => "Rc4 Decrypt", result => "DdgRocks" }), 'rc4 ' => undef, From 4ad212aebb296e01db1b475ea31268872a8cebe0 Mon Sep 17 00:00:00 2001 From: puskin94 Date: Thu, 26 Feb 2015 18:20:13 +0100 Subject: [PATCH 15/51] change name --- lib/DDG/Goodie/Rc4.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/Rc4.pm b/lib/DDG/Goodie/Rc4.pm index 0709d2638..981033e1b 100644 --- a/lib/DDG/Goodie/Rc4.pm +++ b/lib/DDG/Goodie/Rc4.pm @@ -11,7 +11,7 @@ use MIME::Base64; zci answer_type => "rc4"; zci is_cached => 1; -name "DDG::Goodie::RC4.pm"; +name "RC4.pm"; description "Encrypt or decrypt a text using a key provided by the user"; primary_example_queries "crypto encrypt key string", "crypto decrypt key string"; secondary_example_queries "crypto en key string", "crypto de key string"; From ae8d086ab41d6009d94744e58e5cba01beb260cd Mon Sep 17 00:00:00 2001 From: Zach Thompson Date: Thu, 26 Feb 2015 19:02:57 -0500 Subject: [PATCH 16/51] DDG::Goodie::CheatSheets: Make CheatSheets plural; send data through, not json content.handlebars: just use #each for now --- lib/DDG/Goodie/CheatSheets.pm | 18 +++++++++++------- share/goodie/cheat_sheets/content.handlebars | 6 +++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/DDG/Goodie/CheatSheets.pm b/lib/DDG/Goodie/CheatSheets.pm index c9e469191..3c59a53d0 100644 --- a/lib/DDG/Goodie/CheatSheets.pm +++ b/lib/DDG/Goodie/CheatSheets.pm @@ -7,13 +7,13 @@ use DDG::Goodie; zci answer_type => 'cheat_sheet'; zci is_cached => 1; -name 'CheatSheet'; +name 'CheatSheets'; description 'Cheat sheets'; code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/CheatSheets.pm'; category 'cheat_sheets'; topics qw'computing geek programming sysadmin'; -primary_example_queries 'help', 'cheat sheet', 'example'; +primary_example_queries 'universal help', 'universal cheat sheet', 'universal example'; triggers startend => ( 'cheat sheet', @@ -37,14 +37,18 @@ handle remainder => sub { my $data = decode_json($json); return 'Vim Cheat Sheet', structured_answer => { id => 'cheat_sheets', - name => 'Cheat Sheet', - data => $json, - templates => { - group => 'base', - options => { + name => 'Cheat Sheets', + data => $data, + templates => { + group => 'base', + options => { content => 'DDH.cheat_sheets.content', moreAt => true } + }, + meta => { + sourceName => 'duckduckgo', + sourceURL => 'https://duckduckgo.com' } }; }; diff --git a/share/goodie/cheat_sheets/content.handlebars b/share/goodie/cheat_sheets/content.handlebars index 4f26b2078..5697e3a9f 100644 --- a/share/goodie/cheat_sheets/content.handlebars +++ b/share/goodie/cheat_sheets/content.handlebars @@ -3,12 +3,12 @@

{{this}}

{{#withItem ../sections key=this}} - {{#table-each this}} + {{#each this}} - + - {{/table-each}} + {{/each}}
{{key}}:{{ellipsis val 350}}{{val}}
{{/withItem}} {{/each}} From 641140fc465845b5b1ab141f82414be305c98d91 Mon Sep 17 00:00:00 2001 From: Zach Thompson Date: Fri, 27 Feb 2015 16:48:24 -0500 Subject: [PATCH 17/51] vim123.json: test symlinks --- share/goodie/cheat_sheets/vi123.json | 1 + 1 file changed, 1 insertion(+) create mode 120000 share/goodie/cheat_sheets/vi123.json diff --git a/share/goodie/cheat_sheets/vi123.json b/share/goodie/cheat_sheets/vi123.json new file mode 120000 index 000000000..d7c281839 --- /dev/null +++ b/share/goodie/cheat_sheets/vi123.json @@ -0,0 +1 @@ +vimng.json \ No newline at end of file From c66395e989956ed1aa0157e88162302a7cd8e2b8 Mon Sep 17 00:00:00 2001 From: Zach Thompson Date: Fri, 27 Feb 2015 18:41:36 -0500 Subject: [PATCH 18/51] DDG::Goodie::Cheatsheets: Slightly modify how the cheat sheet data are sent through content.handlebars: basic record display of term/definition regexng.json,tmuxng.json: Existing cheat sheet data for testing reng.json,ving.json: aliases (symlinks) for regexng and vimng Using "ng", i.e. "next gen", so they trigger instead of the existing IAs. --- lib/DDG/Goodie/CheatSheets.pm | 27 ++++++++++++------- share/goodie/cheat_sheets/content.handlebars | 7 +---- share/goodie/cheat_sheets/regexng.json | 1 + share/goodie/cheat_sheets/reng.json | 1 + share/goodie/cheat_sheets/tmuxng.json | 1 + .../cheat_sheets/{vi123.json => ving.json} | 0 6 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 share/goodie/cheat_sheets/regexng.json create mode 120000 share/goodie/cheat_sheets/reng.json create mode 100644 share/goodie/cheat_sheets/tmuxng.json rename share/goodie/cheat_sheets/{vi123.json => ving.json} (100%) diff --git a/lib/DDG/Goodie/CheatSheets.pm b/lib/DDG/Goodie/CheatSheets.pm index 3c59a53d0..43e343744 100644 --- a/lib/DDG/Goodie/CheatSheets.pm +++ b/lib/DDG/Goodie/CheatSheets.pm @@ -35,21 +35,30 @@ handle remainder => sub { open my $fh, $json_path or return; my $json = do { local $/; <$fh> }; my $data = decode_json($json); + my @data; + for my $s (@{$data->{section_order}}){ + my %record_data; + for my $t (@{$data->{sections}{$s}}){ + $record_data{$t->{key}} = $t->{val}; + } + push @data, {title => $s, record_data => \%record_data}; + } return 'Vim Cheat Sheet', structured_answer => { id => 'cheat_sheets', name => 'Cheat Sheets', - data => $data, + data => \@data, templates => { group => 'base', options => { - content => 'DDH.cheat_sheets.content', - moreAt => true - } - }, - meta => { - sourceName => 'duckduckgo', - sourceURL => 'https://duckduckgo.com' - } + content => 'record', + moreAt => true, + rowHighlight => true + } + }, + meta => { + sourceName => 'duckduckgo', + sourceURL => 'https://duckduckgo.com' + } }; }; diff --git a/share/goodie/cheat_sheets/content.handlebars b/share/goodie/cheat_sheets/content.handlebars index 5697e3a9f..bb9adff98 100644 --- a/share/goodie/cheat_sheets/content.handlebars +++ b/share/goodie/cheat_sheets/content.handlebars @@ -1,15 +1,10 @@
-{{#each section_order}} -

{{this}}

- {{#withItem ../sections key=this}} - {{#each this}} + {{#each terms}} {{/each}}
{{key}}: {{val}}
- {{/withItem}} -{{/each}}
diff --git a/share/goodie/cheat_sheets/regexng.json b/share/goodie/cheat_sheets/regexng.json new file mode 100644 index 000000000..f7dccf1b5 --- /dev/null +++ b/share/goodie/cheat_sheets/regexng.json @@ -0,0 +1 @@ +{"name":"Regex Cheat Sheet","section_order":["Anchors","Character Classes","POSIX Classes","Pattern Modifiers","Escape Sequences","Quantifiers","Groups and Ranges","Assertions","Special Characters","String Replacement"],"sections":{"Assertions":[{"val":"Lookahead assertion","key":"?="},{"val":"Negative lookahead","key":"?!"},{"val":"Lookbehind assertion","key":"?<="},{"val":"Negative lookbehind","key":"?!= or ?"},{"val":"Condition [if then]","key":"?()"},{"val":"Condition [if then else]","key":"?()|"},{"val":"Comment","key":"?#"}],"POSIX Classes":[{"val":"Uppercase letters [A-Z]","key":"[:upper:]"},{"val":"Lowercase letters [a-z]","key":"[:lower:]"},{"val":"All letters [A-Za-z]","key":"[:alpha:]"},{"val":"Digits and letters [A-Za-z0-9]","key":"[:alnum:]"},{"val":"Digits [0-9]","key":"[:digit:]"},{"val":"Hexadecimal digits [0-9a-f]","key":"[:xdigit:]"},{"val":"Punctuation","key":"[:punct:]"},{"val":"Space and tab [ \\t]","key":"[:blank:]"},{"val":"Blank characters [ \\t\\r\\n\\v\\f]","key":"[:space:]"},{"val":"Control characters [\\x00-\\x1F\\x7F]","key":"[:cntrl:]"},{"val":"Printed characters [\\x21-\\x7E]","key":"[:graph:]"},{"val":"Printed characters and spaces [\\x20-\\x7E]","key":"[:print:]"},{"val":"Digits, letters and underscore [A-Za-z0-9_]","key":"[:word:]"}],"Groups and Ranges":[{"val":"Any character except newline (\\n)","key":"."},{"val":"a or b","key":"(a|b)"},{"val":"Group","key":"(...)"},{"val":"Passive (non-capturing) group","key":"(?:...)"},{"val":"Single character (a or b or c)","key":"[abc]"},{"val":"Single character (not a or b or c)","key":"[^abc]"},{"val":"Single character range (a or b ... or q)","key":"[a-q]"},{"val":"Single character range (A or B ... or Z)","key":"[A-Z]"},{"val":"Single digit from 0 to 9","key":"[0-9]"}],"Special Characters":[{"val":"New line","key":"\\n"},{"val":"Carriage return","key":"\\r"},{"val":"Tab","key":"\\t"},{"val":"Vertical tab","key":"\\v"},{"val":"Form feed","key":"\\f"},{"val":"Octal character ooo","key":"\\ooo"},{"val":"Hex character hh","key":"\\xhh"}],"Escape Sequences":[{"val":"Escape following character","key":"\\"},{"val":"Begin literal sequence","key":"\\Q"},{"val":"End literal sequence","key":"\\E"}],"Pattern Modifiers":[{"val":"Global Match (all occurrences)","key":"//g"},{"val":"Case-insensitive","key":"//i"},{"val":"Multiple line","key":"//m"},{"val":"Treat string as single line","key":"//s"},{"val":"Allow comments and whitespace","key":"//x"},{"val":"Evaluate replacement","key":"//e"},{"val":"Ungreedy pattern","key":"//U"}],"Quantifiers":[{"val":"0 or more","key":"*"},{"val":"1 or more","key":"+"},{"val":"0 or 1 (optional)","key":"?"},{"val":"Exactly 3","key":"{3}"},{"val":"3 or more","key":"{3,}"},{"val":"2, 3, 4 or 5","key":"{2,5}"}],"String Replacement":[{"val":"n-th non-passive group","key":"$n"},{"val":"\"xyz\" in /^(abc(xyz))$/","key":"$2"},{"val":"\"xyz\" in /^(?:abc)(xyz)$/","key":"$1"},{"val":"Before matched string","key":"$`"},{"val":"After matched string","key":"$'"},{"val":"Last matched string","key":"$+"},{"val":"Entire matched string","key":"$&"}],"Character Classes":[{"val":"Control character","key":"\\c"},{"val":"Whitespace","key":"\\s"},{"val":"Not Whitespace","key":"\\S"},{"val":"Digit","key":"\\d"},{"val":"Not digit","key":"\\D"},{"val":"Word","key":"\\w"},{"val":"Not Word","key":"\\W"},{"val":"Hexadecimal digit","key":"\\x"},{"val":"Octal Digit","key":"\\O"}],"Anchors":[{"val":"Start of string or line","key":"^"},{"val":"Start of string","key":"\\A"},{"val":"End of string or line","key":"$"},{"val":"End of string","key":"\\Z"},{"val":"Word boundary","key":"\\b"},{"val":"Not word boundary","key":"\\B"},{"val":"Start of word","key":"\\<"},{"val":"End of word","key":"\\>"}]},"description":"Regular expression syntax","meta":{"sourceName":"?","sourceURL":""}} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/reng.json b/share/goodie/cheat_sheets/reng.json new file mode 120000 index 000000000..d638cd3d3 --- /dev/null +++ b/share/goodie/cheat_sheets/reng.json @@ -0,0 +1 @@ +regexng.json \ No newline at end of file diff --git a/share/goodie/cheat_sheets/tmuxng.json b/share/goodie/cheat_sheets/tmuxng.json new file mode 100644 index 000000000..7acc7bcd6 --- /dev/null +++ b/share/goodie/cheat_sheets/tmuxng.json @@ -0,0 +1 @@ +{"name":"tmux","section_order":["Session Control (from the command line)","Pane Control","Window Control","Copy-Mode (Emacs)","Copy-Mode (vi)"],"sections":{"Copy-Mode (Emacs)":[{"val":"Enter copy mode","key":"Ctrl-B ["},{"val":"Bottom of history","key":"Ctrl-B M-<"},{"val":"Top of histroy","key":"Ctrl-B M->"},{"val":"Copy selection","key":"Ctrl-B M-w"},{"val":"Paste selection","key":"Ctrl-B M-y"},{"val":"Cursor Up","key":"Ctrl-B Up"},{"val":"Cursor Down","key":"Ctrl-B Down"},{"val":"Cursor Left","key":"Ctrl-B Left"},{"val":"Cursor Right","key":"Ctrl-B Right"}],"Window Control":[{"val":"Create new window","key":"Ctrl-B c"},{"val":"Detach from session","key":"Ctrl-B d"},{"val":"Rename a window","key":"Ctrl-B ,"},{"val":"List windows","key":"Ctrl-B w"}],"Pane Control":[{"val":"Split pane horizontally","key":"Ctrl-B \""},{"val":"Split pane vertically","key":"Ctrl-B %"},{"val":"Next pane","key":"Ctrl-B o"},{"val":"Previous pane","key":"Ctrl-B ;"},{"val":"Kill current pane","key":"Ctrl-B x"},{"val":"Kill all panes but the current one","key":"Ctrl-B !"},{"val":"Swap panes","key":"Ctrl-B Ctrl-O"},{"val":"Display clock","key":"Ctrl-B t"},{"val":"Transpose two letters (delete and paste)","key":"Ctrl-B q"}],"Copy-Mode (vi)":[{"val":"Enter copy mode","key":"Ctrl-B ["},{"val":"Bottom of history","key":"Ctrl-B G"},{"val":"Top of histroy","key":"Ctrl-B g"},{"val":"Copy selection","key":"Ctrl-B Enter"},{"val":"Paste selection","key":"Ctrl-B p"},{"val":"Cursor Up","key":"Ctrl-B k"},{"val":"Cursor Down","key":"Ctrl-B j"},{"val":"Cursor Left","key":"Ctrl-B h"},{"val":"Cursor Right","key":"Ctrl-B l"}],"Session Control (from the command line)":[{"val":"Start a new session","key":"tmux"},{"val":"Re-attach a detached session","key":"tmux attach"},{"val":"Re-attach a detached session (and detach it from elsewhere)","key":"tmux attach -d"}]},"description":"Terminal multiplexer","meta":{"sourceName":"OpenBSD","sourceURL":"http://www.openbsd.org/cgi-bin/man.cgi?query=tmux&sektion=1"}} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/vi123.json b/share/goodie/cheat_sheets/ving.json similarity index 100% rename from share/goodie/cheat_sheets/vi123.json rename to share/goodie/cheat_sheets/ving.json From 049707802817c8f94cc81246aef155166b767417 Mon Sep 17 00:00:00 2001 From: puskin94 Date: Wed, 4 Mar 2015 21:27:31 +0100 Subject: [PATCH 19/51] jagtalon suggestions --- lib/DDG/Goodie/Rc4.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/DDG/Goodie/Rc4.pm b/lib/DDG/Goodie/Rc4.pm index 981033e1b..b8cbd0dc9 100644 --- a/lib/DDG/Goodie/Rc4.pm +++ b/lib/DDG/Goodie/Rc4.pm @@ -13,8 +13,7 @@ zci is_cached => 1; name "RC4.pm"; description "Encrypt or decrypt a text using a key provided by the user"; -primary_example_queries "crypto encrypt key string", "crypto decrypt key string"; -secondary_example_queries "crypto en key string", "crypto de key string"; +primary_example_queries "rc4 en mysecretkey hello", "rc4 de duck yWrJniG/nNg="; category "computing_tools"; topics "cryptography"; code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Rc4.pm"; @@ -41,7 +40,7 @@ handle remainder => sub { # To avoid problems with non printable characters, we transform the result using encode_base64() $result = encode_base64($encrypted); chomp $result; - $operation = "Rc4 Encrypt"; + $operation = "RC4 Encrypt"; } elsif ($type =~ m/^de(c|crypt)?$/) { #To decrypt we do the reverse process, we take the plaintext, transform it using decode_base64() @@ -49,7 +48,7 @@ handle remainder => sub { # Then we pass it to the RC4 funcion to be decrypted. $result = RC4($key, $decoded); # No need to encode again, this result is show as is. - $operation = "Rc4 Decrypt"; + $operation = "RC4 Decrypt"; } else { return; } From 0ec8ed6c658aa67f0642a74f132e134217b7d9b1 Mon Sep 17 00:00:00 2001 From: puskin94 Date: Wed, 4 Mar 2015 22:12:06 +0100 Subject: [PATCH 20/51] test file update --- t/Rc4.t | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/Rc4.t b/t/Rc4.t index dbebda086..62e1f0fcf 100644 --- a/t/Rc4.t +++ b/t/Rc4.t @@ -12,16 +12,16 @@ ddg_goodie_test( [qw( DDG::Goodie::Rc4 )], - 'rc4 en mysecretkey hello' => test_zci("Rc4 Encrypt: hello, with key: mysecretkey is grYU1K8=", + 'rc4 en mysecretkey hello' => test_zci("RC4 Encrypt: hello, with key: mysecretkey is grYU1K8=", structured_answer => { input => ['hello, Key: mysecretkey'], - operation => "Rc4 Encrypt", + operation => "RC4 Encrypt", result => "grYU1K8=" }), - 'rc4 de duck yWrJniG/nNg=' => test_zci("Rc4 Decrypt: yWrJniG/nNg=, with key: duck is DdgRocks", + 'rc4 de duck yWrJniG/nNg=' => test_zci("RC4 Decrypt: yWrJniG/nNg=, with key: duck is DdgRocks", structured_answer => { input => ['yWrJniG/nNg=, Key: duck'], - operation => "Rc4 Decrypt", + operation => "RC4 Decrypt", result => "DdgRocks" }), 'rc4 ' => undef, From e8fed281ca40879df1bd36594641aaf5f6b5ce5c Mon Sep 17 00:00:00 2001 From: Zach Thompson Date: Wed, 4 Mar 2015 15:35:39 -0700 Subject: [PATCH 21/51] DDG::Goodie::CheatSheets: Add triggers from all other cheat sheet goodies. --- lib/DDG/Goodie/CheatSheets.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/DDG/Goodie/CheatSheets.pm b/lib/DDG/Goodie/CheatSheets.pm index 43e343744..91a502f94 100644 --- a/lib/DDG/Goodie/CheatSheets.pm +++ b/lib/DDG/Goodie/CheatSheets.pm @@ -16,14 +16,15 @@ topics qw'computing geek programming sysadmin'; primary_example_queries 'universal help', 'universal cheat sheet', 'universal example'; triggers startend => ( - 'cheat sheet', - 'cheatsheet', - 'guide', - 'help', - 'quick reference', - 'reference', - 'example', - 'examples', + 'char', 'chars', + 'character', 'characters', + 'cheat sheet', 'cheatsheet', + 'command', 'commands', + 'example', 'examples', + 'guide', 'help', + 'quick reference', 'reference', + 'shortcut', 'shortcuts', + 'symbol', 'symbols', ); attribution github => [zachthompson => 'Zach Thompson']; @@ -45,7 +46,7 @@ handle remainder => sub { } return 'Vim Cheat Sheet', structured_answer => { id => 'cheat_sheets', - name => 'Cheat Sheets', + name => 'Cheat Sheet', data => \@data, templates => { group => 'base', From 73e560695d3fa83501eb1fd15f9c63f73c8d4f3f Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Wed, 11 Mar 2015 17:13:09 +0000 Subject: [PATCH 22/51] Add FenViewer Instant answer This is the first commit. --- lib/DDG/Goodie/FenViewer.pm | 124 +++++++++++++++++++++++++ share/goodie/fen_viewer/fen_viewer.css | 41 ++++++++ t/FenViewer.t | 23 +++++ 3 files changed, 188 insertions(+) create mode 100644 lib/DDG/Goodie/FenViewer.pm create mode 100644 share/goodie/fen_viewer/fen_viewer.css create mode 100644 t/FenViewer.t diff --git a/lib/DDG/Goodie/FenViewer.pm b/lib/DDG/Goodie/FenViewer.pm new file mode 100644 index 000000000..ef11631a0 --- /dev/null +++ b/lib/DDG/Goodie/FenViewer.pm @@ -0,0 +1,124 @@ +package DDG::Goodie::FenViewer; +# ABSTRACT: This instant answer parses a chess position in the Forsyth–Edwards notation, +# and draws a chessboard on screen representing that position. The current version only +# parses the current board position (the first field in the FEN format) and does not check +# that the given position is actually legal. + +use DDG::Goodie; +use Scalar::Util qw(looks_like_number); +use Try::Tiny; + +zci answer_type => "fen_viewer"; +zci is_cached => 1; + +# Metadata. See https://duck.co/duckduckhack/metadata for help in filling out this section. +name "FenViewer"; +description "This instant answer parses a chess position in the Forsyth–Edwards notation, and draws a chessboard on screen representing that position."; + primary_example_queries "FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"; + +category "entertainment"; +topics "gaming"; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/FENViewer.pm"; +attribution github => ["rouzbeh", "Ali Neishabouri"], + twitter => "Rou7_beh"; + +# Triggers +triggers start => "fen"; + +# Parse the FEN string into an array of length 64. +sub parse_position { + my ($i) = 0; + my ($inp_query) = @_; + my (@cases) = (); + my (@fen_fields) = split(' ', $inp_query); + my ($position) = $fen_fields[0]; + for (my $char = 0 ; $char < length($position) ; $char++ ) { + my $fenchar = substr($position, $char, 1); + if (looks_like_number($fenchar)) { + for ($i = 0; $i < $fenchar; $i++){ + push(@cases, 'e'); + } + } + elsif ($fenchar ne '/') { + push(@cases, $fenchar); + } + } + return @cases; +} + +# Generate a chessboard as a HTML table. +sub draw_chessboard { + my (@position) = @_; + my ($i) = 0; + my ($j) = 0; + my ($counter) = 0; + my (@arr) = ("A".."Z"); + my (%class_dict) = ( + 'r' => 'black rook', + 'n' => 'black knight', + 'b' => 'black bishop', + 'q' => 'black queen', + 'k' => 'black king', + 'p' => 'black pawn', + 'e' => 'empty', + 'R' => 'white rook', + 'N' => 'white knight', + 'B' => 'white bishop', + 'Q' => 'white queen', + 'K' => 'white king', + 'P' => 'white pawn', + ); + + my (%unicode_dict) = ( + 'r' => '♜', + 'n' => '♞', + 'b' => '♝', + 'q' => '♛', + 'k' => '♚', + 'p' => '♟', + 'e' => '', + 'R' => '♖', + 'N' => '♘', + 'B' => '♗', + 'Q' => '♕', + 'K' => '♔', + 'P' => '♙', + ); + + my ($html_chessboard) = '
'; + for ($i = 0; $i < 8; $i++){ + # Rows + $html_chessboard .= ''; + for ($j = 0; $j < 8; $j++){ + # Columns + $html_chessboard .= ''; + $counter++; + } + $html_chessboard .= ''; + } + $html_chessboard .= '
'; + $html_chessboard .= ''.$unicode_dict{$position[$counter]}.''; + $html_chessboard .= '
'; + return $html_chessboard; +} + +# Handle statement +handle remainder => sub { + + # optional - regex guard + # return unless qr/^\w+/; + my ($query) = $_; + return unless $query; + my (@pos) = parse_position($query); + my ($html_out) = ''; + try { + $html_out = draw_chessboard(@pos); + } + catch { + return; + }; + return 'Chessboard', html => $html_out; +}; + +1; diff --git a/share/goodie/fen_viewer/fen_viewer.css b/share/goodie/fen_viewer/fen_viewer.css new file mode 100644 index 000000000..a40c3d29d --- /dev/null +++ b/share/goodie/fen_viewer/fen_viewer.css @@ -0,0 +1,41 @@ +/* + Document : zeroclickinfo-goodies/share/goodie/fen_viewer/fen_viewer.css + Created on : 2015-03-11 01:06 PM + Author : rouzbeh + Description: + Purpose of the stylesheet follows. + To change this template use Tools | Templates. +*/ + +.zci--answer .zci--fenviewer a { + color:#000; + display:block; + font-size:30px; + height:40px; + position:relative; + text-decoration:none; + text-shadow:0 1px #fff; + width:40px; +} +.zci--answer .zci--fenviewer .chess_board { border:5px solid #333; } +.zci--answer .zci--fenviewer .chess_board td { + background:#fff; + background:-moz-linear-gradient(top, #fff, #eee); + background:-webkit-gradient(linear,0 0, 0 100%, from(#fff), to(#eee)); + box-shadow:inset 0 0 0 1px #fff; + -moz-box-shadow:inset 0 0 0 1px #fff; + -webkit-box-shadow:inset 0 0 0 1px #fff; + height:40px; + text-align:center; + vertical-align:middle; + width:40px; +} +.zci--answer .zci--fenviewer .chess_board tr:nth-child(odd) td:nth-child(even), +.zci--answer .zci--fenviewer .chess_board tr:nth-child(even) td:nth-child(odd) { + background:#ccc; + background:-moz-linear-gradient(top, #ccc, #eee); + background:-webkit-gradient(linear,0 0, 0 100%, from(#ccc), to(#eee)); + box-shadow:inset 0 0 10px rgba(0,0,0,.4); + -moz-box-shadow:inset 0 0 10px rgba(0,0,0,.4); + -webkit-box-shadow:inset 0 0 10px rgba(0,0,0,.4); +} \ No newline at end of file diff --git a/t/FenViewer.t b/t/FenViewer.t new file mode 100644 index 000000000..fcd20cbb8 --- /dev/null +++ b/t/FenViewer.t @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => "fen_viewer"; +zci is_cached => 1; + +ddg_goodie_test( + [qw( DDG::Goodie::FenViewer )], + # At a minimum, be sure to include tests for all: + # - primary_example_queries + # - secondary_example_queries + 'FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' => test_zci('Chessboard', html => ''), + 'fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1' => test_zci('Chessboard', html => ''), + # Try to include some examples of queries on which it might + # appear that your answer will trigger, but does not. + 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' => undef, +); + +done_testing; From b564088b538042f5ba42be745139d859fddc7a6a Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Wed, 11 Mar 2015 17:34:54 +0000 Subject: [PATCH 23/51] FenViewer: Clean up CSS file by removing unneeded prefixes --- share/goodie/fen_viewer/fen_viewer.css | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/share/goodie/fen_viewer/fen_viewer.css b/share/goodie/fen_viewer/fen_viewer.css index a40c3d29d..2aba4e779 100644 --- a/share/goodie/fen_viewer/fen_viewer.css +++ b/share/goodie/fen_viewer/fen_viewer.css @@ -20,11 +20,8 @@ .zci--answer .zci--fenviewer .chess_board { border:5px solid #333; } .zci--answer .zci--fenviewer .chess_board td { background:#fff; - background:-moz-linear-gradient(top, #fff, #eee); - background:-webkit-gradient(linear,0 0, 0 100%, from(#fff), to(#eee)); + background:linear-gradient(top, #fff, #eee); box-shadow:inset 0 0 0 1px #fff; - -moz-box-shadow:inset 0 0 0 1px #fff; - -webkit-box-shadow:inset 0 0 0 1px #fff; height:40px; text-align:center; vertical-align:middle; @@ -33,9 +30,6 @@ .zci--answer .zci--fenviewer .chess_board tr:nth-child(odd) td:nth-child(even), .zci--answer .zci--fenviewer .chess_board tr:nth-child(even) td:nth-child(odd) { background:#ccc; - background:-moz-linear-gradient(top, #ccc, #eee); - background:-webkit-gradient(linear,0 0, 0 100%, from(#ccc), to(#eee)); + background:linear-gradient(top, #ccc, #eee); box-shadow:inset 0 0 10px rgba(0,0,0,.4); - -moz-box-shadow:inset 0 0 10px rgba(0,0,0,.4); - -webkit-box-shadow:inset 0 0 10px rgba(0,0,0,.4); } \ No newline at end of file From f2f80c692620653c18ba46eba9b77db5c5d0b4d4 Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Thu, 12 Mar 2015 12:36:34 +0000 Subject: [PATCH 24/51] FenViewer: Add ASCII output to the answer --- lib/DDG/Goodie/FenViewer.pm | 43 ++++++++++++++++++++++++++++++++++--- t/FenViewer.t | 4 ++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/DDG/Goodie/FenViewer.pm b/lib/DDG/Goodie/FenViewer.pm index ef11631a0..8e653ad78 100644 --- a/lib/DDG/Goodie/FenViewer.pm +++ b/lib/DDG/Goodie/FenViewer.pm @@ -47,7 +47,7 @@ sub parse_position { } # Generate a chessboard as a HTML table. -sub draw_chessboard { +sub draw_chessboard_html { my (@position) = @_; my ($i) = 0; my ($j) = 0; @@ -103,6 +103,39 @@ sub draw_chessboard { return $html_chessboard; } +# Generate a chessboard in ASCII, with the same format as +# 'text output from Chess::PGN::EPD +sub draw_chessboard_ascii { + my (@position) = @_; + my ($i) = 0; + my ($j) = 0; + my ($counter) = 0; + my ($ascii_chessboard) = ""; + for ($i = 0; $i < 8; $i++){ + # Rows + for ($j = 0; $j < 8; $j++){ + # Columns + if ($position[$counter] ne 'e') { + # Occupied square + $ascii_chessboard .= $position[$counter]; + } + elsif ($j % 2 != $i % 2) { + # Black square + $ascii_chessboard .= '-'; + } + else { + # White square + $ascii_chessboard .= ' '; + } + $counter++; + } + if($counter < 63) { + $ascii_chessboard .= "\n"; + } + } + return $ascii_chessboard; +} + # Handle statement handle remainder => sub { @@ -112,13 +145,17 @@ handle remainder => sub { return unless $query; my (@pos) = parse_position($query); my ($html_out) = ''; + my ($ascii_out) = ''; try { - $html_out = draw_chessboard(@pos); + $html_out = draw_chessboard_html(@pos); + $ascii_out = draw_chessboard_ascii(@pos); } catch { return; }; - return 'Chessboard', html => $html_out; + print $ascii_out; + print $html_out; + return $ascii_out, html => $html_out; }; 1; diff --git a/t/FenViewer.t b/t/FenViewer.t index fcd20cbb8..9a1aecf24 100644 --- a/t/FenViewer.t +++ b/t/FenViewer.t @@ -13,8 +13,8 @@ ddg_goodie_test( # At a minimum, be sure to include tests for all: # - primary_example_queries # - secondary_example_queries - 'FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' => test_zci('Chessboard', html => ''), - 'fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1' => test_zci('Chessboard', html => ''), + 'FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' => test_zci("rnbqkbnr\npppppppp\n - - - -\n- - - - \n - - - -\n- - - - \nPPPPPPPP\nRNBQKBNR", html => ''), + 'fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1' => test_zci("rnbqkbnr\npppppppp\n - - - -\n- - - - \n - -P- -\n- - - - \nPPPP PPP\nRNBQKBNR", html => ''), # Try to include some examples of queries on which it might # appear that your answer will trigger, but does not. 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' => undef, From 8274157a001a92649b96b231ba9651a1ea61a67b Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Thu, 12 Mar 2015 12:39:05 +0000 Subject: [PATCH 25/51] FenViewer: Remove useless comments --- lib/DDG/Goodie/FenViewer.pm | 8 -------- share/goodie/fen_viewer/fen_viewer.css | 11 ++--------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/DDG/Goodie/FenViewer.pm b/lib/DDG/Goodie/FenViewer.pm index 8e653ad78..11ff9e319 100644 --- a/lib/DDG/Goodie/FenViewer.pm +++ b/lib/DDG/Goodie/FenViewer.pm @@ -11,7 +11,6 @@ use Try::Tiny; zci answer_type => "fen_viewer"; zci is_cached => 1; -# Metadata. See https://duck.co/duckduckhack/metadata for help in filling out this section. name "FenViewer"; description "This instant answer parses a chess position in the Forsyth–Edwards notation, and draws a chessboard on screen representing that position."; primary_example_queries "FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"; @@ -22,7 +21,6 @@ code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DD attribution github => ["rouzbeh", "Ali Neishabouri"], twitter => "Rou7_beh"; -# Triggers triggers start => "fen"; # Parse the FEN string into an array of length 64. @@ -136,11 +134,7 @@ sub draw_chessboard_ascii { return $ascii_chessboard; } -# Handle statement handle remainder => sub { - - # optional - regex guard - # return unless qr/^\w+/; my ($query) = $_; return unless $query; my (@pos) = parse_position($query); @@ -153,8 +147,6 @@ handle remainder => sub { catch { return; }; - print $ascii_out; - print $html_out; return $ascii_out, html => $html_out; }; diff --git a/share/goodie/fen_viewer/fen_viewer.css b/share/goodie/fen_viewer/fen_viewer.css index 2aba4e779..bfc99e952 100644 --- a/share/goodie/fen_viewer/fen_viewer.css +++ b/share/goodie/fen_viewer/fen_viewer.css @@ -1,12 +1,3 @@ -/* - Document : zeroclickinfo-goodies/share/goodie/fen_viewer/fen_viewer.css - Created on : 2015-03-11 01:06 PM - Author : rouzbeh - Description: - Purpose of the stylesheet follows. - To change this template use Tools | Templates. -*/ - .zci--answer .zci--fenviewer a { color:#000; display:block; @@ -17,6 +8,7 @@ text-shadow:0 1px #fff; width:40px; } + .zci--answer .zci--fenviewer .chess_board { border:5px solid #333; } .zci--answer .zci--fenviewer .chess_board td { background:#fff; @@ -27,6 +19,7 @@ vertical-align:middle; width:40px; } + .zci--answer .zci--fenviewer .chess_board tr:nth-child(odd) td:nth-child(even), .zci--answer .zci--fenviewer .chess_board tr:nth-child(even) td:nth-child(odd) { background:#ccc; From 1afb44f34638cda83d14fa3e1b7b5185efbdfdbd Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Thu, 12 Mar 2015 13:04:21 +0000 Subject: [PATCH 26/51] FenViewer: More robust parsing. The query is now trimmed to remove leading spaces. Malformed input is now better detected, and the IA returns undef. --- lib/DDG/Goodie/FenViewer.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/DDG/Goodie/FenViewer.pm b/lib/DDG/Goodie/FenViewer.pm index 11ff9e319..69ea8562b 100644 --- a/lib/DDG/Goodie/FenViewer.pm +++ b/lib/DDG/Goodie/FenViewer.pm @@ -26,12 +26,14 @@ triggers start => "fen"; # Parse the FEN string into an array of length 64. sub parse_position { my ($i) = 0; - my ($inp_query) = @_; + my ($position) = @_; + $position =~ s/^\s+|\s+$//g; my (@cases) = (); - my (@fen_fields) = split(' ', $inp_query); - my ($position) = $fen_fields[0]; for (my $char = 0 ; $char < length($position) ; $char++ ) { my $fenchar = substr($position, $char, 1); + if ($fenchar eq ' ') { + return @cases; + } if (looks_like_number($fenchar)) { for ($i = 0; $i < $fenchar; $i++){ push(@cases, 'e'); @@ -138,6 +140,10 @@ handle remainder => sub { my ($query) = $_; return unless $query; my (@pos) = parse_position($query); + if ($#pos != 63) { + # The format is wrong, e.g. space in the middle + return; + } my ($html_out) = ''; my ($ascii_out) = ''; try { @@ -145,6 +151,7 @@ handle remainder => sub { $ascii_out = draw_chessboard_ascii(@pos); } catch { + # The format is wrong, e.g. non-existent piece return; }; return $ascii_out, html => $html_out; From c767985bf1773751af781469334a2a6c24958ff9 Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Thu, 12 Mar 2015 13:05:30 +0000 Subject: [PATCH 27/51] FenViewer: Add more realistic test cases, as well as more undefiend Now there are two test cases from the last world champioship --- t/FenViewer.t | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/t/FenViewer.t b/t/FenViewer.t index 9a1aecf24..99c4db97f 100644 --- a/t/FenViewer.t +++ b/t/FenViewer.t @@ -10,14 +10,14 @@ zci is_cached => 1; ddg_goodie_test( [qw( DDG::Goodie::FenViewer )], - # At a minimum, be sure to include tests for all: - # - primary_example_queries - # - secondary_example_queries 'FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' => test_zci("rnbqkbnr\npppppppp\n - - - -\n- - - - \n - - - -\n- - - - \nPPPPPPPP\nRNBQKBNR", html => ''), - 'fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1' => test_zci("rnbqkbnr\npppppppp\n - - - -\n- - - - \n - -P- -\n- - - - \nPPPP PPP\nRNBQKBNR", html => ''), - # Try to include some examples of queries on which it might - # appear that your answer will trigger, but does not. + 'fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1 ' => test_zci("rnbqkbnr\npppppppp\n - - - -\n- - - - \n - -P- -\n- - - - \nPPPP PPP\nRNBQKBNR", html => ''), + # Two examples from the last world championship + 'fen r1b1r1k1/2qn1ppp/1ppp4/p3p3/P2PP3/R4N1P/1PP2PP1/2BQR1K1 b - - 0 14 ' => test_zci("r-b-r-k-\n- qn-ppp\n ppp - -\np - p - \nP- PP- -\nR - -N-P\n PP- PP-\n- BQR K ", html => ''), + 'fen 5rk1/4R1p1/3q1p2/p1p2P1p/P3Q2P/5pP1/2P2P1K/8 w - - 0 35' => test_zci(" - - rk-\n- - R p \n - q p -\np p -P-p\nP- -Q- P\n- - -pP \n -P- P K\n- - - - ", html => ''), 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' => undef, + 'fen' => undef, + 'fen ' => undef, ); done_testing; From 04556b3dade2766e8212409cfbf68c65027e783b Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Fri, 13 Mar 2015 16:14:42 +0000 Subject: [PATCH 28/51] FenViewer: Correct formatting. --- lib/DDG/Goodie/FenViewer.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/DDG/Goodie/FenViewer.pm b/lib/DDG/Goodie/FenViewer.pm index 69ea8562b..88478e631 100644 --- a/lib/DDG/Goodie/FenViewer.pm +++ b/lib/DDG/Goodie/FenViewer.pm @@ -1,5 +1,5 @@ package DDG::Goodie::FenViewer; -# ABSTRACT: This instant answer parses a chess position in the Forsyth–Edwards notation, +# ABSTRACT: This instant answer parses a chess position in the Forsyth-Edwards notation, # and draws a chessboard on screen representing that position. The current version only # parses the current board position (the first field in the FEN format) and does not check # that the given position is actually legal. @@ -12,8 +12,8 @@ zci answer_type => "fen_viewer"; zci is_cached => 1; name "FenViewer"; -description "This instant answer parses a chess position in the Forsyth–Edwards notation, and draws a chessboard on screen representing that position."; - primary_example_queries "FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"; +description "This instant answer parses a chess position in the Forsyth-Edwards notation, and draws a chessboard on screen representing that position."; +primary_example_queries "FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"; category "entertainment"; topics "gaming"; From c3b58c2f4b702045a0019d534fd2218f112ef8aa Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Mon, 16 Mar 2015 22:34:26 +0000 Subject: [PATCH 29/51] FenViewer: Add use strict; --- lib/DDG/Goodie/FenViewer.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/DDG/Goodie/FenViewer.pm b/lib/DDG/Goodie/FenViewer.pm index 88478e631..146625938 100644 --- a/lib/DDG/Goodie/FenViewer.pm +++ b/lib/DDG/Goodie/FenViewer.pm @@ -5,6 +5,7 @@ package DDG::Goodie::FenViewer; # that the given position is actually legal. use DDG::Goodie; +use strict; use Scalar::Util qw(looks_like_number); use Try::Tiny; From 6b0ec2fdbef013b64a9134f15881e572942b2917 Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Fri, 27 Mar 2015 10:52:16 +0000 Subject: [PATCH 30/51] Fenviewer: Clean up visuals --- share/goodie/fen_viewer/fen_viewer.css | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/share/goodie/fen_viewer/fen_viewer.css b/share/goodie/fen_viewer/fen_viewer.css index bfc99e952..eb8888d59 100644 --- a/share/goodie/fen_viewer/fen_viewer.css +++ b/share/goodie/fen_viewer/fen_viewer.css @@ -1,19 +1,16 @@ .zci--answer .zci--fenviewer a { - color:#000; + color:#333; display:block; - font-size:30px; + font-size:27px; height:40px; position:relative; text-decoration:none; - text-shadow:0 1px #fff; width:40px; } -.zci--answer .zci--fenviewer .chess_board { border:5px solid #333; } +.zci--answer .zci--fenviewer .chess_board { border: 2px solid #333; } .zci--answer .zci--fenviewer .chess_board td { background:#fff; - background:linear-gradient(top, #fff, #eee); - box-shadow:inset 0 0 0 1px #fff; height:40px; text-align:center; vertical-align:middle; @@ -22,7 +19,5 @@ .zci--answer .zci--fenviewer .chess_board tr:nth-child(odd) td:nth-child(even), .zci--answer .zci--fenviewer .chess_board tr:nth-child(even) td:nth-child(odd) { - background:#ccc; - background:linear-gradient(top, #ccc, #eee); - box-shadow:inset 0 0 10px rgba(0,0,0,.4); + background-color: #ddd; } \ No newline at end of file From 145684d96c91d4e203a09eaa28d2e21c977ece88 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sun, 29 Mar 2015 22:37:07 +0100 Subject: [PATCH 31/51] Calculator: Adding failing test for https://github.com/duckduckgo/zeroclickinfo-goodies/issues/1026 --- t/Calculator.t | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/t/Calculator.t b/t/Calculator.t index 9f7735073..28fdce847 100644 --- a/t/Calculator.t +++ b/t/Calculator.t @@ -677,6 +677,15 @@ ddg_goodie_test( result => qr/6,666/ } ), + '(0.4e^(0))*cos(0)' => test_zci( + '(0.4e^(0))*cos(0)', + heading => 'Calculator', + structured_answer => { + input => ['(0.4e^(0))*cos(0)'], + operation => 'Calculate', + result => '0.4' + } + ), '123.123.123.123/255.255.255.255' => undef, '83.166.167.160/27' => undef, '9 + 0 x 07' => undef, From 04f698bb5cfd7c8576e4dbe54d7d84cd0165df8a Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sun, 29 Mar 2015 22:49:43 +0100 Subject: [PATCH 32/51] Calculator: Adding failing tests for 2pi; currently implicit multiplication isn't supported --- t/Calculator.t | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/t/Calculator.t b/t/Calculator.t index 28fdce847..f2de877c0 100644 --- a/t/Calculator.t +++ b/t/Calculator.t @@ -686,6 +686,15 @@ ddg_goodie_test( result => '0.4' } ), + '2pi' => test_zci( + '2pi', + heading => 'Calculator', + structure_answer => { + input => ['2pi'], + operation => 'Calculate', + result => "2 * pi = 6.28318530717958" + } + ), '123.123.123.123/255.255.255.255' => undef, '83.166.167.160/27' => undef, '9 + 0 x 07' => undef, From 563cb2909cd64288da3f6131a1dd021fa889d6e8 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sun, 29 Mar 2015 23:07:12 +0100 Subject: [PATCH 33/51] Calculator: Updating tests with accurate output --- t/Calculator.t | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/t/Calculator.t b/t/Calculator.t index f2de877c0..23a165c6d 100644 --- a/t/Calculator.t +++ b/t/Calculator.t @@ -678,21 +678,21 @@ ddg_goodie_test( } ), '(0.4e^(0))*cos(0)' => test_zci( - '(0.4e^(0))*cos(0)', + '(0.4e ^ (0)) * cos(0) = 0.4', heading => 'Calculator', structured_answer => { - input => ['(0.4e^(0))*cos(0)'], + input => ['(0.4e ^ (0)) * cos(0)'], operation => 'Calculate', - result => '0.4' + result => qr'0.4' } ), '2pi' => test_zci( - '2pi', + '2 pi = 6.28318530717958', heading => 'Calculator', - structure_answer => { - input => ['2pi'], + structured_answer => { + input => ['2 pi'], operation => 'Calculate', - result => "2 * pi = 6.28318530717958" + result => qr"6.28318530717958" } ), '123.123.123.123/255.255.255.255' => undef, From 2b833275db133ae89afa938da800284fb0766c16 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sun, 29 Mar 2015 23:10:44 +0100 Subject: [PATCH 34/51] Calculator: Adding support for implicit multiplication and queries like 2pi --- lib/DDG/Goodie/Calculator.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/DDG/Goodie/Calculator.pm b/lib/DDG/Goodie/Calculator.pm index 5e7e23741..f06f9662a 100644 --- a/lib/DDG/Goodie/Calculator.pm +++ b/lib/DDG/Goodie/Calculator.pm @@ -31,7 +31,7 @@ triggers query_nowhitespace => qr< [\( \) x X * % + / \^ 0-9 \. , _ \$ -]* (?(1) (?: -? [0-9 \. , _ ]+ |) |) - (?: [\( \) x X * % + / \^ \$ -] | times | divided by | plus | minus | cos | sin | tan | cotan | log | ln | log[_]?\d{1,3} | exp | tanh | sec | csc | squared )+ + (?: [\( \) x X * % + / \^ \$ -] | times | divided by | plus | minus | cos | sin | tan | cotan | log | ln | log[_]?\d{1,3} | exp | tanh | sec | csc | squared | pi | e )+ (?: [0-9 \. ,]* ) (?: gross | dozen | pi | e | c | squared | score |) @@ -94,7 +94,7 @@ handle query_nowhitespace => sub { $tmp_expr =~ s/ (\d+?)E(-?\d+)([^\d]|\b) /\($1 * 10**$2\)$3/xg; # E == *10^n $tmp_expr =~ s/\$//g; # Remove $s. $tmp_expr =~ s/=$//; # Drop =. - + $tmp_expr =~ s/([0-9])\s*([a-zA-Z])([^0-9])/$1*$2$3/g; # Support 0.5e or 0.5pi; but don't break 1e8 # Now sub in constants while (my ($name, $constant) = each %named_constants) { $tmp_expr =~ s# (\d+?)\s+$name # $1 * $constant #xig; @@ -109,7 +109,6 @@ handle query_nowhitespace => sub { $tmp_expr = $style->for_computation($tmp_expr); # Using functions makes us want answers with more precision than our inputs indicate. my $precision = ($query =~ $funcy) ? undef : ($query =~ /^\$/) ? 2 : max(map { $style->precision_of($_) } @numbers); - my $tmp_result; eval { # e.g. sin(100000)/100000 completely makes this go haywire. From d5fe6fbb2e6733e2a76b9a25c5ee085f3ff7e686 Mon Sep 17 00:00:00 2001 From: rouzbeh Date: Mon, 30 Mar 2015 22:50:16 +0000 Subject: [PATCH 35/51] FenViewer: Fix line height --- share/goodie/fen_viewer/fen_viewer.css | 1 + 1 file changed, 1 insertion(+) diff --git a/share/goodie/fen_viewer/fen_viewer.css b/share/goodie/fen_viewer/fen_viewer.css index eb8888d59..03ccd2172 100644 --- a/share/goodie/fen_viewer/fen_viewer.css +++ b/share/goodie/fen_viewer/fen_viewer.css @@ -6,6 +6,7 @@ position:relative; text-decoration:none; width:40px; + line-height: 1.5; } .zci--answer .zci--fenviewer .chess_board { border: 2px solid #333; } From a07b14688c5a3ae39a1ab4ea70f52dec5b5dd5dd Mon Sep 17 00:00:00 2001 From: ngzhian Date: Sat, 4 Apr 2015 17:17:55 +0000 Subject: [PATCH 36/51] Created my first Goodie! --- lib/DDG/Goodie/IsAwesome/ngzhian.pm | 25 +++++++++++++++++++++++++ t/IsAwesome/ngzhian.t | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/DDG/Goodie/IsAwesome/ngzhian.pm create mode 100644 t/IsAwesome/ngzhian.t diff --git a/lib/DDG/Goodie/IsAwesome/ngzhian.pm b/lib/DDG/Goodie/IsAwesome/ngzhian.pm new file mode 100644 index 000000000..e02dc35de --- /dev/null +++ b/lib/DDG/Goodie/IsAwesome/ngzhian.pm @@ -0,0 +1,25 @@ +package DDG::Goodie::IsAwesome::ngzhian; +# ABSTRACT: ngzhian's first Goodie + +use DDG::Goodie; + +zci answer_type => "is_awesome_ngzhian"; +zci is_cached => 1; + +name "IsAwesome ngzhian"; +description "My first Goodie, it lets the world know that ngzhian is awesome"; +primary_example_queries "duckduckhack ngzhian"; +category "special"; +topics "special_interest", "geek"; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsAwesome/ngzhian.pm"; +attribution github => ["https://github.com/ngzhian", "ngzhian"], + twitter => "ngzhian"; + +triggers start => "duckduckhack ngzhian"; + +handle remainder => sub { + return if $_; + return "ngzhian is awesome and has successfully completed the DuckDuckHack Goodie tutorial!"; +}; + +1; diff --git a/t/IsAwesome/ngzhian.t b/t/IsAwesome/ngzhian.t new file mode 100644 index 000000000..6ca4f5d43 --- /dev/null +++ b/t/IsAwesome/ngzhian.t @@ -0,0 +1,17 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => "is_awesome_ngzhian"; +zci is_cached => 1; + +ddg_goodie_test( + [qw( DDG::Goodie::IsAwesome::ngzhian )], + 'duckduckhack ngzhian' => test_zci('ngzhian is awesome and has successfully completed the DuckDuckHack Goodie tutorial!'), + 'duckduckhack ngzhian is awesome' => undef, +); + +done_testing; From 3898c18876ce982713249261fe69bd0a8d95416c Mon Sep 17 00:00:00 2001 From: Zaahir Moolla Date: Sat, 4 Apr 2015 17:35:33 +0000 Subject: [PATCH 37/51] finished up working detail view cheatsheets --- lib/DDG/Goodie/CheatSheets.pm | 34 +++++++------------ share/goodie/cheat_sheets/cheat_sheets.js | 35 ++++++++++++++++++-- share/goodie/cheat_sheets/content.handlebars | 10 ------ share/goodie/cheat_sheets/regexng.json | 1 - share/goodie/cheat_sheets/reng.json | 1 - share/goodie/cheat_sheets/tmuxng.json | 1 - share/goodie/cheat_sheets/vimng.json | 1 - 7 files changed, 44 insertions(+), 39 deletions(-) delete mode 100644 share/goodie/cheat_sheets/content.handlebars delete mode 100644 share/goodie/cheat_sheets/regexng.json delete mode 120000 share/goodie/cheat_sheets/reng.json delete mode 100644 share/goodie/cheat_sheets/tmuxng.json delete mode 100644 share/goodie/cheat_sheets/vimng.json diff --git a/lib/DDG/Goodie/CheatSheets.pm b/lib/DDG/Goodie/CheatSheets.pm index 91a502f94..3a7802861 100644 --- a/lib/DDG/Goodie/CheatSheets.pm +++ b/lib/DDG/Goodie/CheatSheets.pm @@ -3,17 +3,19 @@ package DDG::Goodie::CheatSheets; use JSON::XS; use DDG::Goodie; +use DDP; zci answer_type => 'cheat_sheet'; zci is_cached => 1; name 'CheatSheets'; description 'Cheat sheets'; +primary_example_queries 'universal help', 'universal cheat sheet', 'universal example'; code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/CheatSheets.pm'; category 'cheat_sheets'; topics qw'computing geek programming sysadmin'; +attribution github => [zachthompson => 'Zach Thompson']; -primary_example_queries 'universal help', 'universal cheat sheet', 'universal example'; triggers startend => ( 'char', 'chars', @@ -27,8 +29,6 @@ triggers startend => ( 'symbol', 'symbols', ); -attribution github => [zachthompson => 'Zach Thompson']; - handle remainder => sub { # If needed we could jump through a few more hoops to check # terms against file names. @@ -36,29 +36,19 @@ handle remainder => sub { open my $fh, $json_path or return; my $json = do { local $/; <$fh> }; my $data = decode_json($json); - my @data; - for my $s (@{$data->{section_order}}){ - my %record_data; - for my $t (@{$data->{sections}{$s}}){ - $record_data{$t->{key}} = $t->{val}; - } - push @data, {title => $s, record_data => \%record_data}; - } + return 'Vim Cheat Sheet', structured_answer => { id => 'cheat_sheets', name => 'Cheat Sheet', - data => \@data, + data => $data, + meta => \%{$data->{meta}}, templates => { - group => 'base', - options => { - content => 'record', - moreAt => true, - rowHighlight => true - } - }, - meta => { - sourceName => 'duckduckgo', - sourceURL => 'https://duckduckgo.com' + group => 'base', + item => 0, + options => { + content => 'DDH.cheat_sheets.detail', + moreAt => 0 + } } }; }; diff --git a/share/goodie/cheat_sheets/cheat_sheets.js b/share/goodie/cheat_sheets/cheat_sheets.js index 2dfc3c543..fa6e8a9e4 100644 --- a/share/goodie/cheat_sheets/cheat_sheets.js +++ b/share/goodie/cheat_sheets/cheat_sheets.js @@ -1,3 +1,32 @@ -Handlebars.registerHelper('withItem', function(object, options) { - return options.fn(object[options.hash.key]); -}); +DDH.cheat_sheets = DDH.cheat_sheets || {}; + +DDH.cheat_sheets.build = function(ops) { + + Handlebars.registerHelper('ordered_cheatsheet', function(sections, section_order, options) { + var result =""; + $.each(section_order, function(i, section) { + if (sections[section]){ + result += options.fn({ name: section, items: sections[section] }); + } + }); + return result; + }); + + return { + onShow: function() { + var $dom = $("#zci-cheat_sheets"), + $container = $dom.find(".cheatsheet__container"), + $more_btn = $dom.find("#show_more"), + $icon = $more_btn.find(".chomp--link__icn"), + $more = $more_btn.find(".chomp--link__mr"), + $less = $more_btn.find(".chomp--link__ls"); + + $more_btn.click(function() { + $container.toggle("compressed"); + $more.toggle(); + $less.toggle(); + $icon.toggleClass("expand"); + }); + } + }; +}; \ No newline at end of file diff --git a/share/goodie/cheat_sheets/content.handlebars b/share/goodie/cheat_sheets/content.handlebars deleted file mode 100644 index bb9adff98..000000000 --- a/share/goodie/cheat_sheets/content.handlebars +++ /dev/null @@ -1,10 +0,0 @@ -
- - {{#each terms}} - - - - - {{/each}} -
{{key}}:{{val}}
-
diff --git a/share/goodie/cheat_sheets/regexng.json b/share/goodie/cheat_sheets/regexng.json deleted file mode 100644 index f7dccf1b5..000000000 --- a/share/goodie/cheat_sheets/regexng.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"Regex Cheat Sheet","section_order":["Anchors","Character Classes","POSIX Classes","Pattern Modifiers","Escape Sequences","Quantifiers","Groups and Ranges","Assertions","Special Characters","String Replacement"],"sections":{"Assertions":[{"val":"Lookahead assertion","key":"?="},{"val":"Negative lookahead","key":"?!"},{"val":"Lookbehind assertion","key":"?<="},{"val":"Negative lookbehind","key":"?!= or ?"},{"val":"Condition [if then]","key":"?()"},{"val":"Condition [if then else]","key":"?()|"},{"val":"Comment","key":"?#"}],"POSIX Classes":[{"val":"Uppercase letters [A-Z]","key":"[:upper:]"},{"val":"Lowercase letters [a-z]","key":"[:lower:]"},{"val":"All letters [A-Za-z]","key":"[:alpha:]"},{"val":"Digits and letters [A-Za-z0-9]","key":"[:alnum:]"},{"val":"Digits [0-9]","key":"[:digit:]"},{"val":"Hexadecimal digits [0-9a-f]","key":"[:xdigit:]"},{"val":"Punctuation","key":"[:punct:]"},{"val":"Space and tab [ \\t]","key":"[:blank:]"},{"val":"Blank characters [ \\t\\r\\n\\v\\f]","key":"[:space:]"},{"val":"Control characters [\\x00-\\x1F\\x7F]","key":"[:cntrl:]"},{"val":"Printed characters [\\x21-\\x7E]","key":"[:graph:]"},{"val":"Printed characters and spaces [\\x20-\\x7E]","key":"[:print:]"},{"val":"Digits, letters and underscore [A-Za-z0-9_]","key":"[:word:]"}],"Groups and Ranges":[{"val":"Any character except newline (\\n)","key":"."},{"val":"a or b","key":"(a|b)"},{"val":"Group","key":"(...)"},{"val":"Passive (non-capturing) group","key":"(?:...)"},{"val":"Single character (a or b or c)","key":"[abc]"},{"val":"Single character (not a or b or c)","key":"[^abc]"},{"val":"Single character range (a or b ... or q)","key":"[a-q]"},{"val":"Single character range (A or B ... or Z)","key":"[A-Z]"},{"val":"Single digit from 0 to 9","key":"[0-9]"}],"Special Characters":[{"val":"New line","key":"\\n"},{"val":"Carriage return","key":"\\r"},{"val":"Tab","key":"\\t"},{"val":"Vertical tab","key":"\\v"},{"val":"Form feed","key":"\\f"},{"val":"Octal character ooo","key":"\\ooo"},{"val":"Hex character hh","key":"\\xhh"}],"Escape Sequences":[{"val":"Escape following character","key":"\\"},{"val":"Begin literal sequence","key":"\\Q"},{"val":"End literal sequence","key":"\\E"}],"Pattern Modifiers":[{"val":"Global Match (all occurrences)","key":"//g"},{"val":"Case-insensitive","key":"//i"},{"val":"Multiple line","key":"//m"},{"val":"Treat string as single line","key":"//s"},{"val":"Allow comments and whitespace","key":"//x"},{"val":"Evaluate replacement","key":"//e"},{"val":"Ungreedy pattern","key":"//U"}],"Quantifiers":[{"val":"0 or more","key":"*"},{"val":"1 or more","key":"+"},{"val":"0 or 1 (optional)","key":"?"},{"val":"Exactly 3","key":"{3}"},{"val":"3 or more","key":"{3,}"},{"val":"2, 3, 4 or 5","key":"{2,5}"}],"String Replacement":[{"val":"n-th non-passive group","key":"$n"},{"val":"\"xyz\" in /^(abc(xyz))$/","key":"$2"},{"val":"\"xyz\" in /^(?:abc)(xyz)$/","key":"$1"},{"val":"Before matched string","key":"$`"},{"val":"After matched string","key":"$'"},{"val":"Last matched string","key":"$+"},{"val":"Entire matched string","key":"$&"}],"Character Classes":[{"val":"Control character","key":"\\c"},{"val":"Whitespace","key":"\\s"},{"val":"Not Whitespace","key":"\\S"},{"val":"Digit","key":"\\d"},{"val":"Not digit","key":"\\D"},{"val":"Word","key":"\\w"},{"val":"Not Word","key":"\\W"},{"val":"Hexadecimal digit","key":"\\x"},{"val":"Octal Digit","key":"\\O"}],"Anchors":[{"val":"Start of string or line","key":"^"},{"val":"Start of string","key":"\\A"},{"val":"End of string or line","key":"$"},{"val":"End of string","key":"\\Z"},{"val":"Word boundary","key":"\\b"},{"val":"Not word boundary","key":"\\B"},{"val":"Start of word","key":"\\<"},{"val":"End of word","key":"\\>"}]},"description":"Regular expression syntax","meta":{"sourceName":"?","sourceURL":""}} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/reng.json b/share/goodie/cheat_sheets/reng.json deleted file mode 120000 index d638cd3d3..000000000 --- a/share/goodie/cheat_sheets/reng.json +++ /dev/null @@ -1 +0,0 @@ -regexng.json \ No newline at end of file diff --git a/share/goodie/cheat_sheets/tmuxng.json b/share/goodie/cheat_sheets/tmuxng.json deleted file mode 100644 index 7acc7bcd6..000000000 --- a/share/goodie/cheat_sheets/tmuxng.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"tmux","section_order":["Session Control (from the command line)","Pane Control","Window Control","Copy-Mode (Emacs)","Copy-Mode (vi)"],"sections":{"Copy-Mode (Emacs)":[{"val":"Enter copy mode","key":"Ctrl-B ["},{"val":"Bottom of history","key":"Ctrl-B M-<"},{"val":"Top of histroy","key":"Ctrl-B M->"},{"val":"Copy selection","key":"Ctrl-B M-w"},{"val":"Paste selection","key":"Ctrl-B M-y"},{"val":"Cursor Up","key":"Ctrl-B Up"},{"val":"Cursor Down","key":"Ctrl-B Down"},{"val":"Cursor Left","key":"Ctrl-B Left"},{"val":"Cursor Right","key":"Ctrl-B Right"}],"Window Control":[{"val":"Create new window","key":"Ctrl-B c"},{"val":"Detach from session","key":"Ctrl-B d"},{"val":"Rename a window","key":"Ctrl-B ,"},{"val":"List windows","key":"Ctrl-B w"}],"Pane Control":[{"val":"Split pane horizontally","key":"Ctrl-B \""},{"val":"Split pane vertically","key":"Ctrl-B %"},{"val":"Next pane","key":"Ctrl-B o"},{"val":"Previous pane","key":"Ctrl-B ;"},{"val":"Kill current pane","key":"Ctrl-B x"},{"val":"Kill all panes but the current one","key":"Ctrl-B !"},{"val":"Swap panes","key":"Ctrl-B Ctrl-O"},{"val":"Display clock","key":"Ctrl-B t"},{"val":"Transpose two letters (delete and paste)","key":"Ctrl-B q"}],"Copy-Mode (vi)":[{"val":"Enter copy mode","key":"Ctrl-B ["},{"val":"Bottom of history","key":"Ctrl-B G"},{"val":"Top of histroy","key":"Ctrl-B g"},{"val":"Copy selection","key":"Ctrl-B Enter"},{"val":"Paste selection","key":"Ctrl-B p"},{"val":"Cursor Up","key":"Ctrl-B k"},{"val":"Cursor Down","key":"Ctrl-B j"},{"val":"Cursor Left","key":"Ctrl-B h"},{"val":"Cursor Right","key":"Ctrl-B l"}],"Session Control (from the command line)":[{"val":"Start a new session","key":"tmux"},{"val":"Re-attach a detached session","key":"tmux attach"},{"val":"Re-attach a detached session (and detach it from elsewhere)","key":"tmux attach -d"}]},"description":"Terminal multiplexer","meta":{"sourceName":"OpenBSD","sourceURL":"http://www.openbsd.org/cgi-bin/man.cgi?query=tmux&sektion=1"}} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/vimng.json b/share/goodie/cheat_sheets/vimng.json deleted file mode 100644 index bb27abdca..000000000 --- a/share/goodie/cheat_sheets/vimng.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"Vim","section_order":["Cursor movement","Insert mode - inserting/appending text","Editing","Marking text (visual mode)","Visual commands","Cut and paste","Exiting","Search and replace","Working with multiple files","Tabs"],"sections":{"Tabs":[{"val":"open a file in a new tab","key":":tabnew filename, :tabn filename"},{"val":"move the current split window into its own tab","key":"Ctrl+wt"},{"val":"move to the next tab","key":"gt, :tabnext, :tabn"},{"val":"move to the previous tab","key":"gT, :tabprev, :tabp"},{"val":"move to tab number #","key":"#gt"},{"val":"move current tab to the #th position (indexed from 0)","key":":tabmove #"},{"val":"close the current tab and all its windows","key":":tabclose/:tabc"},{"val":"close all tabs except for the current one","key":":tabonly/:tabo"}],"Editing":[{"val":"replace a single character","key":"r"},{"val":"join line below to the current one","key":"J"},{"val":"change (replace) entire line","key":"cc"},{"val":"change (replace) to the end of the word","key":"cw"},{"val":"change (replace) to the end of the line","key":"c$"},{"val":"delete character and substitute text","key":"s"},{"val":"delete line and substitute text (same as cc)","key":"S"},{"val":"transpose two letters (delete and paste)","key":"xp"},{"val":"undo","key":"u"},{"val":"redo","key":"Ctrl+r"},{"val":"repeat last command","key":"."}],"Exiting":[{"val":"write (save) the file, but don't exit","key":":w"},{"val":"write (save) and quit","key":":wq"},{"val":"write (save) and quit","key":":x"},{"val":"quit (fails if there are unsaved changes)","key":":q"},{"val":"quit and throw away unsaved changes","key":":q!"}],"Insert mode - inserting/appending text":[{"val":"insert before the cursor","key":"i"},{"val":"insert at the beginning of the line","key":"I"},{"val":"insert (append) after the cursor","key":"a"},{"val":"insert (append) at the end of the line","key":"A"},{"val":"append (open) a new line below the current line","key":"o"},{"val":"append (open) a new line above the current line","key":"O"},{"val":"insert (append) at the end of the word","key":"ea"},{"val":"exit insert mode","key":"Esc"}],"Cut and paste":[{"val":"yank (copy) a line","key":"yy"},{"val":"yank (copy) 2 lines","key":"2yy"},{"val":"yank (copy) word","key":"yw"},{"val":"yank (copy) to end of line","key":"y$"},{"val":"put (paste) the clipboard after cursor","key":"p"},{"val":"put (paste) before cursor","key":"P"},{"val":"delete (cut) a line","key":"dd"},{"val":"delete (cut) 2 lines","key":"2dd"},{"val":"delete (cut) word","key":"dw"},{"val":"delete (cut) to the end of the line","key":"D"},{"val":"delete (cut) to the end of the line","key":"d$"},{"val":"delete (cut) character","key":"x"}],"Marking text (visual mode)":[{"val":"start visual mode, mark lines, then do a command (like y-yank)","key":"v"},{"val":"start linewise visual mode","key":"V"},{"val":"move to other end of marked area","key":"o"},{"val":"start visual block mode","key":"Ctrl+v"},{"val":"move to other corner of block","key":"O"},{"val":"mark a word","key":"aw"},{"val":"a block with ()","key":"ab"},{"val":"a block with {}","key":"aB"},{"val":"inner block with ()","key":"ib"},{"val":"inner block with {}","key":"iB"},{"val":"exit visual mode","key":"Esc"}],"Working with multiple files":[{"val":"edit a file in a new buffer","key":":e filename"},{"val":"go to the next buffer","key":":bnext/:bn"},{"val":"go to the previous buffer","key":":bprev/:bp"},{"val":"delete a buffer (close a file)","key":":bd"},{"val":"open a file in a new buffer and split window","key":":sp filename"},{"val":"open a file in a new buffer and vertically split window","key":":vsp filename"},{"val":"split window","key":"Ctrl+ws"},{"val":"switch windows","key":"Ctrl+ww"},{"val":"quit a window","key":"Ctrl+wq"},{"val":"split window vertically","key":"Ctrl+wv"},{"val":"move cursor to next buffer (right)","key":"Ctrl+wh"},{"val":"move cursor to previous buffer (left)","key":"Ctrl+wl"}],"Cursor movement":[{"val":"move cursor left","key":"h"},{"val":"move cursor down","key":"j"},{"val":"move cursor up","key":"k"},{"val":"move cursor right","key":"l"},{"val":"jump forwards to the start of a word","key":"w"},{"val":"jump forwards to the start of a word (words can contain punctuation)","key":"W"},{"val":"jump forwards to the end of a word","key":"e"},{"val":"jump forwards to the end of a word (words can contain punctuation)","key":"E"},{"val":"jump backwards to the start of a word","key":"b"},{"val":"jump backwards to the start of a word (words can contain punctuation)","key":"B"},{"val":"jump to the start of the line","key":"0"},{"val":"jump to the first non-blank character of the line","key":"^"},{"val":"jump to the end of the line","key":"$"},{"val":"go to the last line of the document","key":"G"},{"val":"go to line 5","key":"5G"},{"val":"To the position before the latest jump, or where the last \"m'\" or \"m`\" command was given.","key":"''"}],"Visual commands":[{"val":"shift text right","key":">"},{"val":"shift text left","key":"<"},{"val":"yank (copy) marked text","key":"y"},{"val":"delete marked text","key":"d"},{"val":"switch case","key":"~"}],"Search and replace":[{"val":"search for pattern","key":"/pattern"},{"val":"search backward for pattern","key":"?pattern"},{"val":"repeat search in same direction","key":"n"},{"val":"repeat search in opposite direction","key":"N"},{"val":"replace all old with new throughout file","key":":%s/old/new/g"},{"val":"replace all old with new throughout file with confirmations","key":":%s/old/new/gc"}]},"description":"Text Editor"} \ No newline at end of file From 483728a5660233f4d280b651840d9047af9b9308 Mon Sep 17 00:00:00 2001 From: Zaahir Moolla Date: Sat, 4 Apr 2015 17:43:04 +0000 Subject: [PATCH 38/51] remove old files --- share/goodie/cheat_sheets/ving.json | 1 - 1 file changed, 1 deletion(-) delete mode 120000 share/goodie/cheat_sheets/ving.json diff --git a/share/goodie/cheat_sheets/ving.json b/share/goodie/cheat_sheets/ving.json deleted file mode 120000 index d7c281839..000000000 --- a/share/goodie/cheat_sheets/ving.json +++ /dev/null @@ -1 +0,0 @@ -vimng.json \ No newline at end of file From 50c38f8f81322ced371003ca8cd604a33762ed88 Mon Sep 17 00:00:00 2001 From: Zaahir Moolla Date: Sat, 4 Apr 2015 17:46:11 +0000 Subject: [PATCH 39/51] Add json, css and template files --- share/goodie/cheat_sheets/cheat_sheets.css | 55 ++++ share/goodie/cheat_sheets/detail.handlebars | 31 ++ share/goodie/cheat_sheets/regex.json | 252 ++++++++++++++++ share/goodie/cheat_sheets/tmux.json | 118 ++++++++ share/goodie/cheat_sheets/vim.json | 314 ++++++++++++++++++++ 5 files changed, 770 insertions(+) create mode 100644 share/goodie/cheat_sheets/cheat_sheets.css create mode 100644 share/goodie/cheat_sheets/detail.handlebars create mode 100644 share/goodie/cheat_sheets/regex.json create mode 100644 share/goodie/cheat_sheets/tmux.json create mode 100644 share/goodie/cheat_sheets/vim.json diff --git a/share/goodie/cheat_sheets/cheat_sheets.css b/share/goodie/cheat_sheets/cheat_sheets.css new file mode 100644 index 000000000..242640d43 --- /dev/null +++ b/share/goodie/cheat_sheets/cheat_sheets.css @@ -0,0 +1,55 @@ +.zci--cheat_sheets .cheatsheet__container.chomp { + max-height: none; +} + +.zci--cheat_sheets .cheatsheet__container .cheatsheet__section { + display: none; +} + +.zci--cheat_sheets .cheatsheet__container .cheatsheet__section .g { + display: none; +} + +.zci--cheat_sheets.has-chomp-expanded .cheatsheet__container .cheatsheet__section { + display: inline-block; +} + +.zci--cheat_sheets .cheatsheet__container .cheatsheet__section:nth-child(-n+2) { + display: inline-block; +} + +.zci--cheat_sheets .cheatsheet__container .cheatsheet__section:nth-child(-n+2) .g:nth-child(-n+6) { + display: inline-block; +} + +.zci--cheat_sheets .cheatsheet__container { + overflow: hidden; +} + +.zci--cheat_sheets .cheatsheet__container.compressed { + height: 15em; +} + +.zci--cheat_sheets .cheatsheet__title { + font-weight: bold; + font-size: 1em; + color: #444; +} + +.zci--cheat_sheets .cheatsheet__section { + margin-bottom: 3px; +} + +.zci--cheat_sheets .cheatsheet__data { + display: block; + margin-bottom: 0.4em; + color: #444 +} + +.zci--cheat_sheets .cheatsheet__data code { + background-color: #e0e0e0; + border-radius: 2px; + padding: 2px; + font-weight: bold; + line-height: 1; +} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/detail.handlebars b/share/goodie/cheat_sheets/detail.handlebars new file mode 100644 index 000000000..70203e605 --- /dev/null +++ b/share/goodie/cheat_sheets/detail.handlebars @@ -0,0 +1,31 @@ +

{{name}}

+

{{description}}

+ +
+ + {{#ordered_cheatsheet sections section_order}} +
+
{{name}}
+
+ {{#each items}} +
+ {{key}} +
+
+ {{val}} +
+ {{/each}} +
+
+ {{/ordered_cheatsheet}} +
+ + \ No newline at end of file diff --git a/share/goodie/cheat_sheets/regex.json b/share/goodie/cheat_sheets/regex.json new file mode 100644 index 000000000..f0b01893b --- /dev/null +++ b/share/goodie/cheat_sheets/regex.json @@ -0,0 +1,252 @@ +{ + "name": "Regex Cheat Sheet", + "section_order": ["Anchors", "Character Classes", "POSIX Classes", "Pattern Modifiers", "Escape Sequences", "Quantifiers", "Groups and Ranges", "Assertions", "Special Characters", "String Replacement"], + "sections": { + "Assertions": [{ + "val": "Lookahead assertion", + "key": "?=" + }, { + "val": "Negative lookahead", + "key": "?!" + }, { + "val": "Lookbehind assertion", + "key": "?<=" + }, { + "val": "Negative lookbehind", + "key": "?!= or ?" + }, { + "val": "Condition [if then]", + "key": "?()" + }, { + "val": "Condition [if then else]", + "key": "?()|" + }, { + "val": "Comment", + "key": "?#" + }], + "POSIX Classes": [{ + "val": "Uppercase letters [A-Z]", + "key": "[:upper:]" + }, { + "val": "Lowercase letters [a-z]", + "key": "[:lower:]" + }, { + "val": "All letters [A-Za-z]", + "key": "[:alpha:]" + }, { + "val": "Digits and letters [A-Za-z0-9]", + "key": "[:alnum:]" + }, { + "val": "Digits [0-9]", + "key": "[:digit:]" + }, { + "val": "Hexadecimal digits [0-9a-f]", + "key": "[:xdigit:]" + }, { + "val": "Punctuation", + "key": "[:punct:]" + }, { + "val": "Space and tab [ \\t]", + "key": "[:blank:]" + }, { + "val": "Blank characters [ \\t\\r\\n\\v\\f]", + "key": "[:space:]" + }, { + "val": "Control characters [\\x00-\\x1F\\x7F]", + "key": "[:cntrl:]" + }, { + "val": "Printed characters [\\x21-\\x7E]", + "key": "[:graph:]" + }, { + "val": "Printed characters and spaces [\\x20-\\x7E]", + "key": "[:print:]" + }, { + "val": "Digits, letters and underscore [A-Za-z0-9_]", + "key": "[:word:]" + }], + "Groups and Ranges": [{ + "val": "Any character except newline (\\n)", + "key": "." + }, { + "val": "a or b", + "key": "(a|b)" + }, { + "val": "Group", + "key": "(...)" + }, { + "val": "Passive (non-capturing) group", + "key": "(?:...)" + }, { + "val": "Single character (a or b or c)", + "key": "[abc]" + }, { + "val": "Single character (not a or b or c)", + "key": "[^abc]" + }, { + "val": "Single character range (a or b ... or q)", + "key": "[a-q]" + }, { + "val": "Single character range (A or B ... or Z)", + "key": "[A-Z]" + }, { + "val": "Single digit from 0 to 9", + "key": "[0-9]" + }], + "Special Characters": [{ + "val": "New line", + "key": "\\n" + }, { + "val": "Carriage return", + "key": "\\r" + }, { + "val": "Tab", + "key": "\\t" + }, { + "val": "Vertical tab", + "key": "\\v" + }, { + "val": "Form feed", + "key": "\\f" + }, { + "val": "Octal character ooo", + "key": "\\ooo" + }, { + "val": "Hex character hh", + "key": "\\xhh" + }], + "Escape Sequences": [{ + "val": "Escape following character", + "key": "\\" + }, { + "val": "Begin literal sequence", + "key": "\\Q" + }, { + "val": "End literal sequence", + "key": "\\E" + }], + "Pattern Modifiers": [{ + "val": "Global Match (all occurrences)", + "key": "//g" + }, { + "val": "Case-insensitive", + "key": "//i" + }, { + "val": "Multiple line", + "key": "//m" + }, { + "val": "Treat string as single line", + "key": "//s" + }, { + "val": "Allow comments and whitespace", + "key": "//x" + }, { + "val": "Evaluate replacement", + "key": "//e" + }, { + "val": "Ungreedy pattern", + "key": "//U" + }], + "Quantifiers": [{ + "val": "0 or more", + "key": "*" + }, { + "val": "1 or more", + "key": "+" + }, { + "val": "0 or 1 (optional)", + "key": "?" + }, { + "val": "Exactly 3", + "key": "{3}" + }, { + "val": "3 or more", + "key": "{3,}" + }, { + "val": "2, 3, 4 or 5", + "key": "{2,5}" + }], + "String Replacement": [{ + "val": "n-th non-passive group", + "key": "$n" + }, { + "val": "\"xyz\" in /^(abc(xyz))$/", + "key": "$2" + }, { + "val": "\"xyz\" in /^(?:abc)(xyz)$/", + "key": "$1" + }, { + "val": "Before matched string", + "key": "$`" + }, { + "val": "After matched string", + "key": "$'" + }, { + "val": "Last matched string", + "key": "$+" + }, { + "val": "Entire matched string", + "key": "$&" + }], + "Character Classes": [{ + "val": "Control character", + "key": "\\c" + }, { + "val": "Whitespace", + "key": "\\s" + }, { + "val": "Not Whitespace", + "key": "\\S" + }, { + "val": "Digit", + "key": "\\d" + }, { + "val": "Not digit", + "key": "\\D" + }, { + "val": "Word", + "key": "\\w" + }, { + "val": "Not Word", + "key": "\\W" + }, { + "val": "Hexadecimal digit", + "key": "\\x" + }, { + "val": "Octal Digit", + "key": "\\O" + }], + "Anchors": [{ + "val": "Start of string or line", + "key": "^" + }, { + "val": "Start of string", + "key": "\\A" + }, { + "val": "End of string or line", + "key": "$" + }, { + "val": "End of string", + "key": "\\Z" + }, { + "val": "Word boundary", + "key": "\\b" + }, { + "val": "Not word boundary", + "key": "\\B" + }, { + "val": "Start of word", + "key": "\\<" + }, { + "val": "End of word", + "key": "\\>" + }] + }, + "description": "Regular expression syntax", + "meta": { + "sourceName": "?", + "sourceURL": "" + } +} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/tmux.json b/share/goodie/cheat_sheets/tmux.json new file mode 100644 index 000000000..fd50578ff --- /dev/null +++ b/share/goodie/cheat_sheets/tmux.json @@ -0,0 +1,118 @@ +{ + "name": "tmux", + "description": "Terminal multiplexer", + "meta": { + "sourceName": "OpenBSD", + "sourceURL": "http://www.openbsd.org/cgi-bin/man.cgi?query=tmux&sektion=1" + }, + "section_order": ["Session Control (from the command line)", "Pane Control", "Window Control", "Copy-Mode (Emacs)", "Copy-Mode (vi)"], + "sections": { + "Copy-Mode (Emacs)": [{ + "val": "Enter copy mode", + "key": "Ctrl-B [" + }, { + "val": "Bottom of history", + "key": "Ctrl-B M-<" + }, { + "val": "Top of histroy", + "key": "Ctrl-B M->" + }, { + "val": "Copy selection", + "key": "Ctrl-B M-w" + }, { + "val": "Paste selection", + "key": "Ctrl-B M-y" + }, { + "val": "Cursor Up", + "key": "Ctrl-B Up" + }, { + "val": "Cursor Down", + "key": "Ctrl-B Down" + }, { + "val": "Cursor Left", + "key": "Ctrl-B Left" + }, { + "val": "Cursor Right", + "key": "Ctrl-B Right" + }], + "Window Control": [{ + "val": "Create new window", + "key": "Ctrl-B c" + }, { + "val": "Detach from session", + "key": "Ctrl-B d" + }, { + "val": "Rename a window", + "key": "Ctrl-B ," + }, { + "val": "List windows", + "key": "Ctrl-B w" + }], + "Pane Control": [{ + "val": "Split pane horizontally", + "key": "Ctrl-B \"" + }, { + "val": "Split pane vertically", + "key": "Ctrl-B %" + }, { + "val": "Next pane", + "key": "Ctrl-B o" + }, { + "val": "Previous pane", + "key": "Ctrl-B ;" + }, { + "val": "Kill current pane", + "key": "Ctrl-B x" + }, { + "val": "Kill all panes but the current one", + "key": "Ctrl-B !" + }, { + "val": "Swap panes", + "key": "Ctrl-B Ctrl-O" + }, { + "val": "Display clock", + "key": "Ctrl-B t" + }, { + "val": "Transpose two letters (delete and paste)", + "key": "Ctrl-B q" + }], + "Copy-Mode (vi)": [{ + "val": "Enter copy mode", + "key": "Ctrl-B [" + }, { + "val": "Bottom of history", + "key": "Ctrl-B G" + }, { + "val": "Top of histroy", + "key": "Ctrl-B g" + }, { + "val": "Copy selection", + "key": "Ctrl-B Enter" + }, { + "val": "Paste selection", + "key": "Ctrl-B p" + }, { + "val": "Cursor Up", + "key": "Ctrl-B k" + }, { + "val": "Cursor Down", + "key": "Ctrl-B j" + }, { + "val": "Cursor Left", + "key": "Ctrl-B h" + }, { + "val": "Cursor Right", + "key": "Ctrl-B l" + }], + "Session Control (from the command line)": [{ + "val": "Start a new session", + "key": "tmux" + }, { + "val": "Re-attach a detached session", + "key": "tmux attach" + }, { + "val": "Re-attach a detached session (and detach it from elsewhere)", + "key": "tmux attach -d" + }] + } +} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/vim.json b/share/goodie/cheat_sheets/vim.json new file mode 100644 index 000000000..97e058e41 --- /dev/null +++ b/share/goodie/cheat_sheets/vim.json @@ -0,0 +1,314 @@ +{ + "name": "Vim", + "description": "Text Editor", + "meta": { + "sourceName": "VimCheatSheet", + "sourceUrl": "https://duckduckgo.com" + }, + "section_order": [ + "Cursor movement", + "Insert mode - inserting/appending text", + "Editing", + "Marking text (visual mode)", + "Visual commands", + "Cut and paste", + "Exiting", + "Search and replace", + "Working with multiple files", + "Tabs" + ], + "sections": { + "Tabs": [{ + "val": "open a file in a new tab", + "key": ":tabnew filename, :tabn filename" + }, { + "val": "move the current split window into its own tab", + "key": "Ctrl+wt" + }, { + "val": "move to the next tab", + "key": "gt, :tabnext, :tabn" + }, { + "val": "move to the previous tab", + "key": "gT, :tabprev, :tabp" + }, { + "val": "move to tab number #", + "key": "#gt" + }, { + "val": "move current tab to the #th position (indexed from 0)", + "key": ":tabmove #" + }, { + "val": "close the current tab and all its windows", + "key": ":tabclose/:tabc" + }, { + "val": "close all tabs except for the current one", + "key": ":tabonly/:tabo" + }], + "Editing": [{ + "val": "replace a single character", + "key": "r" + }, { + "val": "join line below to the current one", + "key": "J" + }, { + "val": "change (replace) entire line", + "key": "cc" + }, { + "val": "change (replace) to the end of the word", + "key": "cw" + }, { + "val": "change (replace) to the end of the line", + "key": "c$" + }, { + "val": "delete character and substitute text", + "key": "s" + }, { + "val": "delete line and substitute text (same as cc)", + "key": "S" + }, { + "val": "transpose two letters (delete and paste)", + "key": "xp" + }, { + "val": "undo", + "key": "u" + }, { + "val": "redo", + "key": "Ctrl+r" + }, { + "val": "repeat last command", + "key": "." + }], + "Exiting": [{ + "val": "write (save) the file, but don't exit", + "key": ":w" + }, { + "val": "write (save) and quit", + "key": ":wq" + }, { + "val": "write (save) and quit", + "key": ":x" + }, { + "val": "quit (fails if there are unsaved changes)", + "key": ":q" + }, { + "val": "quit and throw away unsaved changes", + "key": ":q!" + }], + "Insert mode - inserting/appending text": [{ + "val": "insert before the cursor", + "key": "i" + }, { + "val": "insert at the beginning of the line", + "key": "I" + }, { + "val": "insert (append) after the cursor", + "key": "a" + }, { + "val": "insert (append) at the end of the line", + "key": "A" + }, { + "val": "append (open) a new line below the current line", + "key": "o" + }, { + "val": "append (open) a new line above the current line", + "key": "O" + }, { + "val": "insert (append) at the end of the word", + "key": "ea" + }, { + "val": "exit insert mode", + "key": "Esc" + }], + "Cut and paste": [{ + "val": "yank (copy) a line", + "key": "yy" + }, { + "val": "yank (copy) 2 lines", + "key": "2yy" + }, { + "val": "yank (copy) word", + "key": "yw" + }, { + "val": "yank (copy) to end of line", + "key": "y$" + }, { + "val": "put (paste) the clipboard after cursor", + "key": "p" + }, { + "val": "put (paste) before cursor", + "key": "P" + }, { + "val": "delete (cut) a line", + "key": "dd" + }, { + "val": "delete (cut) 2 lines", + "key": "2dd" + }, { + "val": "delete (cut) word", + "key": "dw" + }, { + "val": "delete (cut) to the end of the line", + "key": "D" + }, { + "val": "delete (cut) to the end of the line", + "key": "d$" + }, { + "val": "delete (cut) character", + "key": "x" + }], + "Marking text (visual mode)": [{ + "val": "start visual mode, mark lines, then do a command (like y-yank)", + "key": "v" + }, { + "val": "start linewise visual mode", + "key": "V" + }, { + "val": "move to other end of marked area", + "key": "o" + }, { + "val": "start visual block mode", + "key": "Ctrl+v" + }, { + "val": "move to other corner of block", + "key": "O" + }, { + "val": "mark a word", + "key": "aw" + }, { + "val": "a block with ()", + "key": "ab" + }, { + "val": "a block with {}", + "key": "aB" + }, { + "val": "inner block with ()", + "key": "ib" + }, { + "val": "inner block with {}", + "key": "iB" + }, { + "val": "exit visual mode", + "key": "Esc" + }], + "Working with multiple files": [{ + "val": "edit a file in a new buffer", + "key": ":e filename" + }, { + "val": "go to the next buffer", + "key": ":bnext/:bn" + }, { + "val": "go to the previous buffer", + "key": ":bprev/:bp" + }, { + "val": "delete a buffer (close a file)", + "key": ":bd" + }, { + "val": "open a file in a new buffer and split window", + "key": ":sp filename" + }, { + "val": "open a file in a new buffer and vertically split window", + "key": ":vsp filename" + }, { + "val": "split window", + "key": "Ctrl+ws" + }, { + "val": "switch windows", + "key": "Ctrl+ww" + }, { + "val": "quit a window", + "key": "Ctrl+wq" + }, { + "val": "split window vertically", + "key": "Ctrl+wv" + }, { + "val": "move cursor to next buffer (right)", + "key": "Ctrl+wh" + }, { + "val": "move cursor to previous buffer (left)", + "key": "Ctrl+wl" + }], + "Cursor movement": [{ + "val": "move cursor left", + "key": "h" + }, { + "val": "move cursor down", + "key": "j" + }, { + "val": "move cursor up", + "key": "k" + }, { + "val": "move cursor right", + "key": "l" + }, { + "val": "jump forwards to the start of a word", + "key": "w" + }, { + "val": "jump forwards to the start of a word (words can contain punctuation)", + "key": "W" + }, { + "val": "jump forwards to the end of a word", + "key": "e" + }, { + "val": "jump forwards to the end of a word (words can contain punctuation)", + "key": "E" + }, { + "val": "jump backwards to the start of a word", + "key": "b" + }, { + "val": "jump backwards to the start of a word (words can contain punctuation)", + "key": "B" + }, { + "val": "jump to the start of the line", + "key": "0" + }, { + "val": "jump to the first non-blank character of the line", + "key": "^" + }, { + "val": "jump to the end of the line", + "key": "$" + }, { + "val": "go to the last line of the document", + "key": "G" + }, { + "val": "go to line 5", + "key": "5G" + }, { + "val": "To the position before the latest jump, or where the last \"m'\" or \"m`\" command was given.", + "key": "''" + }], + "Visual commands": [{ + "val": "shift text right", + "key": ">" + }, { + "val": "shift text left", + "key": "<" + }, { + "val": "yank (copy) marked text", + "key": "y" + }, { + "val": "delete marked text", + "key": "d" + }, { + "val": "switch case", + "key": "~" + }], + "Search and replace": [{ + "val": "search for pattern", + "key": "/pattern" + }, { + "val": "search backward for pattern", + "key": "?pattern" + }, { + "val": "repeat search in same direction", + "key": "n" + }, { + "val": "repeat search in opposite direction", + "key": "N" + }, { + "val": "replace all old with new throughout file", + "key": ":%s/old/new/g" + }, { + "val": "replace all old with new throughout file with confirmations", + "key": ":%s/old/new/gc" + }] + } +} \ No newline at end of file From 45b3318d5d9495828601881faae16ed69d6fe8db Mon Sep 17 00:00:00 2001 From: organiker Date: Sat, 4 Apr 2015 18:07:54 +0000 Subject: [PATCH 40/51] Created my first Goodie --- lib/DDG/Goodie/IsAwesome/organiker.pm | 47 +++++++++++++++++++++++++++ t/IsAwesome/organiker.t | 19 +++++++++++ 2 files changed, 66 insertions(+) create mode 100644 lib/DDG/Goodie/IsAwesome/organiker.pm create mode 100644 t/IsAwesome/organiker.t diff --git a/lib/DDG/Goodie/IsAwesome/organiker.pm b/lib/DDG/Goodie/IsAwesome/organiker.pm new file mode 100644 index 000000000..04ea8b1dc --- /dev/null +++ b/lib/DDG/Goodie/IsAwesome/organiker.pm @@ -0,0 +1,47 @@ +package DDG::Goodie::IsAwesome::organiker; +# ABSTRACT: Write an abstract here +# Start at https://duck.co/duckduckhack/goodie_overview if you are new +# to instant answer development + +use DDG::Goodie; + +zci answer_type => "is_awesome_organiker"; +zci is_cached => 1; + +# Metadata. See https://duck.co/duckduckhack/metadata for help in filling out this section. +name "IsAwesome organiker"; +description "Succinct explanation of what this instant answer does"; +primary_example_queries "first example query", "second example query"; +secondary_example_queries "optional -- demonstrate any additional triggers"; +# Uncomment and complete: https://duck.co/duckduckhack/metadata#category +# category ""; +# Uncomment and complete: https://duck.co/duckduckhack/metadata#topics +# topics ""; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsAwesome/organiker.pm"; +attribution github => ["GitHubAccount", "Friendly Name"], + twitter => "twitterhandle"; + +# Triggers +# triggers any => "triggerWord", "trigger phrase"; +triggers start => "duckduckhack organiker"; + +# Handle statement +# handle remainder => sub { + +# # optional - regex guard +# # return unless qr/^\w+/; + +# return unless $_; # Guard against "no answer" + +# return $_; +# }; + +handle remainder => sub { + + return "organiker is awesome and has successfully completed the DuckDuckHack Goodie tutorial!"; +}; + + + + +1; diff --git a/t/IsAwesome/organiker.t b/t/IsAwesome/organiker.t new file mode 100644 index 000000000..1b34bc408 --- /dev/null +++ b/t/IsAwesome/organiker.t @@ -0,0 +1,19 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => "is_awesome_organiker"; +zci is_cached => 1; + +ddg_goodie_test( + [qw( + DDG::Goodie::IsAwesome::organiker + )], + 'duckduckhack organiker' => test_zci('organiker is awesome and has successfully completed the DuckDuckHack Goodie tutorial!'), + 'duckduckhack organiker is awesome' => undef, +); + +done_testing; From a97b18a0f35c8c24ff91147f0b911f918ff4a35e Mon Sep 17 00:00:00 2001 From: organiker Date: Sat, 4 Apr 2015 18:51:48 +0000 Subject: [PATCH 41/51] Oops save on Codio --- lib/DDG/Goodie/IsAwesome/organiker.pm | 40 ++++++--------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/lib/DDG/Goodie/IsAwesome/organiker.pm b/lib/DDG/Goodie/IsAwesome/organiker.pm index 04ea8b1dc..035940cd1 100644 --- a/lib/DDG/Goodie/IsAwesome/organiker.pm +++ b/lib/DDG/Goodie/IsAwesome/organiker.pm @@ -1,47 +1,25 @@ package DDG::Goodie::IsAwesome::organiker; -# ABSTRACT: Write an abstract here -# Start at https://duck.co/duckduckhack/goodie_overview if you are new -# to instant answer development +# ABSTRACT: organiker's first Goodie use DDG::Goodie; zci answer_type => "is_awesome_organiker"; zci is_cached => 1; -# Metadata. See https://duck.co/duckduckhack/metadata for help in filling out this section. name "IsAwesome organiker"; -description "Succinct explanation of what this instant answer does"; -primary_example_queries "first example query", "second example query"; -secondary_example_queries "optional -- demonstrate any additional triggers"; -# Uncomment and complete: https://duck.co/duckduckhack/metadata#category -# category ""; -# Uncomment and complete: https://duck.co/duckduckhack/metadata#topics -# topics ""; -code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsAwesome/organiker.pm"; -attribution github => ["GitHubAccount", "Friendly Name"], - twitter => "twitterhandle"; +description "My first Goodie, it lets the world know that organiker is awesome"; +primary_example_queries "duckduckhack organiker"; +category "special"; +topics "special_interest", "geek"; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsAwesome/GitHubUsername.pm"; +attribution github => ["https://github.com/organiker", "organiker"], + twitter => "jiyeonorganiker"; -# Triggers -# triggers any => "triggerWord", "trigger phrase"; triggers start => "duckduckhack organiker"; -# Handle statement -# handle remainder => sub { - -# # optional - regex guard -# # return unless qr/^\w+/; - -# return unless $_; # Guard against "no answer" - -# return $_; -# }; - handle remainder => sub { - + return if $_; return "organiker is awesome and has successfully completed the DuckDuckHack Goodie tutorial!"; }; - - - 1; From df608837e94a0fd20e87ca67160afec6c4badf4b Mon Sep 17 00:00:00 2001 From: rramyr Date: Sun, 5 Apr 2015 02:13:23 +0000 Subject: [PATCH 42/51] Created my first Goodie --- lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm | 27 ++++++++++++++++++++++++ t/IsAwesome/GitHubrramyr.t | 19 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm create mode 100644 t/IsAwesome/GitHubrramyr.t diff --git a/lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm b/lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm new file mode 100644 index 000000000..bf2467d37 --- /dev/null +++ b/lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm @@ -0,0 +1,27 @@ +package DDG::Goodie::IsAwesome::GitHubrramyr; +# ABSTRACT: GitHubrramyr's first Goodie +# # Start at https://duck.co/duckduckhack/goodie_overview if you are new +# to instant answer development + +use DDG::Goodie; + +zci answer_type => "is_awesome_git_hubrramyr"; +zci is_cached => 1; + +name "IsAwesome GitHubrramyr"; +description "My first Goodie, it lets the world know that GitHubUsername is awesome"; +primary_example_queries "duckduckhack GitHubrramyr"; +category "special"; +topics "special_interest", "geek"; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm"; +attribution github => ["https://github.com/GitHubUsername", "GitHubrramyr"]; + + +triggers any => "duckduckhack githubrramyr"; + +handle remainder => sub { + return if $_; + return "GitHubrramyr is awesome and has successfully completed the DuckDuckHack Goodie tutorial!"; +}; + +1; diff --git a/t/IsAwesome/GitHubrramyr.t b/t/IsAwesome/GitHubrramyr.t new file mode 100644 index 000000000..57449c4b1 --- /dev/null +++ b/t/IsAwesome/GitHubrramyr.t @@ -0,0 +1,19 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => "is_awesome_git_hubrramyr"; +zci is_cached => 1; + +ddg_goodie_test( + [qw( + DDG::Goodie::IsAwesome::GitHubrramyr + )], + 'duckduckhack GitHubrramyr' => test_zci('GitHubrramyr is awesome and has successfully completed the DuckDuckHack Goodie tutorial!'), + 'duckduckhack GitHubrramyr is awesome' => undef, +); + +done_testing; From 054c199ac397fc2e4d4134f965ed40749af5fa83 Mon Sep 17 00:00:00 2001 From: Josh Klein Date: Sun, 5 Apr 2015 18:41:14 +0000 Subject: [PATCH 43/51] Created my first Goodie --- lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm | 27 ++++++++++++++++++++++++ t/IsAwesome/kleinjoshuaa.t | 18 ++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm create mode 100644 t/IsAwesome/kleinjoshuaa.t diff --git a/lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm b/lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm new file mode 100644 index 000000000..997bb54a7 --- /dev/null +++ b/lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm @@ -0,0 +1,27 @@ +package DDG::Goodie::IsAwesome::kleinjoshuaa; +# ABSTRACT: kleinjoshuaa's first goodie + + +use DDG::Goodie; + +zci answer_type => "is_awesome_kleinjoshuaa"; +zci is_cached => 1; + +name "IsAwesome kleinjoshuaa"; +description "My first Goodie, it lets the world know that kleinjoshuaa is awesome"; +primary_example_queries "duckduckhack kleinjoshuaa"; +category "special"; +topics "special_interest", "geek"; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm"; +attribution github => ["https://github.com/kleinjoshuaa", "kleinjoshuaa"]; + +# Triggers +triggers start => "duckduckhack kleinjoshuaa"; + +# Handle statement +handle remainder => sub { + return if $_; + return "kleinjoshuaa is awesome and has successfully completed the duckduckhack goodie tutorial!"; +}; + +1; diff --git a/t/IsAwesome/kleinjoshuaa.t b/t/IsAwesome/kleinjoshuaa.t new file mode 100644 index 000000000..3030feb38 --- /dev/null +++ b/t/IsAwesome/kleinjoshuaa.t @@ -0,0 +1,18 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => "is_awesome_kleinjoshuaa"; +zci is_cached => 1; + +ddg_goodie_test( + [qw( DDG::Goodie::IsAwesome::kleinjoshuaa )], + 'duckduckhack kleinjoshuaa' => test_zci('kleinjoshuaa is awesome and has successfully completed the duckduckhack goodie tutorial!'), + 'duckduckhack kleinjoshuaa is awesome' => undef, + +); + +done_testing; From fc8a4b5ca8b939b3eee899be1a1d804b376567fe Mon Sep 17 00:00:00 2001 From: Medowar Date: Mon, 6 Apr 2015 00:38:32 +0200 Subject: [PATCH 44/51] adding opendns ipv6 adresses(see https://www.opendns.com/about/innovations/ipv6/) --- share/goodie/public_dns/providers.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/share/goodie/public_dns/providers.yml b/share/goodie/public_dns/providers.yml index 7f4288f2c..35d3141ce 100644 --- a/share/goodie/public_dns/providers.yml +++ b/share/goodie/public_dns/providers.yml @@ -30,4 +30,6 @@ OpenDNS: ip4: - 208.67.222.222 - 208.67.220.220 - ip6: [] + ip6: + - 2620:0:ccc::2 + - 2620:0:ccd::2 From 7b235e3f540c218d37fcb9a3bf9f38df5c085ea5 Mon Sep 17 00:00:00 2001 From: Josh Klein Date: Mon, 6 Apr 2015 00:42:17 +0000 Subject: [PATCH 45/51] Added use strict --- lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm b/lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm index 997bb54a7..eec5b6a34 100644 --- a/lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm +++ b/lib/DDG/Goodie/IsAwesome/kleinjoshuaa.pm @@ -3,6 +3,7 @@ package DDG::Goodie::IsAwesome::kleinjoshuaa; use DDG::Goodie; +use strict; zci answer_type => "is_awesome_kleinjoshuaa"; zci is_cached => 1; From 2c0d6fd067130d344a10ec3cf2d14b5390304633 Mon Sep 17 00:00:00 2001 From: rramyr Date: Mon, 6 Apr 2015 05:03:44 +0000 Subject: [PATCH 46/51] Created my first Goodie --- lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm | 27 ------------------------ lib/DDG/Goodie/IsAwesome/rramyr.pm | 24 +++++++++++++++++++++ sub | 0 t/IsAwesome/GitHubrramyr.t | 19 ----------------- t/IsAwesome/rramyr.t | 19 +++++++++++++++++ 5 files changed, 43 insertions(+), 46 deletions(-) delete mode 100644 lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm create mode 100644 lib/DDG/Goodie/IsAwesome/rramyr.pm create mode 100644 sub delete mode 100644 t/IsAwesome/GitHubrramyr.t create mode 100644 t/IsAwesome/rramyr.t diff --git a/lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm b/lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm deleted file mode 100644 index bf2467d37..000000000 --- a/lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm +++ /dev/null @@ -1,27 +0,0 @@ -package DDG::Goodie::IsAwesome::GitHubrramyr; -# ABSTRACT: GitHubrramyr's first Goodie -# # Start at https://duck.co/duckduckhack/goodie_overview if you are new -# to instant answer development - -use DDG::Goodie; - -zci answer_type => "is_awesome_git_hubrramyr"; -zci is_cached => 1; - -name "IsAwesome GitHubrramyr"; -description "My first Goodie, it lets the world know that GitHubUsername is awesome"; -primary_example_queries "duckduckhack GitHubrramyr"; -category "special"; -topics "special_interest", "geek"; -code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsAwesome/GitHubrramyr.pm"; -attribution github => ["https://github.com/GitHubUsername", "GitHubrramyr"]; - - -triggers any => "duckduckhack githubrramyr"; - -handle remainder => sub { - return if $_; - return "GitHubrramyr is awesome and has successfully completed the DuckDuckHack Goodie tutorial!"; -}; - -1; diff --git a/lib/DDG/Goodie/IsAwesome/rramyr.pm b/lib/DDG/Goodie/IsAwesome/rramyr.pm new file mode 100644 index 000000000..c1b1cc0e8 --- /dev/null +++ b/lib/DDG/Goodie/IsAwesome/rramyr.pm @@ -0,0 +1,24 @@ +package DDG::Goodie::IsAwesome::rramyr; + +use DDG::Goodie; + +zci answer_type => "is_awesome_rramyr"; +zci is_cached => 1; + +name "IsAwesome rramyr"; +description "My first Goodie, it lets the world know that GitHubUsername is awesome"; +primary_example_queries "duckduckhack rramyr"; +category "special"; +topics "special_interest", "geek"; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsAwesome/rramyr.pm"; +attribution github => ["https://github.com/rramyr", "rramyr"]; + + +triggers any => "duckduckhack rramyr"; + +handle remainder => sub { + return if $_; + return "rramyr is awesome and has successfully completed the DuckDuckHack Goodie tutorial!"; +}; + +1; diff --git a/sub b/sub new file mode 100644 index 000000000..e69de29bb diff --git a/t/IsAwesome/GitHubrramyr.t b/t/IsAwesome/GitHubrramyr.t deleted file mode 100644 index 57449c4b1..000000000 --- a/t/IsAwesome/GitHubrramyr.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use Test::More; -use DDG::Test::Goodie; - -zci answer_type => "is_awesome_git_hubrramyr"; -zci is_cached => 1; - -ddg_goodie_test( - [qw( - DDG::Goodie::IsAwesome::GitHubrramyr - )], - 'duckduckhack GitHubrramyr' => test_zci('GitHubrramyr is awesome and has successfully completed the DuckDuckHack Goodie tutorial!'), - 'duckduckhack GitHubrramyr is awesome' => undef, -); - -done_testing; diff --git a/t/IsAwesome/rramyr.t b/t/IsAwesome/rramyr.t new file mode 100644 index 000000000..9eb28dd19 --- /dev/null +++ b/t/IsAwesome/rramyr.t @@ -0,0 +1,19 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => "is_awesome_rramyr"; +zci is_cached => 1; + +ddg_goodie_test( + [qw( + DDG::Goodie::IsAwesome::rramyr + )], + 'duckduckhack rramyr' => test_zci('rramyr is awesome and has successfully completed the DuckDuckHack Goodie tutorial!'), + 'duckduckhack rramyr is awesome' => undef, +); + +done_testing; \ No newline at end of file From 8c5a4c23dfe65f390d8f75cf0214d9639834942f Mon Sep 17 00:00:00 2001 From: rramyr Date: Mon, 6 Apr 2015 05:57:30 +0000 Subject: [PATCH 47/51] Created my first Goodie --- lib/DDG/Goodie/IsAwesome/rramyr.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/IsAwesome/rramyr.pm b/lib/DDG/Goodie/IsAwesome/rramyr.pm index c1b1cc0e8..19d1e67bc 100644 --- a/lib/DDG/Goodie/IsAwesome/rramyr.pm +++ b/lib/DDG/Goodie/IsAwesome/rramyr.pm @@ -1,4 +1,5 @@ package DDG::Goodie::IsAwesome::rramyr; +# ABSTRACT: GitHubrramyr's first Goodie use DDG::Goodie; @@ -6,7 +7,7 @@ zci answer_type => "is_awesome_rramyr"; zci is_cached => 1; name "IsAwesome rramyr"; -description "My first Goodie, it lets the world know that GitHubUsername is awesome"; +description "My first Goodie, it lets the world know that rramyr is awesome"; primary_example_queries "duckduckhack rramyr"; category "special"; topics "special_interest", "geek"; From a3b629547225b62c8179a23a27cdbfb27f5413d1 Mon Sep 17 00:00:00 2001 From: Zaahir Moolla Date: Tue, 7 Apr 2015 00:09:28 +0000 Subject: [PATCH 48/51] fixed display bugs, manually show/hide content --- share/goodie/cheat_sheets/cheat_sheets.css | 18 ++++++------------ share/goodie/cheat_sheets/cheat_sheets.js | 8 +++----- share/goodie/cheat_sheets/detail.handlebars | 4 ++-- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/share/goodie/cheat_sheets/cheat_sheets.css b/share/goodie/cheat_sheets/cheat_sheets.css index 242640d43..cb3bf4257 100644 --- a/share/goodie/cheat_sheets/cheat_sheets.css +++ b/share/goodie/cheat_sheets/cheat_sheets.css @@ -1,16 +1,14 @@ -.zci--cheat_sheets .cheatsheet__container.chomp { - max-height: none; +.zci--cheat_sheets .cheatsheet__container.compressed { + max-height: 20em; } -.zci--cheat_sheets .cheatsheet__container .cheatsheet__section { +.zci--cheat_sheets .cheatsheet__container.compressed .cheatsheet__section, +.zci--cheat_sheets .cheatsheet__container.compressed .cheatsheet__section .g { display: none; } -.zci--cheat_sheets .cheatsheet__container .cheatsheet__section .g { - display: none; -} - -.zci--cheat_sheets.has-chomp-expanded .cheatsheet__container .cheatsheet__section { +.zci--cheat_sheets .cheatsheet__section, +.zci--cheat_sheets .cheatsheet__section .g { display: inline-block; } @@ -26,10 +24,6 @@ overflow: hidden; } -.zci--cheat_sheets .cheatsheet__container.compressed { - height: 15em; -} - .zci--cheat_sheets .cheatsheet__title { font-weight: bold; font-size: 1em; diff --git a/share/goodie/cheat_sheets/cheat_sheets.js b/share/goodie/cheat_sheets/cheat_sheets.js index fa6e8a9e4..4d8f1d534 100644 --- a/share/goodie/cheat_sheets/cheat_sheets.js +++ b/share/goodie/cheat_sheets/cheat_sheets.js @@ -16,16 +16,14 @@ DDH.cheat_sheets.build = function(ops) { onShow: function() { var $dom = $("#zci-cheat_sheets"), $container = $dom.find(".cheatsheet__container"), - $more_btn = $dom.find("#show_more"), + $more_btn = $dom.find(".chomp--link"), $icon = $more_btn.find(".chomp--link__icn"), $more = $more_btn.find(".chomp--link__mr"), $less = $more_btn.find(".chomp--link__ls"); $more_btn.click(function() { - $container.toggle("compressed"); - $more.toggle(); - $less.toggle(); - $icon.toggleClass("expand"); + $dom.toggleClass("has-chomp-expanded"); + $container.toggleClass("compressed"); }); } }; diff --git a/share/goodie/cheat_sheets/detail.handlebars b/share/goodie/cheat_sheets/detail.handlebars index 70203e605..a6af13dd1 100644 --- a/share/goodie/cheat_sheets/detail.handlebars +++ b/share/goodie/cheat_sheets/detail.handlebars @@ -1,7 +1,7 @@

{{name}}

{{description}}

-
+
{{#ordered_cheatsheet sections section_order}}
@@ -22,7 +22,7 @@