Web Development at Pelfusion.com:

Barnsite's Blog - Don’t Fall Victim To The Windows / Microsoft Phone Scam! 

There are many phone scams where someone will ring you claiming to be from Microsoft, Dell, Apple, or some other known IT company.

They will tell you that they have detected issues with your computer, normally “security” issues.

They will often ask you to open the “Event Viewer” on your computer to show you the errors.

They will then ask you to go to a particular webpage and download some software that will fix your computer

Consider the following:

  1. Do Microsoft, Dell, Apple, etc have your telephone number: Probably NOT
  2. Do Microsoft, Dell, Apple, etc offer free support where they monitor your computer and offer to fix it over the phone: Definitely NOT
  3. Can Microsoft, Dell, Apple, etc see errors on your computer: Definitely NOT
  4. Would Microsoft, Dell, Apple, etc ring you and ask you to visit a webpage or install software on your computer: Definitely NOT
  5. If you do open the “Event Viewer” on your computer, as advised by the caller, will you see errors: Almost Certainly YES*
  6. Are these errors they can see or fix: Definitely NOT

Imagine someone knocked on your door and said, “I can tell your oven is broken and I can fix it if you give me your credit card details”, what would you do?

  • NEVER believe that any IT company will ring you out of the blue telling you that you have computer issues
  • NEVER go to a website that any caller tells you to go to
  • NEVER install any software that any caller tells you to
  • NEVER give your credit / debit card, or bank details to any cold caller

*All Windows computers will show errors in the “Event Viewer” (this is something the hoaxers rely on). They are generally unimportant errors that you don’t need to worry about, but the scammers rely on you thinking they have “seen” these errors and you need to take action.

Barnsite's Blog - Remove Characters in String T-SQL with No Loop Part 2 

Okay, expanding on what I did yesterday.

I Built a table, called ExclusionList with one field, ExcludedText



Then created a function:

CREATE FUNCTION [dbo].[udf_clean_string]
	@string VARCHAR(100)

    @string = REPLACE(@string,ExcludedText,'')
FROM ExclusionList

RETURN @string

You can then use like this:

FROM TableName

Barnsite's Blog - Remove Characters in String T-SQL with No Loop 

Ok, I’ve seen many ways to do this using loops, but nothing in plain T-SQL

Let’s say we have a string that may contain illegal characters, in my case it was project identifiers that needed to be used as file names for exporting. However, many had / or * in the names.

One thing I hate in T-SQL is loops, so having only found looping ways to solve this I started from scratch.

He’s my solution:

Build a table of exclusions, i.e. characters or strings that you want to remove from your string (in my example below this is a temp table, but I would make it a permanent table in the end solution).

Then use REPLACE joined to this table to clean the string e.g.

/*Create the temp table for the exclusion list table*/
CREATE TABLE #ExclusionList
	ExcludedChar VARCHAR(50)

/*Add the stuff we want to exclude*/
INSERT INTO #ExclusionList SELECT ''
INSERT INTO #ExclusionList SELECT '|'
INSERT INTO #ExclusionList SELECT '?'
INSERT INTO #ExclusionList SELECT '*'
INSERT INTO #ExclusionList SELECT ':'
INSERT INTO #ExclusionList SELECT '<'
INSERT INTO #ExclusionList SELECT '>'
INSERT INTO #ExclusionList SELECT '"'
INSERT INTO #ExclusionList SELECT 'egg'

/*Get the horrible string that we want to clean*/
DECLARE @string VARCHAR(50) = 'th""<i>???s:: :|||"<egg>wo|r|k|**s*< ">we*l::l::'

/*Do the SELECT*/
	@string = REPLACE(@string,ExcludedChar,'')
FROM #ExclusionList

/*Show the string post processing*/
SELECT @string

/*Drop the temp table*/
DROP TABLE #ExclusionList

If you run this you’ll see that all the excluded text has been stripped and you’re left with “this works well”.

I’m all ready thinking of ways this could be expanded, e.g. Exclusion List type added to the exclusion list, you could then maintain different lists for different things, e.g. File Names, Email Addresses, etc and just add a WHERE clause to the REPLACE select statement.

Any comments or ideas please let me know!

DarkLordofthePenguins's Blog - Black hat hacking I'm taking a couple of computer security related courses on Coursera. For those of you who are not familiar with Coursera, it's an online program that offers classes that anyone can take for free. The classes consist of video lectures along with quizzes and problems sets and sometimes supplementary reading material.

