Wednesday, August 24, 2016

How to install Objective C 2.0 and GNUstep under Windows SubSystem for Linux - Bash Shell

Install Objective C 2.0 and GNUstep under Windows 10 bash shell
Follow the steps below (make sure the steps are followed in order, that is build libobjc2 before GNUstep) to install required packages and build scripts

bash    Select all
sudo apt-get update sudo apt-get install build-essential libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev gobjc libxml2-dev libjpeg-dev libtiff-dev libpng12-dev libcups2-dev libfreetype6-dev libcairo2-dev libxt-dev libgl1-mesa-dev sudo apt-get install clang-3.6 cmake git sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 cd $HOME git clone --depth=1 cd libobjc2 rm -fr Build mkdir Build && cd Build cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIB_INSTALL_PATH=/usr/local/lib make sudo make install cd $HOME wget tar xvf gnustep-make*.tar.gz cd gnustep-make* CC=clang CXX=clang++ ./configure --prefix=/usr/local make sudo make install cd $HOME wget tar xvf gnustep-base*.tar.gz cd gnustep-base* CC=clang CXX=clang++ ./configure --prefix=/usr/local make sudo make install sudo ldconfig -v # no gnustep-gui installation here. sudo apt-get install libdispatch-dev # testing cd $HOME cat > blocktest.m << EOF #include <stdio.h> int main() { void (^hello)(void) = ^(void) { printf("Hello, block!\n"); }; hello(); return 0; } EOF clang `gnustep-config --objc-flags` -fblocks -o blocktest -x objective-c blocktest.m `gnustep-config --base-libs` ./blocktest cat > main.m << EOF // // main.m // Just a little test case for Objective-C 2.0 on Ubuntu // #import <Foundation/Foundation.h> #import <dispatch/dispatch.h> int main(int argc, const char * argv[]) { @autoreleasepool { int multiplier = 7; int (^myBlock)(int) = ^(int num) { return num * multiplier; }; NSLog(@"%d", myBlock(3)); dispatch_queue_t queue = dispatch_queue_create(NULL, NULL); dispatch_sync(queue, ^{ printf("Hello, world from a dispatch queue!\n"); }); dispatch_release(queue); } @autoreleasepool { NSLog(@"Wow it works!"); } return 0; } EOF # command line for locale generation sudo locale-gen en_US.UTF-8 # command line to reset timezone if not yet configured sudo dpkg-reconfigure tzdata clang `gnustep-config --objc-flags` -fblocks -o main -x objective-c main.m `gnustep-config --base-libs` -ldispatch ./main # to compile objective c++, you would need extra parameters and use clang++ clang++ -std=c++11 -stdlib=libc++ -x objective-c++ clang++ -std=c++11 -stdlib=libstdc++ -x objective-c++

GNUstep documentation is here ->

Wednesday, August 3, 2016

Bash Shell Built Into Windows 10 Anniversary Update 1607 Build 14393.10

After Windows 10 Anniversary Update, you have to enable "Developer mode" on the "Update & Security" page.
Then go to Control Panel -> Program and Features -> Turn Windows Features on or off -> Windows SubSystem for Linux (Beta), and click OK.

Bash Shell is only for 64-bit versions of Windows 10.

Bash Shortcut Keys
There are a number of very useful shortcut keys you can use in the bash shell:

Ctrl + U: Clears the line from the cursor point back to the beginning.
Ctrl + A: Moves the cursor to the beginning of the line.
Ctrl + E: Moves the cursor to the end of the line.
Ctrl + Left / Right: Moves the cursor to one word Left / Right.
Ctrl + R: Allows you to search through the previous commands.

Batch Rename Files
rename –v 's/foo/bar/g' *

