Improving Wetwarehttp://improvingwetware.com
en-us40Because technology is never the issueElixir Ecto simple SQL Query<p>Demo after the previous post, showing just executing SQL</p>
<pre>
Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> alias Ora.Repo
Ora.Repo
iex(2)> result = Ecto.Adapters.SQL.query!(Repo, "select * from scott.emp where empno = :1 ", [7369])
13:34:54.892 [debug] QUERY OK db=16.0ms
select * from scott.emp where empno = :1 [7369]
%{
columns: ["EMPNO", "ENAME", "JOB", "MGR", "HIREDATE", "SAL", "COMM", "DEPTNO"],
num_rows: 1,
rows: [
[7369, "SMITH", "CLERK", 7902, ~N[1980-12-17 00:00:00], 800.0, nil, 20]
]
}
iex(3)>
</pre>
<p>Note. Can also use <tt>Ecto.Adapters.SQL.query</tt> which will then return the usual tuple</p>
<pre>
iex(3)> result = Ecto.Adapters.SQL.query(Repo, "select * from scott.emp where empno = :1 ", [7369])
13:38:05.739 [debug] QUERY OK db=16.0ms
select * from scott.emp where empno = :1 [7369]
{:ok,
%{
columns: ["EMPNO", "ENAME", "JOB", "MGR", "HIREDATE", "SAL", "COMM",
"DEPTNO"],
num_rows: 1,
rows: [
[7369, "SMITH", "CLERK", 7902, ~N[1980-12-17 00:00:00], 800.0, nil, 20]
]
}}
iex(4)>
</pre>
<p>Need to set MIX_ENV to dev/test/prod to switch between environments.</p>Tue, 21 May 2019 06:00:00 +0000urn:uuid:540e12d9-a920-42e5-8120-27844766284dPete McBreenhttp://improvingwetware.com/2019/05/21/elixir-ecto-simple-sql-query#commentshttp://improvingwetware.com/2019/05/21/elixir-ecto-simple-sql-query
Setting up Elixir and Ecto with jamdb_oracle <p>Creating a simple Elixir application to test database connectivity to a legacy Oracle database (SCOTT) usign jamdb_oracle. Sorry for the wall of text, but could not find this clearly documented anywhere else, so putting it out here in case I ever need to find it again</p>
<pre>
C:\Dev\lelixir>mix new ora --sup
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating config
* creating config/config.exs
* creating lib
* creating lib/ora.ex
* creating lib/ora/application.ex
* creating test
* creating test/test_helper.exs
* creating test/ora_test.exs
Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:
cd ora
mix test
Run "mix help" for more commands.
C:\Dev\lelixir>cd ora
C:\Dev\lelixir\ora>
</pre>
<p>Setup for Oracle, using jamdb_oracle, need to edit ./mix.exs , adding in the extra applications that need to run</p>
<pre>
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :ecto, :jamdb_oracle],
mod: {Ora.Application, []}
</pre>
<p>further down add in the dependencies, specifying the versions the application wants from <a href="https://hex.pm/packages/jamdb_oracle">Hex.pm</a>.</p>
<pre>
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ecto, "~> 3.0"},
{:jamdb_oracle, "~>0.3.2"}
</pre>
<p>Then need to run commands to get the dependencies and to compile them. Note that there are extras pulled in when the library you request also has dependencies.</p>
<pre>
C:\Dev\lelixir\ora>mix deps.get
Resolving Hex dependencies...
Dependency resolution completed:
New:
base64url 0.0.1
connection 1.0.4
db_connection 2.0.6
decimal 1.7.0
ecto 3.1.4
ecto_sql 3.1.3
jamdb_oracle 0.3.2
jose 1.9.0
telemetry 0.4.0
* Getting ecto (Hex package)
* Getting jamdb_oracle (Hex package)
* Getting ecto_sql (Hex package)
* Getting jose (Hex package)
* Getting base64url (Hex package)
* Getting db_connection (Hex package)
* Getting telemetry (Hex package)
* Getting connection (Hex package)
* Getting decimal (Hex package)
</pre>
<p>Followed by compilation, I got some warnings here, but still worked later on.</p>
<pre>
C:\Dev\lelixir\ora>mix compile
==> base64url (compile)
Compiled src/base64url.erl
==> connection
Compiling 1 file (.ex)
Generated connection app
==> jose
Compiling 90 files (.erl)
Compiling 8 files (.ex)
warning: function Poison.EncodeError.exception/1 is undefined
(module Poison.EncodeError is not available)
lib/jose/poison/lexical_encoder.ex:8
Generated jose app
===> Compiling telemetry
==> decimal
Compiling 1 file (.ex)
Generated decimal app
==> db_connection
Compiling 16 files (.ex)
Generated db_connection app
==> ecto
Compiling 54 files (.ex)
Generated ecto app
==> ecto_sql
Compiling 25 files (.ex)
Generated ecto_sql app
==> jamdb_oracle
Compiling 5 files (.erl)
Compiling 3 files (.ex)
warning: function table_exists_query/1 required by behaviour Ecto.Adapters.SQL.Connection
is not implemented (in module Ecto.Adapters.Jamdb.Oracle.Connection)
lib/jamdb_oracle_ecto.ex:138
Generated jamdb_oracle app
==> ora
Compiling 2 files (.ex)
Generated ora app
</pre>
<p>After that had to type <tt>mix ecto.gen.repo</tt>, Which gave the output</p>
<pre>
warning: could not find Ecto repos in any of the apps: [:ora].
You can avoid this warning by passing the -r flag or by setting the
repositories managed by those applications in your config/config.exs:
config :ora, ecto_repos: [...]
** (Mix) ecto.gen.repo expects the repository to be given as -r MyApp.Repo
</pre>
<p>Which required the following edits to ./config/config.exs</p>
<pre>
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
config :ora, Ora.Repo,
database: "SCOTT", # original Oracle test database
username: "user",
password: "pass",
hostname: "db.domain.name",
port: 1521 # default oracle port
config :ora, ecto_repos: [Ora.Repo]
</pre>
<p>rerunning the command was successful, with the message</p>
<pre>
* creating lib/ora
* creating lib/ora/repo.ex
* updating config/config.exs
Don't forget to add your new repo to your supervision tree
(typically in lib/ora/application.ex):
# For Elixir v1.5 and later
{Ora.Repo, []}
# For Elixir v1.4 and earlier
supervisor(Ora.Repo, [])
And to add it to the list of ecto repositories in your
configuration files (so Ecto tasks work as expected):
config :ora,
ecto_repos: [Ora.Repo]
</pre>
<p>At this point, ./lib/ora/repo.ex needed a minor edit to use the jamdb adapter</p>
<pre>
defmodule Ora.Repo do
use Ecto.Repo,
otp_app: :ora,
adapter: Ecto.Adapters.Jamdb.Oracle
end
</pre>
<p>and ./lib/ora/application.ex needed</p>
<pre>
def start(_type, _args) do
# List all child processes to be supervised
children = [
{Ora.Repo, []}
# Starts a worker by calling: Ora.Worker.start_link(arg)
# {Ora.Worker, arg}
]
</pre>
<p>At this point, OK to test it out</p>
<pre>
iex -S mix
Compiling 4 files (.ex)
Generated ora app
Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> alias Ora.Repo
Ora.Repo
iex(2)> import Ecto.Query, only: [from: 2]
Ecto.Query
iex(3)> query = from e in "emp", where: e.ename == "SMITH", select: e.empno
#Ecto.Query<from n0 in "emp", where: n0.ename == "SMITH",
select: n0.empno>
iex(4)> Repo.all(query)
16:10:06.896 [debug] QUERY OK source="emp" db=15.0ms
SELECT n0.empno FROM emp n0 WHERE (n0.ename = 'SMITH') []
[7369]
iex(5)>
</pre>
<p>Mission accomplished, connected to legacy Oracle database (SCOTT) using Elixir and jamdb_oracle</p>Mon, 20 May 2019 15:00:00 +0000urn:uuid:c2187aa5-76ae-4ab7-bc89-5614b4f50e01Pete McBreenhttp://improvingwetware.com/2019/05/20/setting-up-elixir-and-ecto-with-jamdb_oracle#commentshttp://improvingwetware.com/2019/05/20/setting-up-elixir-and-ecto-with-jamdb_oracle
Thank You for Erlang Joe<p>Recently I have been looking at Erlang and Elixir, and in the process was reading <a href="https://www.amazon.com/exec/obidos/ASIN/1430219483/mcbreenconsul-20/nosim">Coders at Work</a> and came across this quote from Joe Armstrong (pg 213)</p>
<blockquote><p>I think the lack of reusability comes in object-oriented languages, not in functional languages. Because the problem with object-oriented languages is they&#8217;ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.</p>
<p>If you have <b title ="the same language expression produces the same value when evaluated twice">referentially transparent</b> code, if you have pure functions &#8211;all the data comes in its input arguments and everything goes out and laves no data behind &#8211; it&#8217;s incredibly reusable. You can just reuse it here, there and everywhere&#8230;</p></blockquote>
<p>Something to think about.</p>Sun, 19 May 2019 04:00:00 +0000urn:uuid:f871e6f0-2fa4-4ab9-9d7c-1b9132e95ad0Pete McBreenhttp://improvingwetware.com/2019/05/19/thank-you-for-erlang-joe#commentshttp://improvingwetware.com/2019/05/19/thank-you-for-erlang-joe
Blockchain - is it a good idea for some domains?<p>Found this set of articles on twitter&#8230;</p>
<ul>
<li><a href="http://finnoworld.com/supply-chain-is-obviously-not-a-blockchain-use-case/">Supply Chain is not a blockchain use case</a></li>
<li><a href="https://shkspr.mobi/blog/2018/06/how-i-became-leonardo-da-vinci-on-the-blockchain/">How I became leonardo da vinci on the blockchain</a></li>
<li><a href="https://davidgerard.co.uk/blockchain/2019/04/20/medical-records-on-the-blockchain-the-history-of-a-bad-idea/">Medical records on the blockchain - history of a bad idea</a></li>
<li><a href="https://www.techdirt.com/articles/20181110/01030941012/blockchain-voting-solves-none-actual-problems-online-voting-leverages-none-benefits-blockchain.shtml">Blockchain and online voting</a></li>
</ul>
<p>From the history of a bad idea....</p>
<blockquote><p>When an audience member, tiring of this foggy talk, asked if there was anything concrete that blockchains could offer the NHS, they responded that asking for practical uses of Blockchain was “like trying to predict Facebook in 1993.” The main takeaway for the health care sector people I was with was swearing never to use said accounting firm for anything whatsoever that wasn’t accounting.</p></blockquote>Wed, 15 May 2019 06:00:00 +0000urn:uuid:db5a6b9d-e522-4044-a41d-5ee86d586f36Pete McBreenhttp://improvingwetware.com/2019/05/15/blockchain-is-it-a-good-idea-for-some-domains#commentshttp://improvingwetware.com/2019/05/15/blockchain-is-it-a-good-idea-for-some-domains
Rethinking Driverless Vehicles<p>in <a href="https://www.nature.com/articles/d41586-019-01473-3">Nature is suggesting that researchers have made a wrong turn</a> in thinking and writing about Driverless Vehicles</p>
<blockquote><p>What these academics are not doing is asking the questions that society needs answered to decide what the role of driverless cars will be.</p></blockquote>
<p>Ashley Nunes suggests</p>
<blockquote><p>This leads to something many academics overlook: driverless does not mean humanless. My research on the history of technology suggests that such advances might reduce the need for human labour, but it seldom, if ever, eliminates that need entirely. Regulators in the United States and elsewhere have never signed off on the use of algorithms crucial to safety without there being some accompanying human oversight. Rather than rehashing decisions from Philosophy 101, more academics should educate themselves on the history of the technology and the regulatory realities that surround its use.</p></blockquote>Fri, 10 May 2019 13:53:37 +0000urn:uuid:1d2aed04-8fda-4725-b8b1-43ef2f3295f5Pete McBreenhttp://improvingwetware.com/2019/05/10/rethinking-driverless-vehicles#commentshttp://improvingwetware.com/2019/05/10/rethinking-driverless-vehicles
Free and fair elections in the age so social media?<p>Carole Cadwalladr&#8217;s TED Talk resulted in an article in The Guardian called <a href="https://www.theguardian.com/uk-news/2019/apr/21/carole-cadwalladr-ted-tech-google-facebook-zuckerberg-silicon-valley">how I took on the tech titans in their lair</a></p>
<blockquote><p>They have created platforms of unimaginable complexity. But if they’re not sick to their stomach about what has happened in Myanmar or overwhelmed by guilt about how their platforms were used by Russian intelligence to subvert their own country’s democracy, or sickened by their own role in what happened in New Zealand, they’re not fit to hold these jobs or wield this unimaginable power.</p></blockquote>Wed, 24 Apr 2019 03:00:00 +0000urn:uuid:02d13891-b9f9-43fd-aa7b-31b13da87263Pete McBreenhttp://improvingwetware.com/2019/04/24/free-and-fair-elections-in-the-age-so-social-media#commentshttp://improvingwetware.com/2019/04/24/free-and-fair-elections-in-the-age-so-social-media
Time to revoke some corporate charters?<p>With the recent news about bad corporate behavior by facebook, <a href="https://www.theguardian.com/uk-news/2019/mar/21/facebook-knew-of-cambridge-analytica-data-misuse-earlier-than-reported-court-filing">Cambridge Analytica misuse of data</a>, <a href="https://boingboing.net/2019/03/22/secret-emails-show-facebook-kn.html">lying about cambridge analytica</a>, <a href="https://techcrunch.com/2019/03/03/facebook-phone-number-look-up/">asking for phone numbers for login and then using those numbers for advertising targetting</a>, <a href="https://techcrunch.com/2018/09/27/yes-facebook-is-using-your-2fa-phone-number-to-target-you-with-ads/">second link</a>, <a href="https://www.bbc.com/news/technology-43656746">letting scammers search for you by phone number</a> and finally <a href="https://www.salon.com/2019/03/22/livestreamed-massacre-means-its-time-to-shut-down-facebook-live_partner/">livestreaming murder</a>. Maybe it is time to start the conversation about how to regulate, break up or revoke the corporate charter for some of the larger social media companies.</p>
<p>The argument that they are just a common carrier not responsible for the content does not fly. They are wittingly allowing propaganda, agitprop and other unwelcome content to be disseminated around the world, and benefiting by getting advertisers to pay to be associated with the content. The common carrier excuse worked in for some industries, where the carrier was transmitting content from known providers, but now that the <em>carrier</em> is enabling the publishing and broadcast from any random internet connection, facebook is now the publisher and the carrier. Hence it is responsible for the content.</p>
<p>If it cannot make a valid business model out of properly curated content, then too bad, it does not deserve to exist. There are many business models that society does not allow to exist, and publishing/promoting propaganda, agitprop and dubious content is one of the business models that needs to be controlled by society.</p>
<p>Twitter probably falls into the same category with <a href="https://edition.cnn.com/2019/03/22/tech/twitter-algorithm-political-rhetoric/index.html">the way the platform promotes extreme political rhetoric</a>. There is reasonable evidence that multiple elections around the world have been adversely affected by the various social media platforms over the past several years, so before outside influences create more havoc, societies around the world need to come up with a strategy to deal with social media companies that profit from spreading information designed to decrease the quality of life for everyone.</p>Wed, 27 Mar 2019 03:41:31 +0000urn:uuid:843256b3-1bf9-4577-89a6-f3e881a2beb6Pete McBreenhttp://improvingwetware.com/2019/03/27/time-to-revoke-some-corporate-charters#commentshttp://improvingwetware.com/2019/03/27/time-to-revoke-some-corporate-charters
Cynefin Framework for understanding Methodologies<p>Dave Snowden is writing up the <a href="https://cognitive-edge.com/blog/cynefin-as-of-st-davids-day-2019/">Definitive History of the Cynefin Framework</a>, so I thought it was time to mention it here. Dave was one of the creators of DSDM that I covered in my Questioning XP book, so it is nice that he has now come up with a way to talk about methodologies</p>
<p><img src="/files/resource/5/CynefinDomains.png" alt="Cynefin Domains Picture from above article, hosted here to avoid putting load on other server" /></p>
<p>Cynefin documents five different domains, earliest documentation is in article on <a href="https://onlinelibrary.wiley.com/doi/pdf/10.1002/bult.284">Complex Acts of Knowing</a> back in 2002/2003.This link is an archive of the <a href="http://old.cognitive-edge.com/wp-content/uploads/2002/07/13-Complex-Acts-of-Knowing-paradox-and-descriptive-self-awareness.pdf">Creative Commons version of Complex Acts of Knowing</a> in case the Wiley link goes down.</p>
<ul>
<li>Obvious - this is the domain of <em>Best Practices</em>, where everyone knows how to operate, so it is process of just doing what everyone knows how to do.</li>
<li>Complicated - this is the domain of learned expertise, there are multiple good answers, but careful analysis might be needed to discover the way forward. One metaphor refers to this as the domain of the bicycle, if it is not working right you can take it apart, discover what is broken and then reassemble it.</li>
<li>Complex - this is the domain where good answers are only discovered in retrospect. A metaphor for this is that of the frog - you cannot take it apart, discover what is wrong and then reassemble it, you have to try different treatments on the whole organism. Dave Snowden talks about <em>Safe to Fail</em> experiments in this domain.</li>
<li>Chaotic - this is the domain of no clear cause and effect, so you just need to take action to try to move out of the chaotic state into one of the other domains.</li>
<li>Disorder - this is the domain of not knowing which domain you are in.</li>
</ul>
<p>There are some things in software development that fall into the <em>Obvious</em> domain, but mostly there is an existing product or library that handles this domain for you. So if your application needs to store some data, then depending on what the data is, the choice of the filesystem, transient cache, a database or offsite cloud storage will be obvious. There may be some debate as to the flavour and/or vendor of the storage mechanism, but storing data is a known problem with well known solutions.</p>
<p>In part some of my <em>Software Craftsmanship</em> book was raising issues about using techniques that are relevant to the <em>Obvious</em> domain in <em>Software Development</em>. A Factory with a mechanical metaphor is appropriate for the <em>Obvious</em> domain, after all we know how to assemble a car. But the reason we know how to assemble a car is because experts working in the <em>Complicated</em> domain did a lot of <em>Design for Manufacture</em> work on the design of the car so that it could be economically made in a factory. Designing an assembly line is a very complicated process, but once it is built, it is <em>Obvious</em> what you are supposed to do at each work station along the line.</p>
<p>In software development, all of the <em>Obvious</em> domains are well served, so what is left is the <em>Complicated</em> and <em>Complex</em> domains where off the shelf solutions are not available. Looking back up to the image of the Cynefin domains, some Methodologies are better suited to domains that are not very <em>Complicated</em>, bordering on the <em>Obvious</em>, others like Jim Highsmith&#8217;s <em>Adaptive Software Development</em> are targeted at working in the <em>Complex</em> domain, with the three project phases of speculation, collaboration and learning.</p>Sun, 17 Mar 2019 20:22:06 +0000urn:uuid:ea20615d-868a-4ca7-b199-627c46d6ba4ePete McBreenhttp://improvingwetware.com/2019/03/17/cynefin-framework-for-understanding-methodologies#commentshttp://improvingwetware.com/2019/03/17/cynefin-framework-for-understanding-methodologies
Another take on "How Hard Can It Be?"<p><a href="https://freethoughtblogs.com/stderr/2019/03/02/in-5-years-there-will-be-moaning-and-wailing/">In 5 Years There Will Be Moaning and Wailing</a> writes Marcus Ranum about the logistical management software for the F-35</p>
<blockquote><p>I love it when software developers say “How hard can it be?!” and decide to build their own complete replacement system. The results are usually about as bad as the first system, for the same reason. To be fair, this stuff is really hard to write – which is all the more reason to be skeptical when someone says they’ll just put together a modular cloud-based version of their own. You should always ask “why do you believe you will get right the things that everyone else got wrong? Because the reasons that they got it wrong apply to you, as well.”</p></blockquote>Mon, 04 Mar 2019 15:44:02 +0000urn:uuid:152b61a7-9f87-40f1-ba4a-2b031c74127dPete McBreenhttp://improvingwetware.com/2019/03/04/another-take-on-how-hard-can-it-be#commentshttp://improvingwetware.com/2019/03/04/another-take-on-how-hard-can-it-be
Learning The World<p>Playing with a book idea:</p>
<blockquote><p><a href="/files/resource/4/ltw.pdf">Learning the world</a>, an introduction to SQL for Business Analysts. Uses <a href="https://www.postgresql.org/">PostgreSQL</a> but most of the SQL in the book is standard and could be used on any other database. Might need an appendix or web reference for other database specific queries looking at the table catalogs.</p></blockquote>Mon, 04 Mar 2019 03:45:40 +0000urn:uuid:af46ea54-6f15-43e9-ad10-48fb04dd56e6Pete McBreenhttp://improvingwetware.com/2019/03/04/learning-the-world#commentshttp://improvingwetware.com/2019/03/04/learning-the-world