Currently I am taking a course in cryptography and a course in software security. I find both of them very enjoyable. The subject of computer security is fascinating both from the point of view of the defender and from that of the attacker. In the area of codes, for example, this amounts to the disciplines of cryptography and cryptanalysis, respectively. The cryptography class I am taking now teaches a little bit of both actually. It shows you how to make codes that are hard to break, and it also shows you how to break some codes that have been broken in the past, mostly for the sake of understanding how such attacks work for the sake of being able to defend against them. The Software Security class follows a similar agenda - it teaches you how to break security for the purpose of understanding how defenses must be set up.

I am becoming very interested in learning how to hack, and by hack I don't mean how to program. I mean how to dissect programs and get into the nitty-gritty details of computers and operating systems, and exploit security holes to my own advantage. I'm not interested in gaining such knowledge because I want to commit actual cyber-crimes. I am simply fascinated with the intellectual possibility of breaking security, and with the technical details of cyber-warfare. A lot of people when I say I want to learn to hack might conjure up mental images of me stealing people's credit card numbers, but that's not my intention at all. I am simply passionately curious.

I've been learning some basic black hat hacking skills, to the point where I could exploit some very insecure programs. I've been learning from my two classes, and learning about how to write viruses from Mark A. Ludwig's Little Black Book of Viruses. I'm far from being able to hack with any degree of mastery, but I'm getting some of the basic ideas, which I will share here. I believe it's against Codecall's terms of service to give tutorials on cracking, so I will try to give a basic idea of what I've been learning without revealing too much about how to do it. Basically, there are certain functions in C and C++ that are vulnerable to overflow attacks because they don't perform the necessary bounds checking, and these functions can be exploited to overwrite data used by the program. You can, for example, overwrite the program counter with the address of code that you inserted into the program with the same buffer overflow. Of course, there's the challenge of knowing where the buffers are in relation to each other, which is where tools like reverse engineering, debuggers, and NOPs come into play.

As for cryptography and cryptanalysis, I've always been fascinated by the eternal war between code makers and code breakers, and how the integrity of codes can be decisive in warfare. It was Allan Turing's genius in code breaking that was partly responsible for the Allies' victory in World War II. Code making and breaking continued to be decisive throughout the Cold War. A very smart cryptographer or cryptanalyst can easily win a cyber-war in today's world, and I always have this thought in my mind that someday I could be that person.

Then there's Mark A. Ludwig and his book on viruses. Of course it's centered around MS-DOS, but the architecture on which the viruses are based hasn't changed much since then and the virus technologies could probably fairly easily be adapted for modern operating systems given some understanding of how those operating systems work. Ludwig gives a very interesting perspective on viruses. In his introduction, he says that viruses are not to be seen as just a neussance; they are, in fact, the beginning of digital life, and they represent endless possibilities, the edge of a vast ocean that we have yet to sail. Viruses are worth studying, not just for their military value, but also for their analogy to biological life.

I think I would like to write some viruses, again, as an intellectual curiosity. I wouldn't send them to anyone, or if I did, they wouldn't be destructive in any way. I'm attracted to the challenge of bypassing security measures like antivirus software to get a virus to replicate on a remote machine. That sounds like it would be a much greater challenge than any of the programming I've done so far, since there would be actual software tools trying to stop me from doing it. I think what I would do is write viruses, test them on my own local network, and then publish them on my own website as a demonstration of my technical skill. I don't think there's anything illegal about that.

Well, that's all I have to write about this particular topic for now. This is an exciting new road for me, and I hope it leads me to places I never thought I'd go.
DarkLordofthePenguins's Blog - Essential skills for computer nerds This is something I did just for fun in my inordinate free time. I compiled a list of essential skills that are valuable for computer geeks and that every computer geek should at least try to learn how to do. This is meant as a "just for fun" thing where you can add up how many skills you know to see how good you are, as well as a helpful list of skills you can improve yourself by learning if you ever feel like you don't know where to go next. These skills range from really obvious "Computers for Dummies" type material to next-to-impossible feats that only a total wizard would be able to pull off.

Disclaimer: Some of the things on this list may be illegal depending on the jurisdiction and circumstances. I am not responsible for any criminal activities you decide to partake in as a result of reading this list.

Okay, now that that's out of the way, here's my list of 212 essential skills for computer nerds:

