sharen

A bash script to rename files using its sha256 hash number, no error trapping or anything yet.

#!/usr/bin/bash

function procfile {
	filename=$1
	filesum=$(sha256sum -b $filename)
	filesha=$(echo $filesum | cut -d " " -f1)
	# filesha=${filesum%-*}
	extension="${filename##*.}"
	newfilename=$filesha"."$extension
	mv $filename $newfilename
}

function showhelp {
	echo "sharen or $1, is a program designed to rename a specified file"
	echo "to its sha256 hash as its filename, preserving the file exitension"
	echo
	echo "The syntax"
	echo
	echo "	sharen filename"
	echo "		filename being the name of the file to process."
	echo
}

if [ -f "$1" ]; then
	procfile $1
else
	showhelp $0
fi

Adam Warlock

Photoshop edit of Adam Warlock, from his short tenure in Malibu Comics’ Runeverse. Text bubbled removed, graininess removed, color enhanced and resized.

Java OOP program to repeat a number of “Hello World” or other user defined string.

class helloOBJ
{
    Integer count;
    String Greeting;
    
    helloOBJ() {
        count = 10;
        Greeting = "Hello World.";
    }
    
    void assignGreeting(String s) {
        if(s!="") Greeting = s;
    }
    
    void assignCount(Integer i) {
        if(i>0) count = i;
    }
    
    public void run() {
        for(Integer i=1; i<=count; i++)
        {
            System.out.printf("[%04d] %s\n", i, Greeting);
        }
    }
}

class helloAPP
{
    public static void main(String[] args)
    {

        Integer pramCount = args.length;
        helloOBJ myObj = new helloOBJ();

        try {
            if(pramCount>=1) {
                Integer j = Integer.parseInt( args[0] );
                myObj.assignCount( j );
            }
            if(pramCount>=2)
                myObj.assignGreeting( args[1] );
            myObj.run();
        } catch (Exception e) {
            System.out.println("An error occured, check arguments.");
        }

    }
}

Syntax

helloAPP [count [custom string]]

Linkable Object C++ Hello World

// thello.hpp
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class THello
{
	string TGreeting;
	unsigned long TRepeatCount;
public:
	THello();
	THello(string UserGreeting);
	THello(unsigned long Count);
	THello(string UserGreeting, unsigned long Count);
	void AssignGreeting(string UserGreeting);
	void AssignRepeat(unsigned long Count);
	void operator<<(string UserGreeting);
	void run();
};

//thello.cpp
#include "thello.hpp"

void THello::AssignGreeting(string UserGreeting)
{
	TGreeting = UserGreeting;
}

void THello::AssignRepeat(unsigned long Count)
{
	if(Count>0) TRepeatCount = Count;
}

THello::THello()
{
	AssignGreeting("Hello World.");
	AssignRepeat(10);
}

THello::THello(string UserGreeting)
{
	AssignGreeting(UserGreeting);
	AssignRepeat(10);
}

THello::THello(unsigned long Count)
{
	AssignGreeting("Hello World.");
	AssignRepeat(Count);
}

THello::THello(string UserGreeting, unsigned long Count)
{
	AssignGreeting(UserGreeting);
	AssignRepeat(Count);
}

void THello::operator<<(string UserGreeting)
{
	AssignGreeting(UserGreeting);
}

void THello::run()
{
	unsigned int i = 1;
	while(i<=TRepeatCount)
	{
		cout << "[" << setfill('0') << setw(5) << i << "] ";
		cout << TGreeting << endl;
		i++;
	}
}

This creates an object that can be linked to a main program containing all hello world services to a parent program.

#include "hellolib\thello.hpp"
#include <cstdlib>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
	switch(argc)
	{
		case 1:
		{	THello World;
			World.run();
			break;
		}
		case 2:
		{
			long i = atol(argv[1]);
			THello World( i );
			World.run();
			break;
		}
		default:
		{
			long i = atol(argv[1]);
			string s = argv[2];
			THello World( s , i );
			World.run();
		}
	}
	return 0;
}

A sample program using that object.