Mittwoch, 16. Dezember 2015

Running Oracle in a Docker container on OS X

This guide provides a step-by-step introduction for getting up and running with the Oracle database in a Docker container on OS X.

Step 1: Install Docker

Grab the Docker toolbox  and install it

Step 2: Startup Docker

Run Docker Quickstart Terminal (e.g. by searching for "Docker" in Spotlight)

Step 3: Get the image

We'll use the excellent Docker image by alexeiled - it contains some modifications to make our life easier.

Inside our Docker shell, run

docker pull alexeiled/docker-oracle-xe-11g

to get the image from DockerHub.


Step 4: Startup container

To launch a new container from our image, run

docker run -d -p 49160:22 -p 49161:1521 -p 49162:8080 alexeiled/docker-oracle-xe-11g

You can check which containers are running with

docker ps

Step 5: Connect to our Docker container via SSH

There's a gotcha here: most Docker tutorials assume you're running on a Linux box, where Docker client and Docker server are the same machine. But on OS X, your Docker server is a VirtualBox VM, so none of the usual commands work without modification.

E.g. to connect to our Docker image via SSH, we'd normally use

ssh root@localhost -p 49160

but we'll have to connect to our Docker server instead of localhost:

ssh root@192.168.99.100 -p 49160

(this assumes that the Docker server uses the IP address 192.168.99.100 - when the Docker VM is starting up, it'll tell you which IP address it uses).

Step 6: Logon to Oracle APEX

Now, you can use your Oracle installation. E.g. to log on to APEX, simply open

http://192.168.99.100:49162/apex

in your web browser.


Samstag, 12. Dezember 2015

Sonntag, 6. Dezember 2015

Cooking recipe for GitHub

Simple bugfix / pull request

If you want to help an open source project on GitHub and have a simple bugfix that you would like to see integrated, here's the most straightforward way to do it:

- fork the repo on GitHub
- clone your repo locally
- create a new local branch (let's call it doc-fix-1)
      git branch doc-fix-1
- switch to this branch
      git checkout doc-fix-1
- change the code :-)
- commit it
      git commit -a -m "simple doc fix"
- push it to github, creating a new branch
      git push origin doc-fix-1
- create a pull request on GitHub

(Just a personal note: how I wish that git would at least try to be as user-friendly as hg is...)

Syncing a fork

If you've forked a repository and want to keep it up-to-date, do this:

Add the original repo (just once)

git remote add upstream

Sync with original (whenever you like)


git fetch upstream
git checkout master
git merge upstream/master

Extract values via pattern matching in Elm/Haskell

Haskell


Suppose you have a simple data definition for a direction and want to add a delta of type Int to it:

data Direction = Direction Int deriving Show
let d = Direction 7
 

Obviously, this doesn't work:

d + 5

because the types are not compatible. The solution is pattern matching:

let 
  (Direction value) = d
in
  d + 5


Elm


type Direction = Direction Int

update :: Direction -> Int -> Direction
update dir delta =
  let 
    (Direction value) = dir
  in
    Direction (value + delta)

Freitag, 23. Oktober 2015

Mixing static content and signals in Elm

Elm is awesome, but sometimes, the simplest things prove to be surprisingly challenging.

You can easily create a HTML page showing an image:

import Graphics.Element exposing (..)

main : Element
main =
    image 200 200 ("./images/Mimas_moon.jpg")

and you can just as easily create a HTML page showing the current mouse position:

import Mouse
import Signal
import Graphics.Element

main =
  Signal.map Graphics.Element.show Mouse.position

but creating a HTML page that displays both is not as easy as you would imagine. I finally settled for

import Mouse
import Signal
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import List

toCollage : List Form -> Element
toCollage lst =
  collage 600 400 lst

combine : List (Signal a) -> Signal (List a)
combine = List.foldr (Signal.map2 (::)) (Signal.constant [])
main : Signal Element
main =
  Signal.map toCollage
     (combine
      [ Signal.map toForm (Signal.map Graphics.Element.show Mouse.position)
      , Signal.constant(move (200,-100) (toForm (image 200 200 ("./images/Mimas_moon.jpg"))))
      ])
This code
- takes the current Mouse position (which is a Signal)
- converts it to a Signal Form using Signal.map toForm
- creates and moves an image
- converts it to a Signal Form using Signal.constant
- puts these two elements into a List [ Signal Form ]
- uses combine to convert this List [ Signal Form ] to a Signal List [ Form ]
- finally uses Signal.map toCollage to create a collage out of this list







Mittwoch, 1. April 2015

Using regular expressions with sed (avoiding the "illegal reference \1" error)

Nothing beats sed for doing quick replacements on the command line, but if you try to naively use backreferences, e.g.

  sed "s/(thursday|friday)/\1 next week/" 

 you'll get the (not very helpful) error message

illegal reference \1

The solution is simple - just add the -r command line switch (or --regexp-extended if you like being verbose):

  sed -r "s/(thursday|friday)/\1 next week/"

Samstag, 28. März 2015

Capturing packets on FritzBox routers

Although I've been quite content with my FritzBox routers, I always wanted more information about the actual packets it's receiving and transmitting. Unlike e.g. Astaro routers, FritzBoxes don't have a nice UI that gives you real-time information about the packets it's filtering etc.

Today, I stumbled upon a Sonoya article that describes how you can enable packet capturing on your FritzBox and download the capture in Wireshark format. In essence:

- log in to your FritzBox
- open http:///html/capture.html
- start the capture
- stop the capture; this automatically downloads the capture file

Sonoya article: http://www.sonoya.com/tutorial-netzwerk-datenverkehr-mit-fritzbox-aufzeichnen.html

Samstag, 14. März 2015

Running the "League of Legends" client on Mac OS X

My kids've been pestering me because they wanted to play "League of Legends" on my old Mac for quite some time now. So I thought "Let's download the client and run it - shouldn't take more than a few minutes".

Boy, was I wrong.

On startup (after completing the usual registration process), the client started downloading a whopping 2GB of data. I thought "Oookay. Apparently, they've done a major upgrade right now. So we'll download this once and then we can run it".

Boy, was I wrong.

After the download was finished and we restarted the client, it started downloading another 1GB. I thought "This is getting ridiculous, but what the heck. Surely, this will be the final download".

Boy, was I wrong.

After successfully downloading it and restarting the client, IT STARTED DOWNLOADING AGAIN. WTF?

Now I started thinking (I know, I should have done more of that in the first place...).

Was it possible that in 2015, a game could still require an Administrator account to run properly?
For testing purposes, I logged in using my own (Administrator) account, re-downloaded the installer, went through the initial 2GB download, restarted it, and lo and behold - it worked!

But since giving the kids access to my account is a big no-go, I bit the bullet and
- transferred ownership of the game to them: chown -R League_of_Legends.app
- told them that whenever the game tries to upgrade itself and fails, they should call me

IMO, this is totally unacceptable. Either the people at Riot Games (the makers of League of Legends)  are completely incompetent or just incredibly lazy. Either way, this sucks.


Sonntag, 1. März 2015

Elm: unexpected '|', expecting whitespace or end of input

I recently bought "Seven more languages in seven weeks" (E-Book). I really love the "Seven .. in seven weeks" series - it's intense + challenging + mind-bending.

However, one of the things that was driving me crazy was that this simple piece of Elm code:


type Color = Black | White

generated this error:

unexpected '|'
expecting whitespace or end of input

After trying out various things, the solution turned out to be quite simple - change your Terminal settings to use ASCII instead of Unicode-8, and everything works as expected (you might want to ensure your editor of choice also uses ASCII encoding if you're not using the REPL).

Happy coding!

UPDATE
Turns out the solution wasn't related to the character encoding - it seems to be a bug in the ELM REPL where it doesn't recover once you've typed in something wrong:

franks-air:~ frank$ elm-repl
Elm REPL 0.4
Type :help for help, :exit to exit
> data List = Empty | Node Int List

Error in repl-temp-000.elm:

Parse error at (line 2, column 19):
unexpected '|'
expecting whitespace or end of input


> type List = Empty | Node Int List

Error in repl-temp-000.elm:

Parse error at (line 3, column 19):
unexpected '|'
expecting whitespace or end of input


franks-air:~ frank$ elm-repl
Elm REPL 0.4
Type :help for help, :exit to exit

> type List = Empty | Node Int List
>