<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: nigel447</title>
    <description>The latest articles on DEV Community by nigel447 (@nigel447).</description>
    <link>https://dev.to/nigel447</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F491098%2Fec37c7c6-1e18-45b1-8b4d-02c59c6b1162.png</url>
      <title>DEV Community: nigel447</title>
      <link>https://dev.to/nigel447</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nigel447"/>
    <language>en</language>
    <item>
      <title>Some notes on Dart package encapsulation</title>
      <dc:creator>nigel447</dc:creator>
      <pubDate>Tue, 28 May 2024 14:11:48 +0000</pubDate>
      <link>https://dev.to/nigel447/some-notes-on-dart-package-encapsulation-e2i</link>
      <guid>https://dev.to/nigel447/some-notes-on-dart-package-encapsulation-e2i</guid>
      <description>&lt;p&gt;This is a short note showing how I use dart package encapsulation to manage the dependency in a dart/flutter application.&lt;br&gt;&lt;br&gt;
If you are new to creating your own dart package there is a great post here on dev to help u get started &lt;a href="https://dev.to/aaronreddix/how-to-create-dart-packages-in-flutter-a-step-by-step-guide-1f5a"&gt;How to Create Dart Packages in Flutter: A Step-by-Step Guide&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Dependencies are always an issue and need to be managed carefully to avoid cycles among other things, Golang helps by throwing a compilation error if u have any Cyclic dependencies in your code. Creating acyclic dependency trees(graphs) preferably Directed &lt;a href="https://en.wikipedia.org/wiki/Directed_acyclic_graph"&gt;DAG&lt;/a&gt; is what you want, you can research the details if u r interested.  &lt;/p&gt;

&lt;p&gt;Say you have a project with a few packages like below&lt;br&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqge3r2m87rksdp4jbzia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqge3r2m87rksdp4jbzia.png" alt="Image description" width="471" height="181"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Here I have a rest_client package among others, the rest_client package will use other dependency packages like &lt;a href="https://pub.dev/packages/dio"&gt;Dio&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
I want to use Dio response types in the main code.&lt;br&gt;&lt;br&gt;
To keep the dependency tree clean I dont want to import Dio types  in the main source as well as the rest_client package, so I export Dio from the rest_client package as so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;library rest_client;

export 'package:dio/dio.dart';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the main source code I import any needed Dio artifact from my rest_client package like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:rest_client/rest_client.dart' as transport;
class FreeAuthService  {

