IPv6 Resolution in gen_tcp connect when called from Elixir - erlang

When using the connect method of gen_tcp, IPv4 domains are resolved automatically, i.e.:
:gen_tcp.connect('google.com', 443, [:binary, active: false])
{:ok, #Port<0.116>}
However, if resolving an IPv6 domain, it will not resolve correctly
iex(production#b7726c04)3> :gen_tcp.connect('ipv6.google.com', 443, [:binary, active: false])
{:error, :nxdomain}
Am I missing an option with the socket options of :gen_tcp.connect that would enable IPv6 resolution or do I have manually resolve the domain myself before usage? i.e. something like:
:inet_res.resolve('ipv6.google.com', :in, :aaaa)
{:ok,
{:dns_rec, {:dns_header, 1, true, :query, false, false, true, true, false, 0},
[{:dns_query, 'ipv6.google.com', :aaaa, :in, false}],
[
{:dns_rr, 'ipv6.google.com', :cname, :in, 0, 604606, 'ipv6.l.google.com',
:undefined, [], false},
{:dns_rr, 'ipv6.l.google.com', :aaaa, :in, 0, 300,
{9220, 26624, 16387, 3072, 0, 0, 0, 101}, :undefined, [], false},
{:dns_rr, 'ipv6.l.google.com', :aaaa, :in, 0, 300,
{9220, 26624, 16387, 3072, 0, 0, 0, 102}, :undefined, [], false},
{:dns_rr, 'ipv6.l.google.com', :aaaa, :in, 0, 300,
{9220, 26624, 16387, 3072, 0, 0, 0, 113}, :undefined, [], false},
{:dns_rr, 'ipv6.l.google.com', :aaaa, :in, 0, 300,
{9220, 26624, 16387, 3072, 0, 0, 0, 100}, :undefined, [], false}
], [], []}}
Then using the IPv6 tuple directly:
:gen_tcp.connect({9220, 26624, 16387, 3072, 0, 0, 0, 101}, 443, [:binary, active: false])
{:ok, #Port<0.138>}

You can use inet6:
{ok, P} = gen_tcp:connect("ipv6.google.com", 80, [inet6]).
{ok,#Port<0.14>}

Related

Why is Highcharts x axis not respecting my categories in stacked area chart

I have created a stacked area chart in Highcharts at https://jsfiddle.net/kg3b2xyL/ I am feeding the hours as 24 categories (I guess I could have fed timestamps with an X-axis interval instead, but I think either way should work?). Each series correspondingly has 24 entries. Highcharts is charting the data okay and shows all the categories I gave it, but then it adds additional categories for some reason at the end on the right side of the chart, so that the numbers extend to 24 even though my categories started in the middle of the day and the final category in the categories list is 18. Is this a bug in Highcharts? Do I have to switch to feeding timestamps, or is there a way for this to work as I have coded it?
Thanks!
Here is my HTML:
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
And my JavaScript:
Highcharts.chart('container', {
chart: {
type: 'area'
},
legend: {
enabled: false
},
title: {
text: 'Calls to technical support last 24 hours'
},
xAxis: {
title: {
text: 'Time of Day'
},
categories: ['19', '20', '21', '22', '23', '24', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18']
},
yAxis: {
title: {
text: 'Calls during the hour'
},
},
tooltip: {
split: true,
},
plotOptions: {
area: {
stacking: 'normal',
lineColor: '#666666',
lineWidth: 1,
marker: {
lineWidth: 1,
lineColor: '#666666'
}
}
},
series: [
{ name: 'Jane', data: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'John', data: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Julie', data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Walter', data: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Andy', data: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Julio', data: [2, 0, 0, 2, 0, 0, 2, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Rachel', data: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Steven', data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Phil', data: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
]
});
The issue can be resolved by deleting the zeros from Julio nad Reachel data - there are too many zeros.
Demo:
https://jsfiddle.net/BlackLabel/h50m9y72/

Positioning a popup keyboard

I found a plugin from github that pops out a virtual keyboard as you click a textbox/textarea. The problem is, if you have other elements, the keyboard appears at the bottom. I want it to show adjacent the textbox clicked. I tried appending ".position({
my: "left top",
at: "left top",
of: "#targetElement"
});" at the end of the keyboard initializer(last line) but it's not taking effect. Here's the script.
<script type="text/javascript">
$(function(){
var keyboard = {
'layout': [
// alphanumeric keyboard type
// text displayed on keyboard button, keyboard value, keycode, column span, new row
[
[
['`', '`', 192, 0, true], ['1', '1', 49, 0, false], ['2', '2', 50, 0, false], ['3', '3', 51, 0, false], ['4', '4', 52, 0, false], ['5', '5', 53, 0, false], ['6', '6', 54, 0, false],
['7', '7', 55, 0, false], ['8', '8', 56, 0, false], ['9', '9', 57, 0, false], ['0', '0', 48, 0, false], ['-', '-', 189, 0, false], ['=', '=', 187, 0, false],
['q', 'q', 81, 0, true], ['w', 'w', 87, 0, false], ['e', 'e', 69, 0, false], ['r', 'r', 82, 0, false], ['t', 't', 84, 0, false], ['y', 'y', 89, 0, false], ['u', 'u', 85, 0, false],
['i', 'i', 73, 0, false], ['o', 'o', 79, 0, false], ['p', 'p', 80, 0, false], ['[', '[', 219, 0, false], [']', ']', 221, 0, false], ['\', '\\', 220, 0, false],
['a', 'a', 65, 0, true], ['s', 's', 83, 0, false], ['d', 'd', 68, 0, false], ['f', 'f', 70, 0, false], ['g', 'g', 71, 0, false], ['h', 'h', 72, 0, false], ['j', 'j', 74, 0, false],
['k', 'k', 75, 0, false], ['l', 'l', 76, 0, false], [';', ';', 186, 0, false], [''', '\'', 222, 0, false], ['Enter', '13', 13, 3, false],
['Shift', '16', 16, 2, true], ['z', 'z', 90, 0, false], ['x', 'x', 88, 0, false], ['c', 'c', 67, 0, false], ['v', 'v', 86, 0, false], ['b', 'b', 66, 0, false], ['n', 'n', 78, 0, false],
['m', 'm', 77, 0, false], [',', ',', 188, 0, false], ['.', '.', 190, 0, false], ['/', '/', 191, 0, false], ['Shift', '16', 16, 2, false],
['Bksp', '8', 8, 3, true], ['Space', '32', 32, 12, false], ['Clear', '46', 46, 3, false], ['Cancel', '27', 27, 3, false]
]
]
]
}
$('#name.jQKeyboard').initKeypad({'keyboardLayout': keyboard});
});
</script>
If we're talking about: https://github.com/poiyee/jQKeyboard then I would suggest:
$('#name.jQKeyboard').initKeypad({'keyboardLayout': keyboard});
$('#jQKeyboardContainer').position({
my: "left top",
at: "left top",
of: $('#name.jQKeyboard')
});
The plugin is written in an older fashion and I would suggest or consider using $.widget() to write you're own that allows you to set the position as an option.
If you wanted a modern working widget, it would look like this: https://jsfiddle.net/Twisty/mzj9w2yb/4/

TCPDF alignment rendering issue

I'm getting weird alignment issues with TCPDF.
Here's a chunk of my looping code:
$pdf->setColor('text', 255, 255, 255);
$pdf->SetFontSize(20);
$pdf->Cell( 180, 25, $post->post_title, 0, 1, 'R', false, '', 3);
$pdf->Ln(1);
$pdf->setColor('text', 0, 0, 0);
$pdf->SetFontSize(14);
$pdf->Cell( 180, 8, $product->get_sku(), 0, 1, 'R', false);
$pdf->Ln(4);
$pdf->Image( $product->post->thumbnail, 15, 50, 80, 0, 'JPG', '', '', true, 150, '', false, false, 0, false, false, false);
$pdf->SetFontSize(10);
$pdf->MultiCell(90, 0, '', 1, 'C', 1, 0, '', '', true, 0, false, true, 0, 'T');
$pdf->setCellHeightRatio(1.65);
$pdf->MultiCell(90, 0, ($post->post_excerpt ? $post->post_excerpt : 'No description found.'), 1, 'C', 1, 1, '', '', true, 0, true, true, 0);
$pdf->setCellHeightRatio(0);
And here are the results which vary from first line centering for description to the more obvious title alignment even though it is from the same loop :
What gives?
Makes me wonder if I should have just stuck with FPDF...

Has anyone seen this Elixir/Erlang error? [duplicate]

I'm new to Elixir and Erlang and having some issues with accessing https URLs. I've tried the Elixir-specific HTTPotion and Erlang's :inets module.
So from the iex console (Interactive Elixir):
With HTTPotion:
HTTPotion.start
HTTPotion.get("https://api.github.com")
With :inets:
:inets.start
:ssl.start
:httpc.request('https://api.github.com')
In both cases I get a giant stacktrace that essential says there is a bad match somewhere and that a state machine is terminating. I don't get this when accessing http URLs. What am I missing? Thanks.
Edit - here is the error message from HTTPotion:
iex(40)> HTTPotion.get("https://api.github.com")
** (Protocol.UndefinedError) protocol String.Chars not implemented for {:EXIT, {{{{:badmatch, ""}, [{:ssl_handshake, :dec_hello_extensions, 2, [file: 'ssl_handshake.erl', line: 1737]}, {:ssl_handshake, :decode_handshake, 3, [file: 'ssl_handshake.erl', line: 926]}, {:tls_handshake, :get_tls_handshake_aux, 3, [file: 'tls_handshake.erl', line: 155]}, {:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 433]}, {:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 503]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 237]}]}, {:gen_fsm, :sync_send_all_state_event, [#PID<0.227.0>, {:start, 5000}, :infinity]}}, {:gen_server, :call, [#PID<0.226.0>, {:send_req, {{:url, 'https://api.github.com', 'api.github.com', 443, :undefined, :undefined, '/', :https, :hostname}, [], :get, "", [], 5000}}, 5000]}}}
(elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir) lib/string/chars.ex:17: String.Chars.to_string/1
(httpotion) lib/httpotion.ex:157: HTTPotion.request/5
iex(40)>
16:50:10.640 [error] ** State machine #PID<0.227.0> terminating
** Last message in was {:tcp, #Port<0.7454>,
<<22, 3, 3, 0, 93, 2, 0, 0, 89, 3, 3, 84, 40, 158, 178, 2, 216, 45, 226, 183, 79, 42, 199, 205, 19, 31, 63, 223, 138, 208, 132, 186, 28, 129, 123, 235, 1, 142, 90, 243, 25, 70, 210, 32, 199, 56, 251, 131, ...>>}
** When State == :hello
** Data == [data: [{'StateData',
{:state, :client, {#Reference<0.0.0.1360>, #PID<0.226.0>}, :gen_tcp,
:tls_connection, :tcp, :tcp_closed, :tcp_error, 'api.github.com', 443,
#Port<0.7454>,
{:ssl_options, :tls, [{3, 3}, {3, 2}, {3, 1}, {3, 0}], :verify_none,
{#Function<7.50551058/3 in :ssl.handle_verify_options/2>, []},
#Function<8.50551058/1 in :ssl.handle_verify_options/2>, false, false,
:undefined, 1, "", '***', "", '***', '***', '***', "", '***', :undefined,
:undefined, '***', '***',
[<<192, 36>>, <<192, 40>>, <<192, 38>>, <<192, 42>>, <<0, 107>>,
<<0, 106>>, <<0, 61>>, <<192, 35>>, <<192, 39>>, <<192, 37>>, <<192, 41>>,
<<0, 103>>, <<0, ...>>, <<...>>, ...],
#Function<1.50551058/4 in :ssl.handle_options/1>, true, 268435456, false,
:undefined, false, :undefined, :undefined, true, :undefined, false},
{:socket_options, :binary, 0, 0, 0, false}, '***', '***', '***', 49168,
'***', 61463, :ssl_session_cache, {3, 3}, false, :undefined,
{:undefined, :undefined}, :undefined, :undefined, '***', '***', '***',
:undefined, '***', '***', '***', 53269, #Reference<0.0.0.1363>, :undefined,
'***', {false, :first}, {#PID<0.226.0>, #Reference<0.0.0.1361>},
#Reference<0.0.0.1364>, {[], []}, false, true, false, false, :undefined,
:undefined, :undefined}}]]
** Reason for termination =
** {{:badmatch, ""},
[{:ssl_handshake, :dec_hello_extensions, 2,
[file: 'ssl_handshake.erl', line: 1737]},
{:ssl_handshake, :decode_handshake, 3,
[file: 'ssl_handshake.erl', line: 926]},
{:tls_handshake, :get_tls_handshake_aux, 3,
[file: 'tls_handshake.erl', line: 155]},
{:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 433]},
{:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 503]},
{:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 237]}]}
16:50:10.642 [error] GenServer #PID<0.226.0> terminating
Last message: {:send_req, {{:url, 'https://api.github.com', 'api.github.com', 443, :undefined, :undefined, '/', :https, :hostname}, [], :get, "", [], 5000}}
State: {:state, 'api.github.com', 443, :undefined, #Reference<0.0.0.1352>, false, :undefined, [], true, :undefined, false, [], {[], []}, :undefined, :idle, :undefined, "", 0, 0, [], :undefined, :undefined, :undefined, :undefined, false, :undefined, :undefined, "", :undefined, false, 188446, 0, :undefined}
** (exit) exited in: :gen_fsm.sync_send_all_state_event(#PID<0.227.0>, {:start, 5000}, :infinity)
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: ""
(ssl) ssl_handshake.erl:1737: :ssl_handshake.dec_hello_extensions/2
(ssl) ssl_handshake.erl:926: :ssl_handshake.decode_handshake/3
(ssl) tls_handshake.erl:155: :tls_handshake.get_tls_handshake_aux/3
(ssl) tls_connection.erl:433: :tls_connection.next_state/4
(stdlib) gen_fsm.erl:503: :gen_fsm.handle_msg/7
(stdlib) proc_lib.erl:237: :proc_lib.init_p_do_apply/3
nil
iex(41)>
Mystery solved. I posted this question to the Elixir-lang group and this is a known bug in Erlang OTP 17.3. The solution is to apply a patch, wait for the next version, or downgrade to OTP 17.1.
Details here:
https://groups.google.com/forum/#!topic/elixir-lang-talk/xsAEzCfmRoQ
Either downgrade to Erlang 17.1 or use the latest release tag "OTP-17.3.4" from GitHub - https://github.com/erlang/otp/releases
Incase you choose to use the "OTP-17.3.4" release tag from GitHub, then once you download the source and untar/unzip it, run ./otp_build autoconf, before you run the usual build instructions (./configure, make, make install).
17.3.4 is an internal release and hence no releases are available on the official Erlang site. [source: https://twitter.com/brucify/status/537240367239016448]. Although, I do see that Erlang Solutions site has builds called 17.3 rev2.

Elixir - problems with https URLs

I'm new to Elixir and Erlang and having some issues with accessing https URLs. I've tried the Elixir-specific HTTPotion and Erlang's :inets module.
So from the iex console (Interactive Elixir):
With HTTPotion:
HTTPotion.start
HTTPotion.get("https://api.github.com")
With :inets:
:inets.start
:ssl.start
:httpc.request('https://api.github.com')
In both cases I get a giant stacktrace that essential says there is a bad match somewhere and that a state machine is terminating. I don't get this when accessing http URLs. What am I missing? Thanks.
Edit - here is the error message from HTTPotion:
iex(40)> HTTPotion.get("https://api.github.com")
** (Protocol.UndefinedError) protocol String.Chars not implemented for {:EXIT, {{{{:badmatch, ""}, [{:ssl_handshake, :dec_hello_extensions, 2, [file: 'ssl_handshake.erl', line: 1737]}, {:ssl_handshake, :decode_handshake, 3, [file: 'ssl_handshake.erl', line: 926]}, {:tls_handshake, :get_tls_handshake_aux, 3, [file: 'tls_handshake.erl', line: 155]}, {:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 433]}, {:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 503]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 237]}]}, {:gen_fsm, :sync_send_all_state_event, [#PID<0.227.0>, {:start, 5000}, :infinity]}}, {:gen_server, :call, [#PID<0.226.0>, {:send_req, {{:url, 'https://api.github.com', 'api.github.com', 443, :undefined, :undefined, '/', :https, :hostname}, [], :get, "", [], 5000}}, 5000]}}}
(elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir) lib/string/chars.ex:17: String.Chars.to_string/1
(httpotion) lib/httpotion.ex:157: HTTPotion.request/5
iex(40)>
16:50:10.640 [error] ** State machine #PID<0.227.0> terminating
** Last message in was {:tcp, #Port<0.7454>,
<<22, 3, 3, 0, 93, 2, 0, 0, 89, 3, 3, 84, 40, 158, 178, 2, 216, 45, 226, 183, 79, 42, 199, 205, 19, 31, 63, 223, 138, 208, 132, 186, 28, 129, 123, 235, 1, 142, 90, 243, 25, 70, 210, 32, 199, 56, 251, 131, ...>>}
** When State == :hello
** Data == [data: [{'StateData',
{:state, :client, {#Reference<0.0.0.1360>, #PID<0.226.0>}, :gen_tcp,
:tls_connection, :tcp, :tcp_closed, :tcp_error, 'api.github.com', 443,
#Port<0.7454>,
{:ssl_options, :tls, [{3, 3}, {3, 2}, {3, 1}, {3, 0}], :verify_none,
{#Function<7.50551058/3 in :ssl.handle_verify_options/2>, []},
#Function<8.50551058/1 in :ssl.handle_verify_options/2>, false, false,
:undefined, 1, "", '***', "", '***', '***', '***', "", '***', :undefined,
:undefined, '***', '***',
[<<192, 36>>, <<192, 40>>, <<192, 38>>, <<192, 42>>, <<0, 107>>,
<<0, 106>>, <<0, 61>>, <<192, 35>>, <<192, 39>>, <<192, 37>>, <<192, 41>>,
<<0, 103>>, <<0, ...>>, <<...>>, ...],
#Function<1.50551058/4 in :ssl.handle_options/1>, true, 268435456, false,
:undefined, false, :undefined, :undefined, true, :undefined, false},
{:socket_options, :binary, 0, 0, 0, false}, '***', '***', '***', 49168,
'***', 61463, :ssl_session_cache, {3, 3}, false, :undefined,
{:undefined, :undefined}, :undefined, :undefined, '***', '***', '***',
:undefined, '***', '***', '***', 53269, #Reference<0.0.0.1363>, :undefined,
'***', {false, :first}, {#PID<0.226.0>, #Reference<0.0.0.1361>},
#Reference<0.0.0.1364>, {[], []}, false, true, false, false, :undefined,
:undefined, :undefined}}]]
** Reason for termination =
** {{:badmatch, ""},
[{:ssl_handshake, :dec_hello_extensions, 2,
[file: 'ssl_handshake.erl', line: 1737]},
{:ssl_handshake, :decode_handshake, 3,
[file: 'ssl_handshake.erl', line: 926]},
{:tls_handshake, :get_tls_handshake_aux, 3,
[file: 'tls_handshake.erl', line: 155]},
{:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 433]},
{:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 503]},
{:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 237]}]}
16:50:10.642 [error] GenServer #PID<0.226.0> terminating
Last message: {:send_req, {{:url, 'https://api.github.com', 'api.github.com', 443, :undefined, :undefined, '/', :https, :hostname}, [], :get, "", [], 5000}}
State: {:state, 'api.github.com', 443, :undefined, #Reference<0.0.0.1352>, false, :undefined, [], true, :undefined, false, [], {[], []}, :undefined, :idle, :undefined, "", 0, 0, [], :undefined, :undefined, :undefined, :undefined, false, :undefined, :undefined, "", :undefined, false, 188446, 0, :undefined}
** (exit) exited in: :gen_fsm.sync_send_all_state_event(#PID<0.227.0>, {:start, 5000}, :infinity)
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: ""
(ssl) ssl_handshake.erl:1737: :ssl_handshake.dec_hello_extensions/2
(ssl) ssl_handshake.erl:926: :ssl_handshake.decode_handshake/3
(ssl) tls_handshake.erl:155: :tls_handshake.get_tls_handshake_aux/3
(ssl) tls_connection.erl:433: :tls_connection.next_state/4
(stdlib) gen_fsm.erl:503: :gen_fsm.handle_msg/7
(stdlib) proc_lib.erl:237: :proc_lib.init_p_do_apply/3
nil
iex(41)>
Mystery solved. I posted this question to the Elixir-lang group and this is a known bug in Erlang OTP 17.3. The solution is to apply a patch, wait for the next version, or downgrade to OTP 17.1.
Details here:
https://groups.google.com/forum/#!topic/elixir-lang-talk/xsAEzCfmRoQ
Either downgrade to Erlang 17.1 or use the latest release tag "OTP-17.3.4" from GitHub - https://github.com/erlang/otp/releases
Incase you choose to use the "OTP-17.3.4" release tag from GitHub, then once you download the source and untar/unzip it, run ./otp_build autoconf, before you run the usual build instructions (./configure, make, make install).
17.3.4 is an internal release and hence no releases are available on the official Erlang site. [source: https://twitter.com/brucify/status/537240367239016448]. Although, I do see that Erlang Solutions site has builds called 17.3 rev2.

Resources