Turn a computer on
Log in
Use Windows
Use Mac OS X
Use Linux
Use a smartphone or tablet computer
Use a word processor
Pirate TV shows or music from YouTube
Pirate software through BitTorrent
Subscribe to and manage RSS feeds
Take a screenshot
Record your desktop
Use the DOS prompt
Use the Windows Powershell
Use the Unix CLI
Test network connectivity with ping
Build a computer
Upgrade hardware components
Install an operating system
Install a device driver
Boot up from a live CD
Access and edit the BIOS settings
Write C/C++ programs
Compile C/C++ programs
Create a web page in HTML
Format a web page with CSS
Script a web page with Javascript
Script a website with PHP
Manage a LAMP server
Manage a SQL database
Interface between a SQL database and PHP
Write formatted documents in troff
Write formatted documents in TeX
Write formatted documents in Postscript
Code in a functional language
Code in an assembly language
Program a floating-point unit
Write a BNF specification for a programming language
Change the DNS server from the default
Manually configure an IP address
Solder electronics components
Use a multimeter
Build software from source using a makefile
Write your own makefile
Use a text-based package manager
Free up memory by killing processes
Edit a routing table
Crack trial software so you can use it forever
Use a virtualization platform
Jailbreak an iPhone or iPad
Jailbreak an iPhone or iPad without downloading a jailbreaking app
Reverse-engineer binaries
Effectively use a packet sniffing program
Connect a home computer to the Internet
Set up a home network
Wire an RJ-45 connector
Trace a trojan back to its source
Write a trojan
Read other people's email
Validate a web page for HTML and CSS
Do basic image editing
Create a transparent or semitransparent image
Create a Flash animation
Create an HTML 5 animation
Use a 3D modeling program
Use a 3D printer
Create and/or extract a tarball
Create and/or extract a RAR file
Utilize loadable kernel modules
Utilize shared libraries
Program in the POSIX API
Program in the Windows API
Mount a remote filesystem through NFS
Use a breadboard
Build Arduino projects
Write an adventure program
Write a database system
Write an accounting package
Write a GUI program
Set up a firewall
Set up a managed switch
Set up a CISCO router
Use a vintage computer (pre-1995)
Repair a vintage computer
Program in BASIC
Set up a honeypot to mess with script kiddies
Create and delete user accounts
Use a proxy server to hide your IP address
Use the TOR browser
Recover deleted files
Securely erase files so they can not be recovered
Recover data from a damaged disk
Write a browser extension
Use Vim or Emacs
Create your own colorschemes for Vim or Emacs
Use ed
Program in Fortran
Program in Lisp
Renew an IP address from a DHCP server
Access gopherspace
Run a gopher site
Run a BBS
Use Usenet
Effectively edit the Windows Registry
Read a crash report
Write a sorting algorithm
Implement a linked list
Implement a binary search tree
Write a compiler
Use regular expressions
Implement a regular expression parser
Use Processing
Clear the cache
Delete cookies from your browser
Browse the Internet in incognito mode
Prevent buffer overflow vulnerabilities
Exploit a buffer overflow vulernability
Encrypt a file
Crack an encryption scheme
Copy a copy-protected disk
Boot into safe mode
Use a revision control system
Use a debugger
Write an XML parser
Write self-modifying code
Write a self-reproducing program
Use a disk backup utility
Secure a private WiFi network
Crack a private WiFi network
Connect a TV to a DVD player
Program a universal remote
Hide files on your computer
Effectively edit a video
Back up data to network storage
Use a cloud service
Play a MUD
Use the IRC
Join a multicast group
Launch a denial-of-service attack
Implement a graph traversal algorithm
Find very large prime numbers
Calculate pi or e to a thousand digits
Log into an anonymous FTP server
Set up your own FTP server
Write a batch file in DOS
Write a shell script in Unix
Patch together different scripting languages
Use sed and awk
Partition a drive
Format a drive partition
Wipe a hard drive
Defragment a hard drive
Clone a disk with Clonezilla or similar
Clone a disk with dd
Turn filesystem journaling on and off
Securely erase the free space on a hard drive (without effecting the filesystem)
Securely erase data on a solid state drive
Burn an ISO file
Create an ISO file from a disk
Create an ISO file from a directory
Create and extract a floppy image
Set up a swap space
Do a remote login with Telnet
Do a remote login with SSH
Run fsck in Unix/Linux
Overclock a CPU
Implement error detection and correction
Implement a compression algorithm
Write a command shell
Write a text processor
Write a device driver
Write an operating system
Write an expert system
Read and understand other people's code
Utilize Ajax
Use a content management system
Use a sound editing program
Make an SVG image
Use NMap or Nagios Core
Synchronize backups
Build a custom Linux distro
Use a text-based email client
Use the Windows Recovery Console or Windows RE
Set up a RAID system
Reinstall an OS from the recovery partition
Use a directory service
Implement a directory service
Make an animated GIF
Use fork-exec to spawn a program
Write a daemon
Write a cryptanalysis program
Spoof a MAC address
Test a TCP/UDP port with Telnet
Emulate Finger with Telnet
Forge mail with telnet
Program in the X Window system
Write a CLIST
Utilize the OpenSSL API
Utilize UML
Use a logic probe
Read and understand a datasheet
Simulate a finite automaton
Simulate a pushdown automaton
Simulate a Turing machine
Use a multithreading library to implement concurrency
Write a real-time program
Write a Sendmail configuration file
Trace someone's IP address from a forum post
Set up a Kerberos authentication system