Customize command line prompt
function prompt
local WHITE="\[\033[1;37m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local BLUE="\[\033[0;34m\]"
export PS1="${GREEN}\u${CYAN}@${BLUE}\h ${CYAN}\w${GRAY}$ "

\u refers to the current username
\h refers to the host name
\w refers to the current file path.

or simply uncomment the line force_color_prompt=yes in ~/.bashrc

You can use Docker for Windows as engine and docker client for linux in bash. "Docker for Windows" requires Windows 10 Pro 64-bit and Hyper-V Package.

To install docker client for Linux under bash shell
cd ~/
tar -xzvf docker-1.12.0.tgz
cd docker
./docker -H tcp:// ps

Or simply add the corresponding variables to ~/.bashrc
export DOCKER_HOST=tcp://
export PATH=$PATH:~/docker

To detach the docker tty without exiting the shell, use the escape sequence Ctrl-p + Ctrl-q

Install docker-compose and try docker-compose example as per
shell script    Select all
# install dcoker-compose curl -L`uname -s`-`uname -m` > ~/docker/docker-compose chmod +x ~/docker/docker-compose docker-compose --version # try docker-compose example on wordpress and mysql images cd $HOME mkdir my-wordpress cd my-wordpress cat > docker-compose.yaml <<EOF version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest links: - db ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress EOF # start the docker-compose example docker-compose up -d # then try browser http://localhost:8000/ # stop the docker-compose example docker-compose down

Swift 3 on Ubuntu (14.04 LTS trusty) for Windows 10 bash shell

You need to download and extract the development snapshot (Ubuntu 14.04) from and do these under bash shell.
shell script    Select all
# download and extract swift 3 snapshot cd ~/ wget tar xzvf swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04.tar.gz # the latest snapshot 2016-08-23 has libdispatch cd ~/ wget tar xzvf swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04.tar.gz # Swift 3.0 GM Candidate cd ~/ wget tar xzvf swift-3.0-GM-CANDIDATE-ubuntu14.04.tar.gz # Swift 3.0.2 Release cd ~/ wget tar xzvf swift-3.0.2-RELEASE-ubuntu14.04.tar.gz # install and configure clang plus other tools sudo apt-get update sudo apt-get install -y libicu-dev uuid-dev clang-3.6 sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 sudo apt-get install -y git build-essential # clears the executable stack flag of shared library sudo apt-get install -y execstack sudo execstack -c ~/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04/usr/lib/swift/linux/ sudo execstack -c ~/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04/usr/lib/swift/linux/ sudo execstack -c ~/swift-3.0-GM-CANDIDATE-ubuntu14.04/usr/lib/swift/linux/ sudo execstack -c ~/swift-3.0.2-RELEASE-ubuntu14.04/usr/lib/swift/linux/ # add path in ~/.bashrc export PATH=$PATH:~/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-3.0-GM-CANDIDATE-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-3.0.2-RELEASE-ubuntu14.04/usr/bin # test Foundation, libdispatch and swiftc compile cat > hello.swift <<EOF import Foundation let device = "WIN10" print("Hello from Swift on \(device)") //print("\(TimeZone.defaultTimeZone().name) \(NSDate())") // for old snapshot 2016-08-04 //print("\(NSTimeZone.defaultTimeZone().abbreviation()!) \(NSDate())") // for old snapshot 2016-08-23 print("\(NSTimeZone.default.abbreviation()!) \(NSDate())") // for Swift 3.0 GM Candidate // Test libdispatch import Dispatch var my_dispatch_group = DispatchGroup() let concurrentQueue = DispatchQueue(label: "myqueuename", attributes: DispatchQueue.Attributes.concurrent) for a in 1...20 { my_dispatch_group.enter() let block = DispatchWorkItem { print("do something at \(a)") } my_dispatch_group.leave() my_dispatch_group.notify(queue: concurrentQueue, work:block) } let item = DispatchWorkItem { print("PROGRAM ENDED \(NSTimeZone.default.abbreviation()!) \(NSDate())") } my_dispatch_group.notify(queue:, work:item) print("press enter to exit") let _ = readLine(strippingNewline: true) EOF swiftc hello.swift ./hello # test Swift Package Manager mkdir -p $HOME/test1 cd $HOME/test1 swift package init swift test

Install node.js and mongo shell for Ubuntu
shell script    Select all
# download and extract node.js cd ~/ wget tar xpvf node-v4.4.7-linux-x64.tar.xz # add path in ~/.bashrc export PATH=$PATH:~/node-v4.4.7-linux-x64/bin node --version npm --version # install mongo shell for version 3.2.8 # please refer to instructions here sudo apt-key adv --keyserver hkp:// --recv EA312927 echo "deb trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list sudo apt-get update sudo apt-get install -y mongodb-org-shell=3.2.8 # if you follow the previous post on example # you need to install mongodb server on the Windows platform # in order to test that example.

File System Access

Ubuntu filesystem from Windows Explorer
Ubuntu 16.04 filesystem from Windows Explorer, Fall Creators Update (2017 Oct)

Windows filesystem from Ubuntu bash

#edit ~/.bashrc
#add export LS_COLORS=$LS_COLORS:'di=1;44:' ; # dir white on blue background

To upgrade to Ubuntu 16.04 after Windows 10's Creators Update (2017 April)
open the Bash shell and run the following command:

sudo do-release-upgrade

lsb_release -a

However, lxrun /uninstall then lxrun /install is faster.

The lastest installtion of WSL is documented at
where different and multiple distros can be installed via Microsoft Store since Fall Creators Update (2017 Oct).

Installation of Swift 3.1.1 in Ubuntu 16.04
shell script    Select all
# Install related packages and set LLVM 3.8 as the compiler sudo apt-get -q update && sudo apt-get -q install -y make libc6-dev clang-3.8 curl libedit-dev libicu-dev libssl-dev libxml2 git libcurl4-openssl-dev pkg-config sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100 curl -fSLO # Swift 4.0 # tar xzvf swift-3.1.1-RELEASE-ubuntu16.04.tar.gz export PATH=$PATH:$HOME/swift-3.1.1-RELEASE-ubuntu16.04/usr/bin #test Hello mkdir Hello cd Hello/ swiftc --version swift package init --type=executable swift build ./.build/debug/Hello # test Swift Package Manager mkdir -p $HOME/SessionState cd $HOME/SessionState swift package init --type library cat > $HOME/SessionState/Sources/SessionState.swift <<EOF // SessionState.swift import Foundation import Dispatch public class SessionState { private var storage = [String:Any]() // serial access to internal dictionary // private let syncQueue = DispatchQueue(label:"serializationQueue") // change to concurrent queue private let asyncQueue = DispatchQueue(label:"asyncQueue", attributes:.concurrent, target:nil) private init() {} public static let shared:SessionState = { let instance = SessionState() return instance } () public func set( _ value: Any, forKey key: String) { asyncQueue.sync(flags: .barrier) { // change to barrier queue to have serial write access // syncQueue.sync { storage[key] = value } } public func object (forKey key: String) -> Any? { var result: Any? asyncQueue.sync { result = storage[key] ?? nil } return result } } EOF cat > $HOME/SessionState/Tests/SessionStateTests/SessionStateTests.swift <<EOF //SessionStateTests.swift import XCTest import Dispatch @testable import SessionState class SessionStateTests:XCTestCase { override func setUp() { super.setUp() } override func tearDown() { super.tearDown() } func testConcurrentAccess() { let asyncQueue = DispatchQueue( label: "asyncQueue", attributes: .concurrent, target: nil ) let expect = expectation(description: "Storing value in SessionState shall succeed") let MaxIndex = 2000 for index in 0...MaxIndex { asyncQueue.async { SessionState.shared.set ( index, forKey: String(index) ) } } while SessionState.shared.object(forKey: String(MaxIndex)) as? Int != MaxIndex { //nop } expect.fulfill() waitForExpectations(timeout:10) { (error) in XCTAssertNil(error, "Test expectation failed") } } static var allTests = [ ("testConcurrentAccess", testConcurrentAccess), ] } EOF # build and test swift test # Compile and install Boost sudo apt-get -q install -y build-essential cd $HOME curl -O tar xjvf boost_1_62_0.tar.bz2 cd boost_1_62_0/ ./ --with-libraries=atomic,chrono,date_time,exception,filesystem,graph,iostreams,math,program_options,random,regex,serialization,signals,system,test,thread,wave --prefix=/usr ./b2 -j6 toolset=gcc address-model=64 threading=multi link=static sudo ./b2 install # Compile and install QuantLib cd $HOME curl -O tar xzvf QuantLib-1.10.tar.gz # QuantLib 1.11 download link # cd QuantLib-1.10/ ./configure --prefix=/usr --enable-static --disable-examples make -j6 sudo make install # to remove -> sudo make uninstall # test QuantLib cd $HOME cat > $HOME/qlversion.cpp <<EOF #include <iostream> #include <ql/version.hpp> int main() { std::cout << "Current QL Version:" << QL_LIB_VERSION << std::endl; return 0; } EOF g++ qlversion.cpp -o qlversion ./qlversion # Following this instruction to install QuantLib Python #

Installation of Swift 4 for Cygwin64
shell script    Select all
# first install Cygwin64 in Windows # In Cygwin64 Terminal prompt wget -q tar zxf swift-4.0.3.cygwin.20180212-bin.tar.gz export PATH=$PATH:$(pwd)/usr/bin swift --version # test git clone cd example-package-dealer swift run Dealer