Recent Updates Page 2 Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 5:58 pm on December 27, 2015 Permalink | Reply
    Tags:   

    Categories: Commodore ( 24 )

    How to create relative data files on your Commodore 128 

    Commodore-Logo-PaddedThe CBM DOS can write “relative data” onto disk, based on individual records. The advantage is that all space is allocated once and then randomly accessed if and when it’s needed – much like the tracks on a CD.

    This approach is different from sequential files, which have to read or write the whole file in one go (Apple call this “reading and writing atomically”). So finding the 50th record in a sequential file can take some time, whereas retrieving record 50 from a relative file is just as fast as retrieving record 1 or record 157.

    Let’s see how we can deal with such relative files in CBM BASIC 7.0. This works with all physical disk drives (1541, 1571, etc) as well as the SD2IEC card reader – but not with your trusty old Datasette (for obvious reasons).

    This was revolutionary back in 1982!

    Creating Relative Files

    Here we create a new file with a REL extension using the DOPEN# keyword. When we do this for the first time, we need to tell the operating system how much data we’d like to allocate per record. Anything up to 255 bytes is fine. We’ll use 100 bytes in this example (the letter L followed by the length).

    10 dopen#1,"rel test",l100
    20 for i=1 to 100
    30 record#1,i
    40 a$="record"+str$(i)
    45 print "writing record ";i
    50 print#1,a$
    60 next
    70 close 1
    80 print "all done!"
    

    When we create a new file, CBM DOS doesn’t know how many records we’ll need, but it will create as many as necessary on the file. Here we create 100 entries using a for loop and write them to disk using the PRINT# statement.

    Notice that before saving a record, we must position the record pointer using RECORD#. That’s how our data is written to the correct position on disk. The whole loop will take a while to complete, but all space will be allocated on the disk as soon as we CLOSE the file.

    To add more records, we’ll simply position the record pointer to a later entry – even if one does not yet exist. CBM DOS will create the last record and all records leading up to it so they can be used later, up to a maximum of 65535 (space permitting obviously).

    Reading data from Relative Files

    Much like with sequential data, we can either use INPUT# or GET# to grab the data for an individual record. INPUT# reads everything until a CHR$(13) is found and works much faster, while GET# reads data one character at a time and is a lot slower.

    10 input"which record shall we retrieve";r$
    20 dopen#1,"rel test"
    30 record#1,val(r$)
    40 input#1,a$
    50 close 1
    60 print:print a$:print
    70 print"need another one? (y/n)"
    80 getkey k$:if k$="y" then goto 10:else end
    

    Here we ask the user which record we want to retrieve. Next we open our relative file using DOPEN#, position to the desired RECORD# and then read in its value using INPUT#. When we’re done we close the file and ask if the user wants to retrieve another record.

    While this type of data access is quick and convenient, it doesn’t help much unless you know which record is stored at which position. Think of an address book application: to find “Johnny Appleseed” can’t be done unless you sift through every single record until you find him.

    Commodore therefore suggest to use sequential files alongside relative files, in which things like a last name could be saved together with the record number. Likewise, another sequential file could hold all records for the first names, and appended accordingly when a new record is created, or replaced when updated.

     
  • Jay Versluis 5:36 pm on December 27, 2015 Permalink | Reply
    Tags:   

    Categories: Commodore ( 24 )

    How to create sequential files on your Commodore C128 

    Commodore-Logo-PaddedSequential files are files to which we can write arbitrary data and read it back later. We can even append data to the file later without having to re-write the whole file.

    This works with the Datasette (tape drive) as well as floppy drives. Here’s how to do it in CBM BASIC 7.0:

    Creating Sequential Files

    The C128 has a few special commands up its sleeve to aid us in this task. Here we create a new file using the DOPEN keyword and write 100 statements to it.

    10 dopen#1,"@seq test",w
    20 for i=1 to 100
    30 a$="record"+str$(i)
    40 print#1,a$
    50 print "writing ";a$
    60 next
    70 close 1
    

    We’re creating a new sequential file (SEQ extension rather than the usual PRG), using the w after the filename so that BASIC knows to create the file. The @ sign in front of the file name makes sure this file is overwritten every time we run the programme – omit it if you don’t want that functionality.

    Next we create a loop and generate a variable spelling RECORD 1, RECORD 2, etc. That’s your data. Each entry may be up to 127 characters in length (I believe) and is saved to the file by using the PRINT# keyword. Anything we could print to the screen, we can also print to a file.

    With each new PRINT# command, a carriage return is saved to disk. This can come in handy when we’re reading the data back in. If you need special characters to separate your data, feel free to use them.

    Appending data to Sequential Files

    If we need to add anything to the file (much like Linux would add to the end of a text file using the “greater than” symbol), we can use the APPEND# keyword:

    10 append#1,"seq test"
    20 for i=101 to 150
    30 a$="record"+str$(i)
    40 print#1,a$
    50 print "appending ";a$
    60 next
    70 close 1
    

    APPEND# opens the file for adding data and positions the pointer after the last entry in our file. We’ll do something very similar as above, creating records 101 to 150 and adding them to the file. Make sure to CLOSE the file so all data is saved to disk.

    Reading Sequential Data

    Much like PRINT# can be used to write data to disk, we can use INPUT# to read data back – almost equivalent to the INPUT keyword get get user input from a keyboard. The only difference is that out input comes from a different device:

    10 dopen#1,"seq test"
    20 for i=1 to 150
    30 input#1,a$
    40 print a$
    50 next
    60 close 1
    

    Here we open our file with DOPEN# and grab each entry in the file using the INPUT# keyword. This will automatically position the next INPUT# when a carriage return is received (CHR$(13)).

    This will work just fine as long as the original data does not contain any special characters, like a scary comma. If you need such characters, or if you want to ignore the carriage return, you can also use the GET# command to read one character at a time from disk. This is dramatically slower though.

    Notice that there’s no “end of file” marker as such: right now we need to know how many entries there are and read them accordingly. Reading beyond the data in our file will simply repeat the last record (on real devices) or crash your system (on VICE).

     
  • Jay Versluis 10:30 am on December 24, 2015 Permalink | Reply
    Tags:   

    Categories: Commodore ( 24 )

    How to switch the Commodore 1571 into 1541 mode and back 

    Commodore-Logo-PaddedThe Commodore 1571 floppy drive powers up in compatibility mode and behaves just like a 1541 drive – unless a C128 is connected and sends it a fast serial transfer.

    They did this because otherwise the drive wouldn’t be compatible with the C64 and Plus/4.

    The C128 speaks to its attached disk drive when we power it on, and that’s how a 1571 turns on its super fast magical properties. Holding down the Commodore key will boot into C64 mode, and the 1571 will in turn reset itself to 1541 emulation mode.

    Lucky for us, we can change this with a simple command, no matter what computer we’re using or which mode we’re currently in. This is done by first opening a command channel and then sending the 1571 the following switch command:

    // switch on 1571 mode
    OPEN 15,8,15,"U0>M1"
    CLOSE 15
    
    // switch on 1541 mode
    OPEN 15,8,15,"U0>M0"
    CLOSE 15
    

    This will let the 1571 behave like a 1571 even when attached to a C64 or Plus/4: format floppies on both sides and enjoy 1328 blocks without flipping disks. Sadly it won’t transfer data any faster because the attached computers just can’t handle it.

    Conversely, if we want to use a C128 and have our drive remain in 1541 mode for testing or compatibility, it works equally well.

    Rebooting your computer will reset this value. As far as I know, there is no way to test which mode the drive is in before issuing either of the above commands.

     
  • Jay Versluis 2:47 pm on December 12, 2015 Permalink | Reply
    Tags:   

    Categories: Mac OS X ( 28 )

    How to check the Fan Speed on your Mac 

    Sometimes you may want to know how fast your fans are spinning, more as a “number value” rather than a “noise value”. While you can hear when your Mac in front of you is working hard, it’s impossible to tell how fast those fans are spinning when you’re miles away from your Mac in a data centre.

    Thankfully there is an easy way to read out the fan speed with a small built-in utility we can access from the command line. Launch a terminal session and issue spindump as admin user:

    sudo spindump
    
    Password:
    Sampling all processes for 10 seconds with 10 milliseconds of run time between samples
    Sampling completed, processing symbols...
    Spindump analysis written to file /tmp/spindump.txt
    

    It’ll take a few seconds, at the end of which a file is produced that tells you a lot more than just the fan speed. To filter this info out, issue the following:

    cat /tmp/spindump.txt | grep "Fan speed"
    Fan speed:       3151 rpm (-317)
    

    And there you have it! Execute this command under low load, then try again under heavy load to see your low and high spin numbers to get an impression how how busy your Mac’s fans are.

    To remove that temporary file and avoid your hard disk from being clogged up, issue this when you’re done:

    sudo rm /tmp/spindump.txt
    

    This may not be the most elegant way to read out your fan speeds, but it works without installing additional utilities. The spindump command is computationally expensive, so don’t do it continuously – there are better tools for that (such as smcFanControl, or others – see the link below).

     
  • Jay Versluis 11:31 am on December 2, 2015 Permalink | Reply
    Tags:   

    Categories: Mac OS X ( 28 )

    How to disable System Integrity Protection on OS X El Capitan 

    System Integrity Protection was introduced in El Capitan to add another layer of security to OS X. The system prevents the root user from doing things that are potentially harmful. Apple did this because any app at any time may ask for the administrator password and execute commands with elevated permissions, which is a big security risk on single user systems.

    There are downsides to yet another layer of security, and much like Gate Keeper, System Integrity Protection brings us one step closer to a completely locked off system like iOS. I guess that’s the long term plan.

    Until then, and if you need it, you can disable System Integrity Protection. Here’s how to do it:

    • boot into the Recovery Partition (hold down CMD + R during boot)
    • this takes a little longer than usual
    • when the system is back, select Utilities – Terminal
    • now type “csrutil disable”
    • close Terminal and restart the system

    You can check at any time if this feature is on or off by typing

    csrutil status
    
    System Integrity Protection status: disabled.
    

    Enable it again during a Recovery session by typing “csrutil enable” and El Capitan is secured again.

    To see what else this command has to offer, type csrutil without parameters:

    csrutil
    
    usage: csrutil <command>
    Modify the System Integrity Protection configuration. All configuration changes apply to the entire machine.
    Available commands:
    
        clear
            Clear the existing configuration. Only available in Recovery OS.
        disable
            Disable the protection on the machine. Only available in Recovery OS.
        enable
            Enable the protection on the machine. Only available in Recovery OS.
        status
            Display the current configuration.
    
        netboot
            add <address>
                Insert a new IPv4 address in the list of allowed NetBoot sources.
            list
                Print the list of allowed NetBoot sources.
            remove <address>
                Remove an IPv4 address from the list of allowed NetBoot sources.
    
     
  • Jay Versluis 11:03 am on November 24, 2015 Permalink | Reply
    Tags:   

    Categories: Themes, WordPress ( 25 )

    How to turn plain URLs into clickable links in WordPress 

    The marvellous P2 Theme has an interesting feature: write out a plain link, and it magically becomes clickable without explicitly adding the a href tag.

    This may not be a big deal if you’re writing posts in the visual WordPress editor rather than HTML, but for those of us who like to write in HTML, it’s just one less thing to worry about.

    I was investigating this feature recently, and it turns out WordPress has a built-in function that can do this: they call it make_clickable(), and it works with URIs, FTP, Email addresses and anything starting with www. The function is really easy to use too: it only takes one parameter (a string), and returns the clickable HTML code.

    $clickableText = make_clickable($plainText);
    

    Let’s see how to use it in context, using the TwentyThirteen theme.

    (More …)

     
  • Jay Versluis 9:58 am on November 21, 2015 Permalink | Reply
    Tags: ,   

    Categories: WordPress ( 133 )

    How to display Jetpack stats per post in WordPress 

    Some websites employ this or similar technologies to show how many views a single post has had. I was wondering how they did that without starting to count stats that have already been counted for several years, either by Google or by Jetpack.

    Yesterday I came across this post by Topher about how to render Jetpack Stats: http://wpgr.org/2013/03/02/rendering-jetpack-stats/

    I decided to test this in TwentyThirteen, and it works a treat – here’s how to do it. The principle will of course work with any theme.

    (More …)

     
  • Jay Versluis 2:21 pm on November 19, 2015 Permalink | Reply
    Tags:   

    Categories: Plugins, WordPress ( 19 )

    Zen Dash – Version 1.5 released 

    banner-1544x500

    I’ve just released an update to my Zen Dash plugin. Besides adding funky zen-bamboo artwork to the WordPress.org page, I’ve made the following minor amendments:

    • the option to hide the Jetpack menu now only shows up when Jetpack is activated, otherwise it’s hidden
    • I’ve verified compatibility with the immanent release of WordPress 4.4
    • added funky zen-artwork (see above, courtesy of GraphicStock)

    I’ve you’re one of the 70+ active lucky users, you can upgrade the plugin from within WordPress as usual, or you can download a copy from GitHub or the WordPress.org plugin repository:

    Questions, suggestions, translations and pull requests are always welcome!

    What is Zen Dash again?

    Zen Dash is a magical plugin that lets you get rid of the myriad of options in the WordPress admin area. I’ve created it because sometimes less is indeed more, and new users can get overwhelmed by the sheer volume of menu items, dashboard widgets and upgrade notifications.

    While it is possible to let casual users have privileges less than administrators (and therefore see less items), I found this ineffective. With Zen Dash you simply flick a switch and make things disappear that you don’t want to see everyday. You can just as easily bring them back if you need them.

    You can read more about Zen Dash in my release post, which even includes a video on how to use the plugin.

     
  • Jay Versluis 12:14 pm on November 19, 2015 Permalink | Reply
    Tags:   

    Categories: Linux, Mac OS X ( 76 )

    How to see which users are logged in on OS X and Linux 

    There are two funky commands that can help us see who’s currently logged in, and what operations were performed last. Those two commands are who and last.

    Let me show you how to use them.

    The who command

    Type who at the command prompt and you’ll see a list of currently logged-in users:

    who
    
    versluis tty1         2015-11-19 11:21 (:0)
    root     pts/0        2015-11-19 11:46 (10.0.1.55)
    

    This system has two users logged in: versluis, via TTY, and root via PTS. We also get to see which IP addresses these users are logged in from (:0 is localhost).

    On this note, TTY is the local text based terminal at the machine, while PTS is a pseudo-terminal. This is most likely an SSH session or similar, anything that’s happening remotely.

    who can also show us who we are, in case you’re ever logged in on a system and don’t know which user you are:

    who am i
    
    your-username-here
    

    You can also concatenate who am i into whoami.

    The last command

    The last command can take a moment to execute and will show a list similar to this:

    last
    
    versluis tty1         :0               Tue Feb 10 18:54 - down  (4+13:11)   
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 18:51 - 08:05 (4+13:14)   
    root     pts/1        10.0.1.43        Tue Feb 10 16:33 - 16:44  (00:10)    
    root     pts/0        10.0.1.52        Tue Feb 10 11:36 - down   (07:13)    
    versluis pts/0        :0.0             Tue Feb 10 11:35 - 11:35  (00:00)    
    versluis tty1         :0               Tue Feb 10 11:29 - down   (07:20)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 11:27 - 18:50  (07:22)    
    root     tty1                          Tue Feb 10 11:16 - down   (00:09)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 11:15 - 11:25  (00:10)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 10:59 - 11:25  (00:26)    
    root     tty1                          Tue Feb 10 10:29 - down   (00:28)    
    reboot   system boot  2.6.32-504.el6.i Tue Feb 10 10:28 - 10:58  (00:29)    
    
    wtmp begins Tue Feb 10 10:28:53 2015
    

    You can see who has logged in to the system recently, from which IP address, and when each session started and finished. You can also see when the system was last restarted (and in Linux, which Kernel was used to do so).

    The last line (on Linux, beginning with wtmp) shows since when the command was able to display results. last and who both read a file called wtmp (in /var/log/wtmp), which logs all login attempts over time.

    last accepts several filtering options too. For example, to query when a particular user has logged on and off, type last followed by the username:

    last versluis
    
    versluis tty1         :0               Thu Nov 19 11:21   still logged in   
    versluis tty1         :0               Tue Nov 17 12:44 - 22:32  (09:48)    
    versluis tty1         :0               Tue Nov 17 11:13 - down   (01:29)    
    versluis tty1         :0               Sat Oct 31 23:35 - crash (16+12:37)  
    versluis tty1         :0               Sun Aug  9 09:09 - down  (83+14:24)  
    versluis tty1         :0               Tue Jun 30 18:03 - down  (39+15:04)  
    versluis pts/0        10.0.1.52        Thu Feb 19 14:41 - 18:34  (03:52)
    

    Or if you’re only interested in restarts:

    last reboot
    
    reboot   system boot  2.6.32-573.8.1.e Thu Nov 19 11:20 - 12:02  (00:41)    
    reboot   system boot  2.6.32-573.8.1.e Tue Nov 17 12:43 - 12:02 (1+23:18)   
    reboot   system boot  2.6.32-573.7.1.e Tue Nov 17 11:12 - 12:42  (01:29)    
    reboot   system boot  2.6.32-573.7.1.e Sat Oct 31 23:34 - 12:42 (16+14:07)  
    reboot   system boot  2.6.32-573.1.1.e Sun Aug  9 09:08 - 23:33 (83+14:24)  
    reboot   system boot  2.6.32-504.23.4. Tue Jun 30 18:02 - 09:07 (39+15:05)  
    reboot   system boot  2.6.32-504.8.1.e Sun Feb 15 11:30 - 09:07 (174+20:37) 
    

    On OS X the output is somewhat more limited due to the absence of kernels, but it works just the same. For more information on each command, checkout the man pages with man last and man who.

     
  • Jay Versluis 6:06 pm on November 16, 2015 Permalink | Reply
    Tags:   

    Categories: Mac OS X ( 28 )

    How to burn an ISO image with OS X El Capitan 

    El-Capitan

    Sometimes it’s important that things change for no apparent reason. You know, the way they move things around in supermarkets just to drive you crazy.

    If you’ve tried burning an ISO image to disk in El Capitan recently, you know what I’m talking about:

    because the option to burn an ISO has been removed from Disk Utility.

    Yeah, I get it: plastic disks are out, no one should be using them anymore, there are no more Macs with SuperDrives in production as of 2016, so it’s time to remove this option from the built-in utility that had it for the last ten years. Think different. It keeps you sharp.

    Lucky for us plastic spinners, there are two (not so obvious) solutions: the command line and the good old Finder that can still burn disks for us. Here’s how to do it.

    Using Finder

    Apparently Finder always had the option to burn a disk image. I never knew that! All we have to do is:

    • insert a new blank disk
    • navigate to our ISO image
    • select it (single-click)
    • head over to File – Burn Disk Image “xxx” to Disk

    Screen Shot 2015-11-16 at 18.00.40

    Using the Command Line

    It’s for hackers really, but it’s very simple:

    • insert a blank disk
    • open Utilities – Terminal
    • navigate to the folder that holds your ISO image
    • issue the following command:
    hdiutil burn /path/to/your/image.iso
    
    Preparing data for burn
    Opening session
    Opening track
    Writing track
    .................
    Closing track
    .................
    Closing session
    ...................................................................
    Finishing burn
    Verifying burn…
    Verifying
    .........................................................................
    Burn completed successfully
    .........................................................................
    hdiutil: burn: completed
    

    El Capitan. There’s just more to love with every click.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel