Twigging

A page for discussing Twig

Stu 2008-11-16 Numbers and checksums on this page current as of their writing.


Preemptive Q&A:

Q: Isn't it dangerous to run code from strange places?<<br>>
A: The danger can be averted by checking the code then calculating
a checksum and verifying the code against the checksum before running it.
Hence, Twig.

Q: Ok, there's this page of 'twigs'.
What if someone alters the code then alters the checksum in that big bundle of twigs?
A: There is a checksum against the entire block (or 'bundle', if you prefer).

Q: What if someone alters that as well?
A: I keep the twig of that block on my site as well; you can check against that.

Q: Can I trust you?
A: I'd like to think so.

Q: I don't know ...
A: You can save the twig(s)/check the code yourself.

Twig

Get Twig from Twig or my site. If you're too lazy to copy & paste then wget and a bit of awk can do it. General use instructions on the Twig page.

How to use the twigs on the Twigs page (if you're not using TkTwig).
These examples assume that Twig is installed in your path as 'twig'.

# run #111
$ twig 21912 4 | awk 'NR==111 {print}' | twig -c - | wish &

# verify twigs, then run #111
$ twig 21912 2 | twig -c - | awk 'NR==111 {print}' | twig -c - | wish &

TkTwig

Get TkTwig from TkTwig or my site. Use it or Twig to get the twigs on the Twigs page or get them some other way. Find some new ones and share!

If you're really lazy, this will pull both TkTwig and the Tcler's Wiki twigs, combine and run.

(twig 21912 2 | twig -c - | awk 'NR==310 {print}' | twig -c -; echo 'set ::cow {'; twig 21912 2 | twig -c -; echo '};tktwig::loadBundle +::cow') | wish &

Or this:

(twig 21912 2 | twig -c - | awk 'NR==310 {print}' | twig -c -; twig 21912 2 | twig -c -) | wish -b - &

Mashups

Interesting results can be achieved by combining pages.

This combines the Starfield and Spirograph pages. I've found that Starfield can be mixed with many others.

(twig 21912 2 | twig -c - | awk 'NR==279 {print}' | twig -c -;twig 21912 2 | twig -c - | awk 'NR==276 {print}' | twig -c -) | wish &

These examples are long because they include the checking of the big twig bundle as well as each twig being used. The above could also be done as follows, without any checking. Be careful!

(twig 10100 1; twig 4206 2) | wish & 

TwigSrc

Augment source with Twig

# twigsrc.tcl
namespace eval twig {
        variable sourceMap; array set sourceMap {}
        rename ::source ::_source; interp alias {} ::source {} [namespace current]::src
        proc src {fn args} { variable sourceMap
                if {[info exists sourceMap($fn)]} { uplevel 1 [exec twig -c - <<$sourceMap($fn)]
                } else { uplevel 1 _source $fn {*}$args }
        }
        proc addSrc {fn twig} { variable sourceMap; set sourceMap($fn) $twig }
}
###

TwigSrc for card_img

# card_img.tcl twigsrc
twig::addSrc card_img.tcl {14629 1 C1C8795ED7BD3C21E742DE426FCE0AB2}
#

Twig for Spider Solitaire

# Spider Solitaire (11317) twig
21913 7 2710B2DEC0CAAFFC29B0B2AD6023A856
21913 8 A7920F2523921D0381AB4F21FEF3793F
11317 1 F267A7044616795D85B4D9EF7A4177DA

Twig for Once In A Lifetime

# Once In A Lifetime (11193) twig
21913 7 2710B2DEC0CAAFFC29B0B2AD6023A856
21913 8 A7920F2523921D0381AB4F21FEF3793F
11193 2 55F6103995FAEF1599178DBB039474BE

Twig for TriPeaks Solitaire

# TriPeaks Solitaire (13092) twig
21913 7 2710B2DEC0CAAFFC29B0B2AD6023A856
21913 8 A7920F2523921D0381AB4F21FEF3793F
13092 1 7C33DD1A1196BBE29508A1A1D782B472

Twig for scat

# scat (8810) twig
21913 7 2710B2DEC0CAAFFC29B0B2AD6023A856
21913 8 A7920F2523921D0381AB4F21FEF3793F
8810 1 797608C2FFCD7F0979AA28428E26358A

Run Spider Solitaire (9).
For the others, replace 9 with 10, 11 or 12.

$ twig 21913 9 | twig -c - | wish &

Procs from the Aether

$ twig -g -n 1923 1
1923 1 81B4E2D287A7D79CE4BA7550A7BE01EB {} K

% K a b
invalid command name "K"

% set ::auto_index(K) {{*}[exec twig -c - <<[concat 1923 1 81B4E2D287A7D79CE4BA7550A7BE01EB]]}

% K a b
a

% info procs K
K

% rename K {}

% info procs K

% K x y 
x

argv0/[info script]

argv0/[info script] fooler

# argv0/[info script] fooler
set ::argv0 [info script]

Run An i15d date chooser (1816).

$ twig 21913 18 | twig -c - | wish &

Run Canvas presentation graphics (3312) but check the twig first.

$ twig -s 951B07C2B414D5C94B14EDFB4196F257 21913 19 | twig -c - | wish &

Twig for An i15d date chooser (1816)

# An i15d date chooser (1816)
21913 15 CBC25E3921608AE2967A5C36F52540F9
1816 3 18C41EA8CE93DF04147D3E70B8111AC3

Twig for Canvas presentation graphics (3312)
To do this I had to revert my previous changes to the 3312 page so the twig for this on the Twigs page will no longer work. This is all a work in progress; the Twigs page should get updated often enough.

# Canvas presentation graphics (3312)
21913 15 CBC25E3921608AE2967A5C36F52540F9
3312 1 1E8C2A0214914C7C92C989CABA335FAC

I forgot about echo:// when I originally wrote this bit; it would be easiest to do with echo://.


OS File Locations

I'd like to run A little fortune teller but I don't run the same OS as the original author so my fortunes file is in a different location than specified in the code. To make this work, I've split the original code block into two blocks: the first sets the name of the fortunes file and the second is the rest of the code. All I need now is a twigged line of code setting the name of the fortunes file.

Fortunes file on OpenBSD

# fortunes file on OpenBSD
set filename /usr/share/games/fortune/fortunes

These are done a bit differently, a little more manual effort is involved.
The twigs could all be put into one file and that file twigged for extra ease and security.

First, gather some info

# standard fortunes file
$ twig -g 9425 1
9425 1 D990C81E4F6FD15F00BA3553A5CF8575
# fortunes prog
$ twig -g 9425 2
9425 2 2149D71A722942130CB7E7EE1529FBB4
# openbsd fortunes file
$ twig -g 21913 20
21913 20 3A324AB59E40E456134313F8263993BC

Run A little fortune teller (9425) (standard)

$ (twig -s D990C81E4F6FD15F00BA3553A5CF8575 9425 1; twig -s 2149D71A722942130CB7E7EE1529FBB4 9425 2) | wish &

Run A little fortune teller (9425) (OpenBSD)

$ echo "21913 20 3A324AB59E40E456134313F8263993BC\n9425 2 2149D71A722942130CB7E7EE1529FBB4" | twig -c - | wish &

It can also be done more directly. There are many ways to achieve the same result.

$ (echo 'set filename /usr/share/games/fortune/fortunes'; twig -s 2149D71A722942130CB7E7EE1529FBB4 9425 2) | wish &

Or skip making a twig and simply use echo://.

$ echo '{echo://set filename /usr/share/games/fortune/fortunes} 1 DO-NOT-VERIFY-SUM\n9425 2 2149D71A722942130CB7E7EE1529FBB4' | twig -c - | wish &

DO-NOT-VERIFY-SUM

It's big, ugly, and obvious - for a good reason. Having something like an empty string to signify that you wish to ignore the checksum would be overly prone to slipups. Therefore, if you wish to ignore the sum you have to spell out nice and big that that's want you want to do, no mistake. Running verified and checksummed code is the way of Twig.


Flowers

I was quite excited when I saw Flowers but a little let down that I'd have to download the images before using the program. Here's a bit of code that overrides the image command so that the files are retrieved using the http package. It cheats by knowing that the first three calls will be to load the files. After loading the last image it destroys itself and its associated globals and puts back the original image command.

# Flower picker
set _c 3; set _u http://pagesperso-orange.fr/maurice.ulis/tcl/
rename image _i;
proc image {create photo name -file file} {
        global _c _u
        package require http
        set tok [http::geturl $_u$file]
        _i create photo $name -data [http::data $tok]
        http::reset $tok
        if {[incr _c -1] == 0} { unset _c _u; rename image {}; rename _i image }
}

Put it together:

# Flower picker (21913:26) and Flowers (9888:2)
21913 26 6930BEA578BC001A56046F4C12E94F1D {} {Flower picker}
9888 2 925B0AD0046444A6C7A9ADF37F46F239 {} Flowers

Check:

$ twig  21913 27                                                         
# Flower picker (21913:26) and Flowers (9888:2)
21913 26 6930BEA578BC001A56046F4C12E94F1D {} {Flower picker}
9888 2 925B0AD0046444A6C7A9ADF37F46F239 {} Flowers

$ twig -g 21913 27                                                       
21913 27 E70D4DCA1844824DE053B85C23F27FD0

Run:

twig -s E70D4DCA1844824DE053B85C23F27FD0 21913 27 | twig -c - | wish &

Or:

$ eval `twig  21913 29`

TwigPack

TwigPack #1 - The Fall 2008 Collection

TwigPack #1 is TkTwig + 356 twigs and their code in a single ready-to-run file - all that's needed is Tcl/Tk.

Available on my site.

MD5: A852DC0E792F90066E7A64F30F1B4438