<?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>Forem: Gerbrand van Dieyen</title>
    <description>The latest articles on Forem by Gerbrand van Dieyen (@gerbrandvd).</description>
    <link>https://forem.com/gerbrandvd</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%2F80992%2Fb08c2697-9af7-4fe2-91c2-7d04a4b20d98.JPG</url>
      <title>Forem: Gerbrand van Dieyen</title>
      <link>https://forem.com/gerbrandvd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gerbrandvd"/>
    <language>en</language>
    <item>
      <title>Back and forth from Scala to Java</title>
      <dc:creator>Gerbrand van Dieyen</dc:creator>
      <pubDate>Thu, 07 Nov 2019 10:47:13 +0000</pubDate>
      <link>https://forem.com/gerbrandvd/back-and-forth-from-scala-to-java-ah9</link>
      <guid>https://forem.com/gerbrandvd/back-and-forth-from-scala-to-java-ah9</guid>
      <description>&lt;p&gt;For over two years I've programmed nearly exclusively in Scala on the backend, while using mostly JavaScript and TypeScript on the frontend. Before that I mostly used Java for over 15 years, as well as a few other programming languages&lt;br&gt;
Since a month I use Java, Java 8 even, on an assignment, and I thought I shared my experience.&lt;br&gt;
The reason I use Java again, because the client uses Java and more broadly, I wondered how easy it would be to switch back if needed. After all I claim to be programming-language agnostic&lt;/p&gt;

&lt;p&gt;First, going back wasn't as hard as I thought it was, it all came back to me pretty quickly. Of course I'd need to add ; and some more superfluous code, but that's doable.&lt;/p&gt;
&lt;h4&gt;
  
  
  Lambda's
&lt;/h4&gt;

&lt;p&gt;I use Java 8, which is the first Java version to feature lambda's. I don't think I could bear a language without. I use lambda's heavily, probably more than people who'd never used a programming language.&lt;br&gt;
Scala uses &lt;strong&gt;=&amp;gt;&lt;/strong&gt;, Java uses &lt;strong&gt;-&amp;gt;&lt;/strong&gt;, but that's ok.&lt;/p&gt;
&lt;h3&gt;
  
  
  Mutable data
&lt;/h3&gt;

&lt;p&gt;Just as in Scala, mutable data-structures can lead to unpredictable behavior. In the Scala world people are by now pretty used to using immutable data-structures.&lt;br&gt;
In the Java world, rather then thinking about how to transform data correctly, people still deliberate about &lt;a href="https://www.cs.utexas.edu/users/EWD/transcriptions/EWD09xx/EWD936.html"&gt;anthropomorphic&lt;/a&gt; questions like what responsibilities an object has and how a Employee class relates to an employee in the real world.&lt;/p&gt;
&lt;h4&gt;
  
  
  Option
&lt;/h4&gt;

&lt;p&gt;Java 8 introduced the Optional class, so there's no excuse for having &lt;a href="https://duckduckgo.com/?q=NullPointerException+java+Optional"&gt;NullPointerExceptions&lt;/a&gt; in your code (well, except when using older code and libraries).&lt;br&gt;
Java 8 Optional has a &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#map-java.util.function.Function-"&gt;map&lt;/a&gt; method. Annoyingly, it's &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#orElse-T-"&gt;orElse&lt;/a&gt; method of Option returns the actual value type instead of the value wrapped in an Optional, so you can't chain an orElse. I have no idea what the language designers were thinking. Well, as alternative I could use map, but that's a bit less readable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;      &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
      &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;empty&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
      &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Optional:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;of&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;orElse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Fortunately, Java 9 introduced &lt;a href="https://docs.oracle.com/javase/9/docs/api/java/util/Optional.html#or-java.util.function.Supplier-"&gt;or&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Optional and streams
&lt;/h4&gt;

&lt;p&gt;Also, Java's Optional can't be used as &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html"&gt;Iterable&lt;/a&gt;, while Scala's &lt;a href="https://www.scala-lang.org/api/current/scala/Option.html"&gt;Option&lt;/a&gt; can. Allowing to treat Option as a collection of zero or one values helped me better understanding what an Option is and how you could use it beyond the &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#isPresent--"&gt;isPresent()&lt;/a&gt; method.&lt;br&gt;
Converting an Option to a Stream shouldn't be too hard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;option&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;option&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Stream:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;of&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;orElse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;empty&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

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



&lt;p&gt;Which will then allow me to write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;      &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
      &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;middleName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;empty&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
      &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Doe"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

      &lt;span class="o"&gt;...&lt;/span&gt;
   &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;toName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;middleName&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
              &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
              &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;middleName&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
              &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
              &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flatMap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;identity&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
              &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;collect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;joining&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That doesn't look so concise anymore, but arguably better than nested if else blocks.&lt;/p&gt;

&lt;h4&gt;
  
  
  Try catch finally and Either
&lt;/h4&gt;

