Skip to content

Instantly share code, notes, and snippets.

View PatrickCronin's full-sized avatar

Patrick Cronin PatrickCronin

View GitHub Profile
@PatrickCronin
PatrickCronin / gist:8af88459cd3de23c01bc20cfb91044d8
Created May 6, 2021 15:38
Mojo::DOM text nodes dodge ->text and ->all_text?
> perl -MMojo::DOM -E'$x=Mojo::DOM->new("<span>1</span> a <span>2</span>")->child_nodes->each(sub{ say $_->type . " node `$_` (" . $_->all_text . ") has length " . length($_->all_text) })';
tag node `<span>1</span>` (1) has length 1
text node ` a ` () has length 0
tag node `<span>2</span>` (2) has length 1
>
#!/usr/local/bin/perl
use strict;
use warnings;
my $sql = <<~'SQL';
SELECT *
FROM some_table
SQL
my @vals = (<<'SQL', 1);
SELECT *
FROM the_table
WHERE id=$1
SQL
my @vals = (<<~'SQL', 1);
SELECT *
FROM the_table
WHERE id=$1
#!/usr/bin/perl
use strict;
use warnings;
# The #__ correspond to the pattern # being tested.
#23: double-quoted terminator, embedded HTML
my @double_quoted_html = (<<"HTML", 1);
<i>some text</i>
foreach inputs as $in (
{};
if has("postcode") and has("network") then null
else . as $x
| $in
| if length == 1 and .[0][-1] == "Record" then {}
elif length == 2 and .[0][-1] == "Network" then ($x + {network: .[-1]})
elif length == 2 and .[0][-2] == "postal" and .[0][-1] == "code" and .[-1] == "12061" then ($x + {postcode: .[-1]})
else $x
end
$ docker-compose up
Starting metacpan_elasticsearch_test_1 ... done
Starting metacpan_pgdb_1 ... done
Starting metacpan_logspout_1 ... done
Starting metacpan_elasticsearch_1 ... done
Starting metacpan_web_1 ... done
Starting metacpan_mongodb_1 ... done
Starting metacpan_github-meets-cpan-cron_1 ... done
Starting metacpan_github-meets-cpan_1 ... done
Starting metacpan_api_1 ... done

Bash tips

  • Capture the result of a command as a string: $( <cmd> )
> emacs -nw $(git ls-files | grep the-file)
  • Re-run last command: !!
> git ls-files | grep the-file
@PatrickCronin
PatrickCronin / building-python-openzwave.md
Last active July 12, 2019 21:03
Attempting to build the dev flavor of python-openzwave

Identify platform

[pcronin@cronin src]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[pcronin@cronin src]$ uname -a
Linux cronin 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[pcronin@cronin src]$

Ensure build tools and libs

(virtualenv) -bash-4.2$ pyozw_check -i -d /dev/zstick
-------------------------------------------------------------------------------
Intialize device /dev/zstick
Try to get options
Try to get manager
2019-06-01 15:05:54.237 Always, OpenZwave Version 1.6-417-g3431825-dirty Starting Up
2019-06-01 15:05:54.240 Info, Loading Localization File /home/homeassistant/virtualenv/lib64/python3.6/site-packages/python_openzwave/ozw_config/Localization.xml
2019-06-01 15:05:54.241 Info, Loaded /home/homeassistant/virtualenv/lib64/python3.6/site-packages/python_openzwave/ozw_config/Localization.xml With Revision 6
2019-06-01 15:05:54.241 Always, Using Language Localization
2019-06-01 15:05:54.242 Info, Loading NotificationCCTypes File /home/homeassistant/virtualenv/lib64/python3.6/site-packages/python_openzwave/ozw_config/NotificationCCTypes.xml