0x00-0x04: Computer-illiterate
0x05-0x09: User
0x10-0x1f: Knowledgeable user
0x20-0x2f: Geek
0x30-0x4f: Nerd
0x50-0x6f: Hacker
0x70-0x8f: Wizard
0x90+: Technological badass

Tell me what you got. :D
DarkLordofthePenguins's Blog - Adventures in VirtualBox I've been doing a lot with computers lately - not a lot of programming really, but a lot of messing around with my computer, as well as learning new stuff. I'm going on a sort of intellectual adventure, a learning spree, a period of intense hyperfocus on technical stuff.

One of the first things I did was I learned how to use VirtualBox, and how to use it to install a legacy operating system (i.e. MS-DOS). The first thing I learned about VirtualBox was that it's from Oracle. I honestly had no idea until now. After that I got into the more nitty-gritty stuff. It turns out VirtualBox is actually pretty cool. It gives you options for what kind of hardware you want to emulate, and it creates a virtual computer with that hardware and lets you install an operating system on that computer. There are options for what OS to install, and many of them are explicitly supported, meaning you just select that OS, and VirtualBox selects all the necessary hardware for you so you don't have to. After that, you create a (rather large) file that will serve as a binary image of the hypothetical hard drive on which the operating system is stored. There are a few options for what file format to use. They include VDI, VMDK, VHD, HDD, QED, and QCOW. Never heard of any of these before, and I still don't understand the difference between them. Anyway, I selected VDI, which was the default.