&lt;p&gt;In Java 8, when you use a resource that implements the &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/io/Closeable.html"&gt;Closeable&lt;/a&gt; interface working, a finally block to close the resource is no longer necessary. That's pretty nice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;readMe&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;IOException&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BufferedReader&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BufferedReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"some file.txt"&lt;/span&gt;&lt;span class="o"&gt;)))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;readLine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;At least when an exception is thrown, the resource is closed. What I greatly miss, is a &lt;a href="https://docs.scala-lang.org/overviews/scala-book/functional-error-handling.html"&gt;Try class&lt;/a&gt;, &lt;a href="https://typelevel.org/cats/datatypes/either.html"&gt;Either&lt;/a&gt; or something similar so no exception is thrown by the method at all. There are a few libraries that do add something like Either, like &lt;a href="http://www.functionaljava.org/features.html"&gt;functionalj&lt;/a&gt;, but of course these are non-standard so a bit harder to introduce at project.&lt;/p&gt;

&lt;h4&gt;
  
  
  Beyond the limits of imperative OO: annotations, aspects and reflection.
&lt;/h4&gt;

&lt;p&gt;As is pretty common, &lt;a href="https://spring.io"&gt;Spring&lt;/a&gt; is also used to extend Java. Spring is based on the principle of aspect- or plugin-oriented programming and heavily relies on bytecode-enhancement and reflection to extend the language Java. In practice this means you use either annotations or config files.&lt;br&gt;
The biggest disadvantage: everything is applied at &lt;em&gt;runtime&lt;/em&gt;, e.g., when your application runs.&lt;br&gt;
In Scala, the language itself is flexible enough using pattern matching, implicits, macros and other language constructs.&lt;br&gt;
Scala pattern matching does use reflection in some cases, but most errors are catched compile time rather then runtime. And despite people complaining about implicit, having an error during &lt;em&gt;compilation&lt;/em&gt; because you forgot to import an implicit is a lot easier to handle than an error that occurs when &lt;em&gt;running&lt;/em&gt; your software because some configuration is wrong, or something fails during reflection.&lt;/p&gt;

&lt;p&gt;Spring will give you pretty good errors when having a wrongly applied annotation, and IntelliJ does have good support for Spring. So most of the times you'll get reasonable descriptive warnings or errors for missing beans, wrong spring-configuration, etc, which makes Spring almost feel being part of the language. And it still feels cumbersome, if only because your code is cluttered with annotations.&lt;/p&gt;
&lt;h4&gt;
  
  
  Lombok, case classes
&lt;/h4&gt;

&lt;p&gt;Scala introduced &lt;a href="https://docs.scala-lang.org/overviews/scala-book/case-classes.html"&gt;case classes&lt;/a&gt;, which allows you to write value based classes without a lot of boilerplate - or mistakes like accidentally committing a property in &lt;a href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#equals(java.lang.Object)"&gt;equals&lt;/a&gt; or &lt;a href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#hashCode()"&gt;hashCode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Java by default doesn't. I'm very glad &lt;a href="https://projectlombok.org/order-license-info"&gt;someone&lt;/a&gt; created &lt;a href="https://projectlombok.org"&gt;Lombok&lt;/a&gt; and it seems well accepted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;lombok.Value&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@Value&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;middleName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;employNumber&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

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



&lt;p&gt;You can't do everything you could do in Scala, like pattern matching on a case class, and unlike Scala there's still a difference between methods and properties in Java.&lt;br&gt;
But it's a whole lot better then generated equals, toString and get'ter methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.baeldung.com/lombok-ide"&gt;IDE support for Lombok&lt;/a&gt; is very good, so you hardly notice you're using language extensions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Switching back and forth from Scala to Java is doable, but I certainly wouldn't want to go back indefinitely. The Scala world is still thriving. Java is bearable, but Scala makes programming doable.&lt;/p&gt;

</description>
      <category>scala</category>
      <category>java</category>
      <category>functional</category>
      <category>programming</category>
    </item>
    <item>
      <title>Encrypt your disks</title>
      <dc:creator>Gerbrand van Dieyen</dc:creator>
      <pubDate>Thu, 20 Dec 2018 15:01:00 +0000</pubDate>
      <link>https://forem.com/gerbrandvd/encrypt-your-disks-5c99</link>
      <guid>https://forem.com/gerbrandvd/encrypt-your-disks-5c99</guid>
      <description>&lt;p&gt;If you have a laptop, you should &lt;em&gt;always&lt;/em&gt; encrypt your harddisk. If you have not already done, make this your new year’s resolution - better yet, do it today.&lt;/p&gt;

&lt;p&gt;Loosing your laptop sucks, but it sucks a lot more if you have to fear if someone else somehow gets access to all your data. Even if you have a login-password and have all your data in the cloud, you data could still be a at rest in the temporary folder. And a potential thief could access all your ‘saved passwords’.&lt;/p&gt;

