Updates

Pier Import Loses Ancestor Links

Suppose one has a wiki page for a project, named Smallwiki. Sub-pages can be added and link back to the main page with the text *..*. If the project changes name to Pier, then a single page can have the title changed and all of the sub-pages have the correct name.

An example of a parent link for this page is *..* which goes to Updates, and *../..* goes to John Borden.

A problem occurs when reading in a wiki during an upgrade. Each page is read as an independent entity with no reference to the other pages. A link to a parent like *..* is changed to *.*. This is the expected behavior when editing the root page.

One option is to link to the parent/grandparents/etc to be fully qualified before exporting:

(PRKernel instanceNamed: 'pier') root enumerator all; do: [ :page | page outgoingReferences do: [ :link | (link isInternal and: [ link target ~~ page and: [ page parents includes: link target ] ]) ifTrue: [ link reference: link target absolutePath ] ] ].

If one is not importing into the latest Pier code, this can convert back to relative links with:

(PRKernel instanceNamed: 'pier') root enumerator all; do: [ :page | page outgoingReferences do: [ :link | (link isInternal and: [ (link reference first = $/) and: [ page parents includes: link target ]]) ifTrue: [ link reference: (page relativePathTo: link target) ] ] ].
Posted by John Borden at 27 July 2022, 3:20 pm link

Remove PierAdmin from Baseline

Recently I removed an old task from a PierToDo. I noticed it raised a walked-back from PRAdminRemoveCommand>>#doValidate. The problem was the message self pierAdminAnnouncer returned nil. I was able to reproduce the problem in a clean Pier image using a simple component:

  1. Create a component and choose the counter option
  2. Increment the counter (it needs some sort of data)
  3. Click remove and confirm. Error is the same PRAdmin remove problem

Removing the page that contains the component does not raise the error.

Another problem is that http://localhost:8080/piersetup does not open due to missing the TWBSTabWidget class.

A straight-forward way to resolve this is to remove Pier-Admin from the Pier baselines. It is part of the add-Ons baseline, and the extentions are in part of the core baseline.

Posted by John Borden at 21 March 2022, 2:17 am link

Anagrams

I recently started playing a game against my wife called anagrams. Since she is rather good at it, my first attempt was to use command line and the MacOS dictionary:

0 Johns-MBP$ grep '^[pcilas][pcilas][pcilas][pcilas][pcilas][pcilas][pcilas]$' /usr/share/dict/words | grep -v ll
aplasia
asialia
classic
...

This wasn't very fast since it took too long to type the pattern, and also to guess what double-letter options should be avoided.

Next, created some Smalltalk code for possible matches:

| pattern matches stream |
pattern := 'ufmets' asBag.
matches := OrderedCollection new.
stream := '/usr/share/dict/words' asFileReference readStream.
[ stream atEnd ] whileFalse: [ | word boolean |
	word := stream nextLine.
	( word size <= pattern size and: [ (word allSatisfy: [ :c | pattern includes: c ]) and: [ boolean := true.
			word asBag doWithOccurrences: [ :letter :number | (pattern occurrencesOf: letter) < number ifTrue: [ boolean := false ] ].
			boolean ] ] ) ifTrue: [ matches add: word ] ].
stream close.
matches sorted: [ :a :b | a size > b size ]

This takes care of the double-letter problem, and won my first game. Unfortunately it requires a change in the pattern (the text ufmets above).

To make this faster, the next step is to allow the pattern as a command-line argument, this booklet explains the idea. Creating the class:

CommandLineHandler subclass: #WordCommandLineHandler
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'Custom-CommandLine'

On the class side, created:

commandName
	^ 'word'

Instance side has:

activate
	self activateHelp
		ifTrue: [ ^ self ].
	self arguments size = 1
		ifFalse: [ self printHelp.
			^ self exitFailure: 'Missing Arguments' ].
	self
		printAnagrams;
		quit

and:

printAnagrams
	| pattern matches stream |
	pattern := self arguments first asBag.
	matches := OrderedCollection new.
	stream := '/usr/share/dict/words' asFileReference readStream.
	[ stream atEnd ]
		whileFalse: [ | word boolean |
			word := stream nextLine.
			(word size <= pattern size
				and: [ (word allSatisfy: [ :c | pattern includes: c ])
						and: [ boolean := true.
							word asBag
								doWithOccurrences: [ :letter :number |
									(pattern occurrencesOf: letter) < number
										ifTrue: [ boolean := false ] ].
							boolean ] ])
				ifTrue: [ matches add: word ] ].
	stream close.
	(matches sorted: [ :a :b | a size > b size ])
		do: [ :str |
			str size > 2
				ifTrue: [ self stdout
						print: str;
						lf ] ]

After staving the image, this can be ran as:

0 Johns-MBP$ ./pharo ./anagram.image word pcilas
'spical'
'spica'
'scalp'
'salic'
...

As I was writing this, 3Blue1Brown released a wordle video that is related.

Posted by John Borden at 10 February 2022, 2:44 am link

JQuery Cycler

While working on the Pier editor, I've ran into several issues understanding the code (see Displaying Variables in Pier). To get a little more momentum, I started working on one of the Pier Components, the JQuery Cycler.

After working for a while, this may not be the most effective work - a slideshow like this can be done in CSS and HTML (see this example):

This is from when I removed the tile in my kitchen and added drywall.

Posted by John Borden at 10 December 2021, 1:18 am link

User in Changes Report

After upgrading this wiki to the latest code, the changes report displays the user as:

PUUser [1234] name: 'jborden'
While this only affects logged-in users who view the changes, it is annoying.

When researching this, I found:

  • The message PRContext(Object)>>#magritteDescriptionBuilders is missing QCDescriptionBuilderContainer (from the Magritte-Model package). This is also missing in an older image
  • This area also involves some internal code: Pragma allNamed: #magritteBuilder from: PRContext to: Object - For working and non-working, this returns an empty array.
  • When I was looking into PRHistoryView>>buildReport in the debugger, inspecting self buildDescription raised an error for kernel sent to nil

One option that resolves the issue:

PUUser>>#printOn: aStream
	"Needed so the changes view displays without 'PUUser[1234..] name: admin'."

	aStream nextPutAll: self name

This seems like a better solution since there are many problems. One is Pier does not yet work on Pharo 9 (first issue is in Pillar). I also noticed problems running Exercism in the new version too (seems to work best on Pharo 8).

More information on the Pier changes feature can be found on Complete Task in List of Changes.

Posted by John Borden at 28 August 2021, 5:11 pm link
<< 1 2 3 4 5 6 7 8 9 10 >>