Thursday, February 18, 2021

HP mini 1000 Reborn 2021

HP mini 1000 Reborn 2021


HP mini 1000 is my AE86 (Initial D), Atom CPU, 1+1Gb Ram, it was pre-installed with Windows 7(?), later I changed it to Hackintosh Snow Leopard, and now it is running Raspberry Pi Desktop OS (Debian 10 Buster).

Plastic casing, but good build quality.

HP mini 1000 has many similar variant. The series I am refering has 2 version, the normal black color swirl pattern, and the red color Vivienne Tam special edition 紅牡丹. Mine is black.

Vivienne Tam 譚燕玉 is a fashion designer, settle in New York now. Her design inspired with her Chinese culture background.

HP mini has the best *netbook keyboard*. Netbooks are small in size, but this HP mini keyboard is bigger and easier to type.

Cnet review here

Youtube

HP mini 1000 http://fuyichin.blogspot.com/2008/12/hp-mini-1001tu-hardware.html

HP mini Vivienne Tam 2nd edition. https://fuyichin.blogspot.com/2010/07/hp-mini-210-vivienne-tam-edition.html

J2ME Jumpstart Tutorial With Wireless Toolkit 2.5.2

J2ME Jumpstart Tutorial With Wireless Toolkit 2.5.2


Introduction


I am late by 20 years, but I believe there are still some values with this old software.

In Java 1.2, Java split into 3 categories, J2SE, J2EE and J2ME. J2SE (Standard Edition) is the original Java from Java 1.1. J2EE (Enterprise Edition) is for building server side web application. J2ME (Micro Edition) is a subset of J2SE, with a small footprint to run on mobile and other microprocessors platform.

J2ME was designed to run on low memory and storage, 512k ram or less. In real implementation J2ME vm can runs on 8k ram (as stated in squawk documentation).

J2ME has a configuration base and a profile (J2ME=Configuration+Profile). There are 2 configurations in J2ME, CLDC and CDC. CLDC (Connected Limited Device Configuration) with a smaller footprint. There are more profiles available, the most common is MIDP.

This tutorial focus on CLDC+MIDP.

Software you need to compile MIDP program


1. Java jdk compiler (Java SE)
2. Sun wireless toolkit (which includes CLDC configuration, MIDP profile, preverifier and emulator).

The process to compile MIDP program:
1. compile with java compiler.
2. preverify with the preverifier.
3. package into j2me package.

Sun wireless toolkit 2.5.2


The Sun wireless toolkit (WTK 2.5.2) is a very old software. It might not runs on your system. I have tried on macOS (High Sierra) and Linux (Raspberry Pi Desktop OS), encounter some issues but there are workaround for it.

Download from the Oracle website https://www.oracle.com/java/technologies/java-archive-downloads-javame-downloads.html. Choose your OS platform. There is no macOS platform for WTK 2.5.2, just the Linux version to install.

Install (macOS)
$ chmod +x sun_java_wireless_toolkit_xxx_.bin.sh
$ ./sun_java_wireless_toolkit_xxx_.bin.sh

Read the license. Do you agree to the above license terms? [yes or no] yes
Specify a path to Java interpreter directory: [ /Library/Java/Home ]
(I use /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home )
Directory to install the toolkit: /usr/local/wtk-2.5.2

Test the installation
$ cd /usr/local/wtk-2.5.2
$ bin/ktoolbar
⇒ error
Mac/ktools.properties (no such file)

$ cp lib/Linux/ktools.properties lib/Mac/ktools.properties
$ bin/ktoolbar


to be continue... next will talk about how to write and compile a j2me midp program.

Thursday, February 11, 2021

Python Example Show Big2 Cards Order

Python Example: Show Big2 Cards Order



How to print out the big2 card order in Python?

> cards= list(range(52))
> cards.sort(key=lambda x:(x+12)%13*4+x//13)

[1, 14, 27, 40, 2, 15, 28, 41, 3, 16, 29, 42, 4, 17, 30, 43, 5, 18, 31, 44, 6, 19, 32, 45, 7, 20, 33, 46, 8, 21, 34, 47, 9, 22, 35, 48, 10, 23, 36, 49, 11, 24, 37, 50, 12, 25, 38, 51, 0, 13, 26, 39]

Diamond-23456789TJQKA Club-23456789TJQKA ...

The code id 1 mean D3, 14-C3, 2-D4...39-Spade2

The 2 lines of python code looks simple, but hard to read and understand. I will show you how to do it step by step.

Normal card


First I create a deck of normal cards (52 cards), assign an id for each card from 0..51. Starts from Diamond suit 0-10, JQKA, then Club, Heart and finally Spade. The id does not show the card order by value. The order by value should be D2,C2,H2,S2,... D3,C3…, DA(Diamond Ace), CA, HA, SA.

$ edit card.py
# poker card program

def get_card_name(card):
    ''' pass in the card value, return card name eg. D3-Diamond 3, ST-Spade 10, HA-Heart Ace '''
    suit= ''  # Diamond, Club, Heart or Spade
    value= 0
    if card>=0 and card<13:
        suit= 'Diamond'
    elif card>=13 and card<26:
        suit= 'Club'
    elif card>=26 and card<39:
        suit= 'Heart'
    else:
        suit= 'Spade'
    
    value= (card % 13) + 2
    if value==11:
        value= 'J'
    elif value==12:
        value= 'Q'
    elif value==13:
        value= 'K'
    elif value==14:
        value= 'A'
    else:
        pass
    
    return (suit,value)

def show_hand(cards):
    ''' show cards on hand '''
    for card in cards:
        print(get_card_name(card))

def get_card_value(card):
    ''' convert id 0..51 to value eg. D2=0, C2=1, H2= 2, S2=3, D3= 4 '''
    suit= card//13
    value= card%13
    return value*4+suit
get_card_name() shows a more readable card name:
> get_card_name(0) ⇒ ('Diamond',2)

show_hand() shows all the cards in a list:
> show_hand([0,8,23,24,44])
('Diamond', 2)
('Diamond', 10)
('Club', 'Q')
('Club', 'K')
('Spade', 7)

get_card_value() return the actual value or the card. eg. D2-0 C2-1,...
> cards= list(range(52))
> cards.sort(key=get_card_value)
> show_hand(cards)
('Diamond', 2)
('Club', 2)
('Heart', 2)
('Spade', 2)
('Diamond', 3)
...
('Heart', 'A')
('Spade', 'A')

Big2 card


In the big2 game, 2 is the largest value in a suit. So the order is Diamond 3456789TJQKA2. To sort the cards, you need a new function to replace the get_card_value().
$ edit big2_card
from card import show_hand

def get_big2_value(card):
    ''' D3=0 C3 H3 S3 D4 ... SA D2 C2 H2 A2 '''
    ''' id 1=D3 5=C3 9=H3 13=D4 '''
    suit= card//13
    value= (card+12)%13  # change 2 as the largest value
    return value*4+suit

cards.sort(key=get_big2_value)
show_hand(cards)  
  

⇒ [1, 14, 27, 40, 2, 15, 28, 41, 3, 16, 29, 42, 4, 17, 30, 43, 5, 18, 31, 44, 6, 19, 32, 45, 7, 20, 33, 46, 8, 21, 34, 47, 9, 22, 35, 48, 10, 23, 36, 49, 11, 24, 37, 50, 12, 25, 38, 51, 0, 13, 26, 39] (means [D3, C3, ... S2])

('Diamond', 3)
('Club', 3)
('Heart', 3)
('Spade', 3)
('Diamond', 4)
...


Use sort with Lambda



Lambda function format: f= lambda x: x*x. The lambda function only have 1 return expression, is this case it is x*x.
> f(5) ⇒ 25

> cards= list(range(52))
> # cards.sort(key=get_big2_value)
> cards.sort(key=lambda x:get_big2_value(x))

It also can be written as
> cards= list(range(52))
> cards.sort(key=lambda x:(x+12)%13*4+x//13)

Note: The expression evaluated from get_big2_value(), is hard to read. Referring to get_big2_value() should be easier.

Thursday, February 04, 2021

An Interesting Experience To Install Software On Windows 7

An Interesting Experience To Install Software On Windows 7


My Windows 7 is for fun, it is outdated, sitting there for several years doing nothing. I just want to play around with it before I upgraded to Windows 10. To install some software like Java, Growl and Python.

After having some fail attemps, I feel like Windows system is a big pile of junks messy software code, around 15-20Gb, but still can find something useful out of it.

The process is interesting, so I write it down.

Software Package Manager


The original software manager from Windows is always not good. The first things I am doing is install a 3rd party software manager tools to help me to get the job done. I have tried Scoop many years ago, now I want to try something else, there are quite a few 3rd party tools available, like Chocolatey, OneGet, AppGet. All fail to be installed as Windows 7 is just too old.

Microsoft came out a new software manager, WinGet on May 2020, it is new and only support Windows 10. It is a copycat of AppGet. So my first choice is try AppGet.

AppGet


AppGet fail for the first time, it was unable to download and update the dot net framework. AppGet base on .Net. Later I try the second time, it was able to download the dot net framework. It says AppGet was installed, but I can't find the appget.exe!!

Chocolatey


Let's try Chocolatey. Requirement Windows 7+, PowerShell v2+, sounds good to go.

There are a few methods to install, first try install from PowerShell. It says need PowerShell v3, mine is v2.

PS C:\> Get-Host
==> Version: 2.0

Try Basic Cocolatey Install: cmd


@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Exception calling "DownloadString" with "1" argument(s): "The underlying connec tion was closed: An unexpected error occurred on a send."
At line:1 char:54
+ iex ((New-Object System.Net.WebClient).DownloadString <<<< ('https://chocolat ey.org/install.ps1'))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException


Try PowerShell, fail.

PowerShell


Try upgrade to PowerShell. I have tried a few times before successfully updated to PowerShell 5.

You can try by installing the WMF 5.1 https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf/setup/install-configure?view=powershell-7.1#download-and-install-the-wmf-51-packagePowerShell 5

Scoop


I have tried Scoop before, it was working, but now it says it need PowerShell v5.

Try to upgrade to PowerShell v5, but install Windows Management Framework 5.1 fail! (I have tried a few more times before I succeed)

PS C:\> iwr -useb get.scoop.sh | iex
iwr : The request was aborted: Could not create SSL/TLS secure channel.
At line:1 char:1
+ iwr -useb get.scoop.sh | iex
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], W...
eption
+ FullyQualifiedErrorId :
WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand


You need to upgrade PowerShell to get it work. In my opinion, is not a good idea to write the installation script, rely on PowerShell.

Python: missing DLL


I have tried a few version 3.7, 3.8, 3.9, 32bit and 64bit version, all having 1 problem:

Error:Error: api-ms-win-core-path-l1-1-0.dll is missing from your computer…...

No luck, still unable to solve.

FULL STOP. Oh Microsoft!!!