I downloaded a copy of MS-DOS 5.0 from vetusware.com, a really awesome abandonware site. It came as a RAR file, which I had to download a special program to open (since Mac OS X doesn't have any native utilities capable of working with RAR files). When I unarchived the file, I found three .IMA floppy disk images. This was another learning experience, because I had never heard of this kind of file before. Once I had the VM set up, installing MS-DOS on it was fairly easy. I "inserted" the floppies by simply selecting the floppy images in the VirtualBox control panel. Pretty soon, I had a working copy of a MS-DOS 5.0 running on my computer.

I don't know about other versions of MS-DOS, but in this version, the first thing you see when you boot up is the MS-DOS Shell, a graphical frontend from which you can start the command prompt and various other programs and utilities, and also select files in a graphical manner. MS-DOS Shell even has themes that you can select. I selected a graphical theme, which wasn't character-based at all; it was true graphics - in 4-color monochrome. This was just surreal, because months earlier I had had a dream about using an old MS-DOS machine that was graphical, and it looked just like this.

I few other things: I had some difficulty making the VM truly full-screen, like having the MS-DOS command line take up the entire screen when in full-screen mode. I like the idea that I can fool people into thinking I actually installed a 24-year-old operating system on my Macbook. (Of course, I can do that with DOSBox if I have it in full-screen mode, but I can't truthfully tell people it's MS-DOS, because it isn't.) I somewhat solved the problem by decreasing the resolution of my monitor to 800 x 600 pixels. Now it fills up probably 4/5 of the screen, as opposed to half of it like before. Another thing: I found that MS-DOS 5.0 comes with Microsoft QBASIC. I just thought that was so cool. Of course it's nothing like Commodore BASIC, so what I learned in programming my C64 isn't going to work here. I'd like to get my hands on an old Microsoft QBASIC user's manual. That would be so awesome. :biggrin:

There are some problems I haven't solved yet. For example, I haven't figured out how to make the VM capture my mouse. When I tell it to capture, the Mac OS X pointer disappears, but it doesn't get replaced by a DOS-style pointer (for example, the reverse-video block pointer that you see in MS-DOS Editor). I also haven't found a way to install all the software that I downloaded from vetusware yet. They're in the form of directories containing all the necessary files, and I need to find a way to convert these directories into floppy images, and also to extract floppy images into directories. If I can find a way to do this, I'll finally be able to use programs like Turbo Pascal and IBM Fortran, where the installer tells you to insert disks into Drive A or Drive B. I can't really do that in DOSBox, because that would involve suspending the installer somehow so I can return to the command prompt and type "mount a: whatever" to "insert" the disk, and there is no way to suspend programs in DOSBox. In VirtualBox, you can just do all that from the control panel. No need to do any mounting or inserting within DOS.

I was originally going to call this blog entry "The Intellectual Adventures of Cthuluhu - VirtualBox, MS-DOS, cryptography, and more" and make it about all the cool stuff I've been doing/learning about lately, but it seems the VirtualBox/MS-DOS part has gone on longer than I initially anticipated, so I think I'll stop here. Maybe I'll write about cryptography, Unix, networking utilities, etc. in another blog.
Upstream's Blog - Running PHP script as daemon / system service / on reboot Hi folks,

Done something cool today, at least for me it's cool as its very handy. I desided to share it here as I don't come accross much info on these when I was looking for it myself. So here I go. The below bash script runs as a system service at start up on Ubuntu and all it does is start a background process with a easy to lookup process id (pid) and then runs a simple shell script that just does one thing: launch a php daemon with the command nohup php myscript.php. With only 2 edits we can run any php file as a daemon and that's really handy as they run at boot and can be called with service phpscript start/stop/reload.

Posted Image

I use this skeleton to run all my php daemons for my custom Twitter application for businesses. For example one of several of my php daemon scans for tweets (realtime) containing keywords specified by me and then send the tweets + lots of extra info via this daemon. PHP is often used this way in API programming. In example the Database Server for Twitter from dev140.com that I uses nohup php daemon.php to create the persistent connection to the api this way. It's really important that these run all the time as it sends tweets real-time when the are tweeted.
When running an application that is connected to an API like the Twitter streaming API (Firehose) we need to have a persistent connection with the Twitter API. Persistent
means connecting once and staying connected 24/7 and this 365 days a year. Or untill we need to reboot of course. Most API programming is done in PHP or something similar that doesn't involve much SSL or console operations as root on the web server so that is not something all API programmers have done much. Most would rather leave it that way, just like me some years ago because it involves new things like UNIX shell scripting (bash i.e.). But we need a program running 24/7 persistently connected to the API. So what to do?

Use PHP scripts as system scripts running as daemon and be a happy API programmer!

With this script we can run any PHP file as a daemon from boot as root and as a service and all we need to do is change the the program file name (php script) and its location (use absolute path only).

Connect to your server via SSL as root because only as root we can use get_tweets start/stop/reload for the seperate daemons. On Ubuntu we need to do the following to make a script into a daemon this way and also run them on system reboot.

1) create /etc/init.d/get_tweets
2) place code below in /etc/init.d/get_tweets (nano /etc/init.d/get_tweets)
3) sudo chmod +x /etc/init.d/get_tweets
4) update-rc.d /etc/init.d/get_tweets defaults 98 02
5) add line to rc2.d: /etc/init.d/update-rc.d /etc/init.d/get_tweets
5) add line to rc.local: /etc/init.d/update-rc.d /etc/init.d/get_tweets
6) reboot

Pay attention: don't place the files run as root in the folder /public_html or any subfolders of the folder. For example place the /dev140 folder somewhere in the same folder next to /public_html like /home/someuser/domains/example.com/dev140 and use this path for the PROG_PATH var and as the base url for this file.
# Provides: get_tweets
# Required-Start: 2 3 4 5
# Required-Stop: 0 1 6
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PHP get_tweets.php nohup daemons initscript
# Description: This file should be placed in /etc / init d

# Fill in name of php daemon file and run as System Daemon /

## If not already running start php daemon
start() {
    if [ -e "$PID_PATH/nohup php $PROG.pid" ]; then
        ## Program is running, exit with error.
        echo "Error! $PROG is currently running!" 1>&2
        exit 1
        ## Change from /dev/null to something like /var/log/$PROG if you want to save output.

        cd $PROG_PATH
        nohup php $PROG_PATH/$PROG > /dev/null &

        echo "nohup php $PROG_PATH/$PROG started as system service"
        touch "$PID_PATH/nohup php $PROG.pid"


## If runinng kill php daemon
stop() {
    if [ -e "$PID_PATH/nohup php $PROG.pid" ]; then
        ## Program is running, so stop it

       kill $(ps aux | grep "php $PROG_PATH/$PROG" | awk '{print $2}')

        rm "$PID_PATH/nohup php $PROG.pid"

        echo "System service $PROG stopped"

        ## Program is not running as system service, exit with error.
        echo "Error! $PROG not started!" 1>&2
        exit 1

        case "$1" in
        exit 0
        exit 0
        exit 0
        echo "Usage: $0 {start|stop|reload}" 1>&2
        exit 1
==== tested on ====

No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.2 LTS Release: 14.04 Codename: trusty
YoungPythoner's Blog - HTML5 VS ADOBE FLASH Welcome to my first blog entry! We read the HTML5 vs ADOBE FLASH:
I readed entries from other tecnology sites.
1. "Security Guard" (Security)
HTML5: Security is good i think, are you think so?
FLASH: There are many security opens. (Sorry for bad english.)
HTML5 won! +1 points. *ding ding ding*
2. "The Engine" (Performance)
HTML5: Tested on Youtube it's good.
FLASH: It's good but it's slowing sometimes.
HTML5 won! +1 points. *ding ding ding*
3. "Helper Man" (Help Documents)
HTML5: There are less documents than Flash just now!
FLASH: There are many documents for help!
FLASH won! +1 points. *ding ding ding*
4. "The Pencil and Paper" (Development)
HTML5: You must know JS. Actually CSS, PHP.
FLASH: You must learn FLASH! Just Flash!
I think HTML5 is easy, but FLASH too. To FLASH one point!
HTML5 = FLASH?! It's my think you must know. Hope you like it!
DarkLordofthePenguins's Blog - My new hacker toy I have an interest in old computer stuff, not just obsolete computers, but also ancient programming languages, deprecated networking technologies, antiquated operating systems, terminals and other peripherals, and computer manuals. My interest in old computers, as well as in computing in general, goes way back to my childhood in the 90s, when I was watching my older brother on his Apple ][c. I've been interested in retrocomputing and vintage computing for a long time, though my experience has been pretty much limited playing MS-DOS games in DOSBox and getting a few broken Apple computers from a freecycle. I've only used some emulators and some clones and newer versions of old Unix programs, and I've always dreamed of being able to experience the real thing. I mean dream in both senses of the word, as in I've actually had dreams about using old computers. It's something that is not just a conscious goal, but a subconscious yearning as well.

Needless to say, I was rather excited when I found that Ebay is full of auctions for old computer equipment and software. Commodore 64s, Apple ][c's, TRS-80s, even a couple of VAX minicomputers. You name it and you can probably find it on Ebay. So I joined Ebay and spent some time learning the ropes, trying to figure out how to fully take advantage of the system. I learned about automatic bidding as well as many other features of Ebay. I started bidding on a Commodore 64 that was for sale. The bidding got really fierce towards the end, but I won through a combination of clever maneuvers and blind luck. I was really excited by this. I had actually won something, and now I would finally be able to touch a working vintage computer. I didn't stick around to pay for it, since I was outside at night in the bitter cold (I don't have Internet access at home and the auction ended at 8:50 PM; I had to sit outside the library). I was freezing to death, so I just went home for the night and then took a long hot shower because I was so cold. I promptly went out the next morning and paid for the C64, and bought a monitor (not an auction) to go along with it.

Both the C64 and the monitor shipped sometime the next week. I had to go to the post office to get them. They were in two rather large boxes, very well packaged. I kept the boxes and all the packaging material so that I'll be able to transport them safely when I move out of the group home. The Commodore 64 was in its original box, along with a Commodore 64C power supply, video and audio cables for S-video display, the user manual, a joystick, and a cartridge for Jumpman Junior. The monitor was a Commodore 1702 color CRT. When I first hooked them up, I plugged the A/V cables into the RCA ports on the front, which were for composite video. This resulted in the screen being grey, with no color. Realizing that the cables were for S-video rather than composite video, I plugged them into the S-video ports in the back and moved the switch on the back panel indicating what set of ports to use. I turned the monitor and the C64 on and was welcomed by the Commodore startup message:
    **** COMMODORE 64 BASIC V2 ****
That was so cool. All caps, monospace, light blue text on a dark blue background, with the cursor blinking right below where it said "READY". I spent some time typing on the keyboard, getting used to the layout, and I also did a little bit of rudimentary BASIC programming. At first I didn't register any of it. This was too much of a shock for me. It took a while for me to register the fact that I had actually used and programmed a real vintage computer. Something I had dreamed of and fantasized about for so long, to the point where there was an almost mystical quality to it. This was no mere emulator. This was the real thing.

At first I wasn't that excited about it. But later, as I began to register what was truly going on, I felt thrilled. I kept turning the C64 on every day, just playing around with it. I set out to learn as much as I could about this computer. I learned more of the Commodore BASIC language, and I found some resources on archive.org. Here are some of the BASIC programs I've written:

This is a casino program. Before playing you bet a certain amount. The program displays three random suits, and if they are all the same, you win that amount. If they are not all the same you lose that amount. This is not actually the original code. The "SPADE", "HEART", "CLUB", and "DIAMOND" strings are actually replacement for the PETSCII characters for those suits. The program is rather frustrating, because you lose your money really quickly. I'm thinking of modifying it so that what you win is more than what you lose (say 5 times what you bet).
60 LET X% = INT(100 * X)
110 LET B% = INT(100 * B)
120 IF B% <= X% THEN 150
140 GOTO 90
150 LET A$(0) = "SPADE": A$(1) = "HEART": A$(2) = "DIAMOND": A$(3) = "CLUB"
160 LET Q$ = A$(INT(4 * RND(1)))
170 LET R$ = A$(INT(4 * RND(1)))
180 LET S$ = A$(INT(4 * RND(1)))
190 PRINT Q$; R$; S$
200 IF Q$ = R$ AND R$ = S$ THEN 210
210 IF Q$ <> R$ OR R$ <> S$ THEN 250
230 LET X% = X% + B%
240 GOTO
270 LET X% = X% - B%
290 PRINT "YOU NOW HAVE $"; X% / 100; "."
310 GET P$
320 IF P$ = "" THEN 310
330 IF P$ = "Y" THEN 90
340 END
This one is a display hack. It puts a wall of squares on the screen and then puts holes in the wall by randomly poking spaces into the screen memory. Soon it starts to look like a sponge, and then eventually it looks like a maze. You can stop it at any time by pressing the RUN/STOP key. By this time, I had learned about the CHR$() function, so the program code didn't include any graphical characters, and what you see is exactly what was on the C64.
20 PRINT CHR$(147)
40 FOR X = 1 TO 1000
50 PRINT CHR$(166);
80 LET X% = INT(40 * RND(1))
90 LET Y% = INT(25 * RND(1))
100 LET P = 1024 + X% + 40 * Y%
120 GOTO 70
130 END
This program displays the startup screen:
70 PRINT "    **** COMMODORE 64 BASIC V2 ****"
100 END
This program causes the C64 to look and act like a DEC VT220 terminal connected to a VAX minicomputer running VMS. Keep in mind I've never used said terminal, computer, or operating system, so this is a very primitive imitation:
120 GET K$
130 IF K$ = "" THEN 120
140 IF ASC(K$) = 13 THEN 160 : REM ENTER KEY
150 LET A$(I%) = K$
160 PRINT "*";
170 LET I% = I% + 1
180 GOTO 120
200 IF A$(0) = "V" AND A$(1) = "T" THEN 230
220 GOTO 100
250 END
My advocate at the group home asked me how I can use this Commodore 64 to achieve my goals. I told her that I don't see how it will help me in that area. I said it's not really something I can learn useful skills from; it's more just a hacker's toy, and it's something that will make me happy, so I don't regret spending my savings on it. Surprisingly, however, I've learned a great deal from messing around with this computer. It has opened my eyes to many new things. I've learned about sprite graphics, and about bitmaps. I've learned about character ROM, and how it can be used to generate characters on the screen in the absence of a graphical operating system (e.g. for the BIOS screen or a non-graphical OS). I've gained a better understanding of the limitations of operating systems, and realized that displaying text is not an inherent limitation; it's just easier to write a set of predefined patterns to predefined locations in the framebuffer than it is to create actual graphics; that's why you can play graphical games and run graphical applications on command-line OS's like MS-DOS and Commodore DOS. I've gained a more intimate understanding of how functions and subroutines are implemented, because BASIC's subroutine scheme is much like that used by assembly languages and machine languages. I have also been prompted to start studying reverse-engineering.

Though I don't have any software for it yet, I've learned to do a lot of nifty things on the Commodore. I found this website that shows the layout of the C64's memory, and from it I learned how to change the background and border color of the display. I've also learned how to more effectively edit programs. At some point I want to get a floppy drive for the C64, as well as some software on floppies. I tried inserting the cartridge I got, but couldn't seem to get it in.

So yeah. Old computers are awesome. This is the beginning of a strange and wonderful journey for me. I hope to amass a whole collection or vintage computers and software in the future.
DarkLordofthePenguins's Blog - New project: implementing a simple language I have now started on my first large-scale programming project since the good old days of 2011. I'm writing an interpreter for Boolean straight line programs. Straight line programs are a model of computation equivalent to finite automata and Boolean logic circuits. A straight line program is basically a simple program that has no flow control. Every instruction is either input, output, or computation. An instruction in a straight line program has a number, which increments by 1 for each instruction, followed by a command - either READ, OUTPUT, or a computation command - and then the operands of the command, which are either input variables or numbers of previous instructions. For example, if the commands are AND, OR, and NOT, a program for XOR would look like this:
( 1 READ x )
( 2 READ y )
( 3 OR 1 2 )
( 4 AND 1 2)
( 5 NOT 4 )
( 6 AND 3 5 )
( 7 OUTPUT 6 )
I chose to do Boolean straight lines because that's the kind that was described in the book I was reading, which gives this project as an exercise. There are other forms of straight line programs, for example, programs where the commands are arithmetic operators. Any straight line programming language with a sufficient set of operators is equivalent to a finite automaton. Of course the straight line model is not Turing-Complete; that would require branching or other flow control constructs.

As you can see, this provides a fairly simple language which is relatively easy to write a compiler or interpreter for. It's an ideal place to start, since I won't have to be worrying a lot about the fine details of the language and I can focus on the discipline of parsing. Here and possibly in future blog posts I will chronicle what I've done toward this end. I hope my writings will serve as a sort of amateur tutorial on the discipline of compiler design, written as a narrative of my own efforts to learn this discipline through practice.

Writing a compiler or interpreter requires a lot of initial planning before you start coding. This begins with specifying the syntax, semantics, and pragmatics or the language. Syntax refers to how the code is structured, e.g. right and left curly brackets have to match, etc. Semantics refers to what the code actually means and what it does; type-checking is generally considered a semantic issue. Pragmatics is mainly an optimization issue: what is the best way to implement a programming language?

Context-free grammars are generally sufficient for expressing the syntax of a programming language. The standard method is Backus-Naur form (BNF), which is a variation on this theme. I'm not going to launch into an explanation of formal grammars and BNF here, because that would make this blog entry much longer than I'd like it to be. I'd like to keep this on the topic of my project. As the first step in designing my interpreter, I came up with the BNF specification for the language of Boolean straight line programs:
<program> ::= <command> <program> | <command>
<command> ::= <input> | <output> | <computation>
<input> ::= ( <number> READ <variable> )
<output> ::= ( <number> OUTPUT <number> )
<computation> ::= ( <number> NOT <number> ) | ( <number> AND <number> <number> ) | ( <number> OR <number> <number> )
<variable> ::= u | v | w | x | y | z
<number> ::= <nonzero_numeral><sub_number> | <nonzero_numeral>
<nonzero_numeral> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<sub_number> ::= <sub_number><numeral> | <numeral>
<numeral> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
I have also determined what the tokens and lexemes for the language are (note that there are several possibilities for the choice of tokens and lexemes):
Tokens:         Lexemes:
<lparen>        (
<rparen>        )
<number>        1, 2, 3, 4, etc.
<command>       READ, OUTPUT, AND, OR, NOT
The next step after specifying the syntax is to figure out how to implement it in the code. I chose C as the language to write the interpreter in, simply because that is the language I'm most comfortable with. For the lexical analysis, a finite automaton is generally sufficient. I planned an automaton that would use a vector of bit flags for the state. The first few bits would denote the position within a lexeme, while the higher-order bits would be flags determining whether the scanner is inside a READ, OUTPUT, number, etc.

I came up with what I think was a rather clever trick for implementing token-lexeme pairs. I would use a union type where the tokens are the fields of the union and the lexemes are the values. Like so:
enum lparen { L };
enum rparen { R };
enum command { READ, OUTPUT, AND, OR, NOT };
union token {
        enum lparen lp;
        enum rparen rp;
        enum command cmd;
        int num;
Once the tokens are scanned, they can be arranged one-by-one into a doubly linked list. A doubly linked list will allow easy access to either end of the list, so that tokens can be accessed in the same order in which they were scanned.

After the syntactic analysis, the token-lexeme pairs will be arranged into an abstract syntax tree by the parser. I have not put much thought into how to implement this part. I'm also not entirely sure how the semantic analysis should be carried out, whether I should find some way to implement an attribute grammar.

Overall, this is a very exciting project that will take a lot of creativity to complete. I will be employing some of the most advanced knowledge and techniques I currently know.