&lt;p&gt;Microsoft Windows and Apple’s OS X and most Linux distribution like Ubuntu make disk encryption very easy - it’s hopefully the default on any new laptop. If you want to encrypt your disk after installation, I’d refer to the documentation of your operation system: &lt;em&gt;&lt;a href="https://www.howtogeek.com/234826/how-to-enable-full-disk-encryption-on-windows-10/"&gt;Windows&lt;/a&gt;&lt;/em&gt;, &lt;em&gt;&lt;a href="https://support.apple.com/en-us/HT204837"&gt;OS X&lt;/a&gt;&lt;/em&gt;, search the &lt;em&gt;&lt;a href="https://askubuntu.com/questions/366749/enable-disk-encryption-after-installation"&gt;web&lt;/a&gt;&lt;/em&gt; or ask a colleague or family-member.&lt;/p&gt;

&lt;p&gt;On the operation system I am using, &lt;a href="https://kubuntu.org"&gt;Kubuntu Linux&lt;/a&gt;, disk encryption can be chosen during installation and contrary to Linux’ reputation that’s very easy. My laptop has an SSD as main-disk containing the root dir, and an additional disk of 2TB for all other data that doesn’t fit on my SSD. Of course it’s encrypted too.At first, my configuration required me to enter a passphrase twice, once for the SSD and a second time for the additional disk. Bit of a nuisance. Thanks to this wonderful howto, I have a set-up that’s hardly less secury, but easier to use: &lt;a href="https://www.howtoforge.com/automatically-unlock-luks-encrypted-drives-with-a-keyfile"&gt;HOWTO: Automatically Unlock LUKS Encrypted Drives With A Keyfile&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The encryption key is stored on my main SSD, so I only have to enter the passphrase for that SSD. After that, the key that’s stored on the SSD is used to decrypt the second disk. As mentioned in the howto, if people get access to your root dir all is lost anyway.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>encryption</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Using Swagger to access your secured api</title>
      <dc:creator>Gerbrand van Dieyen</dc:creator>
      <pubDate>Tue, 18 Apr 2017 21:01:00 +0000</pubDate>
      <link>https://forem.com/gerbrandvd/using-swagger-to-access-your-secured-api-3pb0</link>
      <guid>https://forem.com/gerbrandvd/using-swagger-to-access-your-secured-api-3pb0</guid>
      <description>&lt;p&gt;Swagger, &lt;a href="http://swagger.io/"&gt;http://swagger.io/&lt;/a&gt; is a great way make your api accessible. Not only documentation is provided, but your users, your co-developers or your self can try out your api. But what if your API is secured using a token based security system like webtokens?&lt;/p&gt;

&lt;p&gt;Well, it’s quite easy to modify your swagger frontend to allow adding any token to requests.&lt;/p&gt;

&lt;p&gt;First somewhere in your swagger template file, add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form onsubmit="addApiKeyAuthorization()"&amp;gt;
                &amp;lt;div class="input"&amp;gt;
                    &amp;lt;input placeholder="access_token" id="input_apiKey" name="input_apiKey" type="text"&amp;gt;
                    &amp;lt;input type="submit" value="Authenticate"/&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then in the header add the following Javascript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    function addApiKeyAuthorization(){
        var apiKey = getUrlVars().input_apiKey;

        if (apiKey &amp;amp;&amp;amp; apiKey.trim() != "") {
            console.log("initialzing oauth via api-key")
            var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("Authorization", "Bearer " + apiKey, "header");
            window.swaggerUi.api.clientAuthorizations.add("bearer", apiKeyAuth );
            //For clarity, also add in the input field
            $('#input_apiKey')[0].value=apiKey
        }
    }

&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Purging files from Git history</title>
      <dc:creator>Gerbrand van Dieyen</dc:creator>
      <pubDate>Fri, 14 Oct 2016 16:01:00 +0000</pubDate>
      <link>https://forem.com/gerbrandvd/purging-files-from-git-history-2j89</link>
      <guid>https://forem.com/gerbrandvd/purging-files-from-git-history-2j89</guid>
      <description>&lt;p&gt;Most developers, like me, use Git for versioning. Even for personal projects, it’s great to have a history of files available. Deleting a file in git will cause it to remove from your working directory, while the file is still present in the history. Usually this is what you want, but sometimes you might want to remove a file completely including it’s history.&lt;/p&gt;

&lt;p&gt;There’s a command for that but typically for git it’s not exactly &lt;em&gt;intuitive&lt;/em&gt;. To alter history, you can use the &lt;a href="https://git-scm.com/docs/git-filter-branch"&gt;filter-branch&lt;/a&gt; command. Filter branch can be supplied with a filter, which is a shell command that’s executed on each commit.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To purge a file from history, as if it never existed execute:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch MYFILE public' HEAD&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where you can replace &lt;em&gt;MYFILE&lt;/em&gt; with one or more files you want to delete.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you want to purge a whole directory, including it’s content, add the -r switch:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch MYDIRECTORY public' HEAD&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Great if you checked in a large file, or file in a public repository that shouldn’t be public. For more information, read the git manual or the numerous tutorials that exist. For example, git-filter can also be used to move a file from one repository to another &lt;a href="http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history"&gt;while preserving history&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