  final transport.Dio _dio = transport.Dio();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now I am free to encapsulate all my related http transport code in the rest_client package and just return the Dio responses into the main source code.&lt;/p&gt;

&lt;p&gt;Here are some minor details  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;packages are imported in pubspec like
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  rest_client:
    path: packages/rest_client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;in the package directory source you need a top level file where you export the package dependencies you wish to expose like
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;library rest_client;

export 'package:dio/dio.dart';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>dart</category>
      <category>objectorientated</category>
      <category>encapsulation</category>
      <category>directedgraph</category>
    </item>
    <item>
      <title>Some notes on symmetric encryption in golang</title>
      <dc:creator>nigel447</dc:creator>
      <pubDate>Sun, 19 May 2024 10:42:56 +0000</pubDate>
      <link>https://dev.to/nigel447/some-notes-on-symmetric-encryption-in-golang-2c9i</link>
      <guid>https://dev.to/nigel447/some-notes-on-symmetric-encryption-in-golang-2c9i</guid>
      <description>&lt;p&gt;Working today on passing around secure parameters I came across the post &lt;br&gt;
&lt;a href="https://zostay.com/posts/2022/05/04/do-not-use-libsodium-with-go/"&gt;Instead of LibSodium, you should use the nacl/box library that is part of golang.org/x/crypto.&lt;/a&gt; [1] &lt;/p&gt;

&lt;p&gt;here is a simple example using the suggested libraries  &lt;/p&gt;

&lt;p&gt;the encrypt import suggested [1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"golang.org/x/crypto/nacl/secretbox"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func getRandomNonce() ([]byte, [24]byte) {
    iv := make([]byte, 24)
    if _, err := io.ReadFull(rand.Reader, iv); err != nil {
        panic(err)
    }
    return iv, [24]byte(iv)
}

func encryptSecret(plainText []byte) ([]byte, [24]byte) {
    nonce, np := getRandomNonce()
    symKey := [32]byte(secretKeyBytes)
    encrypted := secretbox.Seal(nonce, plainText, &amp;amp;np, &amp;amp;symKey)
    hex.EncodeToString(encrypted)
    return encrypted, np
}

func decryptSecret(cypherText []byte, decryptNonce [24]byte) []byte {
    symKey := [32]byte(secretKeyBytes)
    decrypted, ok := secretbox.Open(nil, cypherText[24:], &amp;amp;decryptNonce, &amp;amp;symKey)
    if !ok {
        panic("decryption error")
    }
    return decrypted
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and here is a test&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func TestSymmEncrypt(t *testing.T) {
    plainText := "this is pop"
    cypherText, decryptNonce := encryptSecret([]byte(plainText))
    hopePlainText := decryptSecret(cypherText, decryptNonce)
    fmt.Println(string(hopePlainText))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;notes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[1] is a good example of why we cant just cut and paste crypto code and hope for the best, its humbling to see even good cryptographers make mistakes&lt;/li&gt;
&lt;li&gt;its amazing how often the crypto random source and its use is a basic repeated error in so much code
&lt;/li&gt;
&lt;li&gt;golangs rand.Reader uses &lt;a href="https://man7.org/linux/man-pages/man2/getrandom.2.html"&gt;getrandom(2)&lt;/a&gt;[2], its worth it to read the man page to see its limitations
from [2] "entropy pool has been initialized and the request size is large (buflen &amp;gt; 256), the call either succeeds, returning a partially filled buffer" oops!
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;philosophical notes  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;is the universe deterministic if yes then we should be able to get a truly random source, however for the believers of science there has always been an argument for a &lt;a href="https://plato.stanford.edu/entries/freedom-ancient/"&gt;non deterministic universe&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;struggling with crypto? =&amp;gt; Zen proverb "Hell, also, is a place to live in."&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cryptography</category>
      <category>philosophy</category>
      <category>go</category>
    </item>
    <item>
      <title>run dart-frog in intellij</title>
      <dc:creator>nigel447</dc:creator>
      <pubDate>Sat, 06 Jan 2024 21:18:04 +0000</pubDate>
      <link>https://dev.to/nigel447/run-dart-frog-in-intellij-2abg</link>
      <guid>https://dev.to/nigel447/run-dart-frog-in-intellij-2abg</guid>
      <description>&lt;p&gt;As a dartlang enthusiast I am sharing a setup to run the dartfrog development server  in Intellij.&lt;br&gt;&lt;br&gt;
There is a dart-frog VSCode extension sadly while Intellij has a good dart plugin  I struggled to create runtime configs, I did not want to have to run the dartfrog cli in a separate terminal. Using the Intellij default ant plugin I was able to easily set up a dev mode run config looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;project name="secure-context" default="run_dev" basedir="."&amp;gt;
    &amp;lt;target name="run_dev"&amp;gt;
        &amp;lt;exec executable="dart_frog"&amp;gt;
        &amp;lt;arg value="dev" /&amp;gt;
        &amp;lt;/exec&amp;gt;
    &amp;lt;/target&amp;gt;
&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;copy this into a file called build.xml in project root dir&lt;/li&gt;
&lt;li&gt;with the ant plugin Intellij will prompt you to add it as a runtime build&lt;/li&gt;
&lt;li&gt;double click on the task run_dev and the dart frog dev server will boot.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feoqbvncp97gbg8l1ku6j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feoqbvncp97gbg8l1ku6j.png" alt="build setup" width="800" height="387"&gt;&lt;/a&gt; &lt;/p&gt;

</description>
      <category>dart</category>
    </item>
    <item>
      <title># The Great Merge Hexagram 44</title>
      <dc:creator>nigel447</dc:creator>
      <pubDate>Sun, 18 Apr 2021 14:58:19 +0000</pubDate>
      <link>https://dev.to/nigel447/the-great-merge-hexagram-44-4bb2</link>
      <guid>https://dev.to/nigel447/the-great-merge-hexagram-44-4bb2</guid>
      <description>&lt;p&gt;A precautionary tale that many of you may experience(d). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A project manager with more money than sense and no technical expertise. &lt;/li&gt;
&lt;li&gt;A distributed development team with little in common in terms of language and communication. &lt;/li&gt;
&lt;li&gt;Teams trapped in DSL, obsessed with micro goals and oblivious to the wider picture.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You have been invited in to help move the project forward and introduced to the type of code so common to this dysfunctional environment. Countless feature branches with nothing merged.&lt;br&gt;&lt;br&gt;
Working with the teams, pruning branches merging and setting clear well defined goals. Trying to communicate between the developers and the project manager.&lt;br&gt;&lt;br&gt;
I had a bad feeling, so I asked the oracle and received &lt;a href="https://www.iching-hexagrams.com/summer-light/hexagram-44/hexagram-44-text/"&gt;44&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
This was good advice. I had become infected by the chaos, I was to controlling, trying to channel the whirlwind of commits. I stopped, stood back, put myself in the place of the devs, "What good is strength if no one cares?", "After breathing in, one pauses for a moment.", "Amidst the hustle and bustle sensitivity emerges."&lt;br&gt;
I focused on sensitivity and the devs started to respond, a shared sense of ownership began to emerge, spontaneous merge policies and the code begins to build correctly.&lt;br&gt;&lt;br&gt;
I am left to consider this most important question "You may be driving the chariot, But who or what drives you?"&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>management</category>
      <category>consutlant</category>
      <category>psychology</category>
    </item>
  </channel>
</rss>
