• Category Archives Coding
  • Spreading coding skills among the younglings (a plan in the making) #python

    Coding skills, even basic ones, are essential in this day and age. Alas, schools around here have not really caught on to this and IT lessons are not even mandatory in many schools around here. As far as I have been able to find out, the IT curriculum of the type of school where I will be teaching, consists entirely of getting pupils to use the MS Office suite correctly. This of course does not include any coding skills, only the formulas and macros in Excel, and I am not even sure if macros are part of the curriculum.

    So, I have decided to offer extra lessons in coding, if time and facilities at the school I will be teaching at, allows.

    Specifically, I will offer Python, because it is an easy language to learn, can be used for scripting and OOP and because you can have something interactive with just a few lines of code (it is theree in this example, but two would suffice to see results):

     

    print "This is a test program for console input."
    
    the_input = raw_input("Please give some input here: ")
    
    print the_input
    
    

    And seeing results quickly is essential for catching the puils‘ attention.

    I have enough material and knowledge to go into at least some depth of Python and let the pupils tackle a number of smaller projects which can be extended and built upon. I am thinking of things like a calculator, a Battleship type game and similar things, nothing too involved since time will most likely not allow for more. It is also likely that some pupils who are interested in learning to code will leave the course again once I tell them that they will not be learning any hacking skills at all.

    I guess I should also warn them not to attempt any hacking and/or go to websites where software for dubious purposes is peddled unless they can run a dual-boot or pure Linux computer with Kali Linux running on a virtual machine within the actual Linux OS (and not even think of hacking if they have no clue what I am talking about).

     

    So, let’s see how this develops and wether or not I will have the opportunity to teach Python, I hope I will.

     


  • Quoth the Server: „404“

    I have to thank my friend Stefan Kramperth for this one, he shared it in his stream. I was not aware of this modern parody of Edgar Allen Poe’s classic before, and I almost died laughing. As a heavy internet user and bibliophile who loves Poe almost as much as Lovecraft, I had to share this jewel:

     

    QUOTH THE SERVER „404“
    (Author unknown, if you know, let me know…)

    Once upon a midnight dreary, while I porn-surfed, weak and weary,
    Over many a strange and spurious porn-site of „hot chicks galore“,
    While I clicked my fav’rite bookmark, suddenly there came a warning,
    And my heart was filled with mourning, mourning for my dear amour,
    „Tis not possible,“ I muttered, „give me back my free hardcore!“
    Quoth the server, „404.“

    Once upon a midnight dreary, while I porn-surfed, weak and weary,
    For many a quaint and curious website of X-rated lore,
    Found the server nearly napping, http replies a-slacking,
    Though my loins were filled with burning, yearning for a teenage whore,
    And as I paused awhile in hope that service be restored –
    Quoth the server, „404.“

    Once upon a night-time dreary, as I web-surfed, red-eyed, weary,
    I resisted strange and lurid websites of hot sex galore,
    But my curiosity grew stronger; hesitating then no longer,
    I gave in and clicked the link to see what waited there in store.
    And with the clicking, came the ticking, of the page that was no more
    Quoth the server, „404“

    Once upon a porn-site dreary, where I lingered, red-eyed, bleary,
    O’er many a strangely grammared page of Russian girls galore,
    Closing popups then cascading, spyware programs now pervading,
    Came a sight that set me thinking, linking to hot chicks galore.
    „‚Fetch the URL,“ I muttered, but browser stuttered as before –
    Quoth the server, „404“

     


  • Coding Golang (Go) for Cthulhu #3 – Installing Go and LiteIDE

    The next of my tutorial videos concerning two things: Learning a programming language and worshipping Cthulhu at the same time.

    In this one, I talk about where and how to download and install Golang and the excellent LiteIDE on your computer.

    Here it is:


  • Coding Golang for Cthulhu #2 – Variables

    Today I continue with the basic tutorial for coding golang as part of the series Coding Golang for Cthulhu with a look at variables. Again, I have added a link to a google doc in the video with material for further reading, please enjoy and I hope you also learn something:

     

     


  • Coding Go/Golang for Cthulhu #1 – Introduction to Go

    I had this idea to combine two hobbies of mine and help spread knowledge at the same time. So what I did was starting a tutorial video series (may be just a mini-series) on programming using examples taken from the Cthulhu Mythos.
    The language I am using is Google Go, also known as Golang, since searching for „Go“ on the web gets you nowhere.
    Anyway, this is my very short intro video concerning Go / Golang with some links for ressources and a first example. „Cthulhu ftaghn!“ instead of „Hello World.“


  • A Basic Character Generator in Java

    When I swiched from Daily Steampunk to Meta Punk it was partly due to me wanting to branch out and do more stuff other than Steampunk, blog about other hobbies and interests of mine.

    As it states in the sub-headline of the blog, one of those is coding. I have been coding in my spare time for the last three years now and have earned a number of certificates in the process, one of them from Harvard, also as part of the EdX program I blogged about below.

    The course consisted of a number of lectures, some literature and problem sets. These usually were pre-coded code with some parts missing that we had to code by ourselves.
    The final project was different, here we got to do whatever we wanted. I, being a role player, chose to do a charcater generator. It is a pretty basic one (due to time constraints and the course did not ask for much either) but it was enough to pass with full points:

     

     

    Another dead give-away that this is a very basic character generator is, that it only uses two classes, one for the GUI (graphical user interface) and one for the dice-rolling, i.e. generating the character.
    I am aware that the generator class could have been split into several smaller classes for better readability and maintenance. These are the classes:

     

    package gui;
    import java.awt.event.ItemEvent;

    /**
    * @author Marcus
    *
    */
    public class Generators {
    private static int strength;

    private static int intelligence;

    private static int dexterity;

    private static int wisdom;

    private static int charisma;

    private static int constitution;

    private static String results = „People“;

    private static String s;

    private static int num = 0;

    public static int getNum() {
    return num;
    }

    public static void setNum(int num) {
    Generators.num = num;
    }

    static GUI_CharacterGenerator gt = new GUI_CharacterGenerator();

    // all getters and setters

    public static int getStrength() {
    return strength;
    }

    public static void setStrength(int strength) {
    strength = strength;
    }

    public static int getIntelligence() {
    return intelligence;
    }

    public static void setIntelligence(int intelligence) {
    intelligence = intelligence;
    }

    public static int getDexterity() {
    return dexterity;
    }

    public static void setDexterity(int dexterity) {
    dexterity = dexterity;
    }

    public static int getWisdom() {
    return wisdom;
    }

    public static void setWisdom(int wisdom) {
    wisdom = wisdom;
    }

    public static int getCharisma() {
    return charisma;
    }

    public static void setCharisma(int charisma) {
    charisma = charisma;
    }

    public static int getConstitution() {
    return constitution;
    }

    private static  void setConstitution(int constitution) {
    constitution = constitution;
    }

    public static String getResults() {
    return results;
    }

    public static  void setResults(String results) {
    results = results;
    }

    public static void randomNumbers() {
    // TODO Auto-generated method stub
    //System.out.println(„Hagara“);
    if (gt.getClassCheck()==0||getNum()==0){
    GUI_CharacterGenerator.setP(„You have to choose a character class first!“);
    }

    if (gt.getClassCheck()==1||getNum()==1){

    strength=(((int)(Math.random()*6))+12);
    intelligence=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    dexterity=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    constitution=(((int)(Math.random()*6))+((int)(Math.random()*6))+8);
    wisdom=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    charisma=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    //setCounter(1);
    //s = „pelepones“;
    setResults(s);
    //System.out.println(„Hagara2“);
    GUI_CharacterGenerator.setP(„Your stats are: \nStrength:  „+getStrength()+“\nIntelligence:  „+getIntelligence()+
    „\nDexterity:  „+getDexterity()+“\nConstitution:  „+getConstitution()+“\nWisdom:  „+getWisdom()+
    „\nCharisma:  „+getCharisma()+ „\nHitpoints: 12“);

    }

    else if (gt.getClassCheck()==2||getNum()==2){

    strength=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    intelligence=(((int)(Math.random()*6))+((int)(Math.random()*6))+8);
    dexterity=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    constitution=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    wisdom=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    charisma=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    GUI_CharacterGenerator.setP(„Your stats are: \nStrength:  „+getStrength()+“\nIntelligence:  „+getIntelligence()+
    „\nDexterity:  „+getDexterity()+“\nConstitution:  „+getConstitution()+“\nWisdom:  „+getWisdom()+
    „\nCharisma:  „+getCharisma()+ „\nHitpoints: 4“);

    }

    else if (gt.getClassCheck()==3||getNum()==3){

    strength=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    intelligence=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    dexterity=(((int)(Math.random()*6))+((int)(Math.random()*6))+8);
    constitution=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    wisdom=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    charisma=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    GUI_CharacterGenerator.setP(„Your stats are: \nStrength:  „+getStrength()+“\nIntelligence:  „+getIntelligence()+
    „\nDexterity:  „+getDexterity()+“\nConstitution:  „+getConstitution()+“\nWisdom:  „+getWisdom()+
    „\nCharisma:  „+getCharisma()+ „\nHitpoints: 6“);

    }

    else if (gt.getClassCheck()==4||getNum()==4){

    strength=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    intelligence=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    dexterity=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    constitution=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    wisdom=(((int)(Math.random()*6))+((int)(Math.random()*6))+8);
    charisma=(((int)(Math.random()*6))+((int)(Math.random()*6))+6);
    GUI_CharacterGenerator.setP(„Your stats are: \nStrength:  „+getStrength()+“\nIntelligence:  „+getIntelligence()+
    „\nDexterity:  „+getDexterity()+“\nConstitution:  „+getConstitution()+“\nWisdom:  „+getWisdom()+
    „\nCharisma:  „+getCharisma()+ „\nHitpoints: 8“);
    }
    setResults(s);

    }

    }

    And this is the GUI:

    package gui;

    //import GUI_CharacterGenerator;

    import java.awt.BorderLayout;
    import java.awt.EventQueue;

    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.JFileChooser;
    import javax.swing.JMenuBar;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JLabel;
    import javax.swing.ImageIcon;
    import javax.swing.JTextArea;
    import javax.swing.BoxLayout;

    import java.awt.FlowLayout;

    import javax.swing.SpringLayout;

    import com.jgoodies.forms.layout.FormLayout;
    import com.jgoodies.forms.layout.ColumnSpec;
    import com.jgoodies.forms.layout.FormSpecs;
    import com.jgoodies.forms.layout.RowSpec;

    import java.awt.Component;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;

    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.DefaultComboBoxModel;

    import java.awt.event.ItemEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.ItemListener;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;

    public class GUI_CharacterGenerator extends JFrame {

    private static String p;
    private JPanel contentPane;

    /**
    * Launch the application.
    */
    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    GUI_CharacterGenerator frame = new GUI_CharacterGenerator();
    frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

    /**
    * Create the frame.
    */
    public GUI_CharacterGenerator() {
    //Create a file chooser
    final JFileChooser fc = new JFileChooser();
    Generators gen = new Generators();
    setTitle(„D&D Character Generator“);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 828, 487);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu(„File“);
    menuBar.add(mnFile);

    JMenuItem mntmSave = new JMenuItem(„Save“);
    mntmSave.addMouseListener(new MouseAdapter() {
    JFileChooser FC = new JFileChooser();
    @Override
    public void mouseReleased(MouseEvent e) {

    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File(„/home/me/Documents“));
    int retrival = chooser.showSaveDialog(null);
    if (retrival == JFileChooser.APPROVE_OPTION) {
    try {
    FileWriter fw = new FileWriter(chooser.getSelectedFile()+“.txt“);
    //fw.write(„Test“);
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(getP());
    bw.close();

    } catch (Exception ex) {
    ex.printStackTrace();
    }

    }

    }

    });

    mnFile.add(mntmSave);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel CharacterImage = new JLabel(„“);
    CharacterImage.setBounds(0, -2, 451, 432);
    CharacterImage.setIcon(new ImageIcon(GUI_CharacterGenerator.class.getResource(„/images/default_griffin.png“)));
    contentPane.add(CharacterImage);

    JTextArea CharacterTextArea = new JTextArea();
    CharacterTextArea.setEditable(false);
    CharacterTextArea.setBounds(550, 46, 252, 296);
    CharacterTextArea.setText(„Select a character class!“);
    contentPane.add(CharacterTextArea);
    CharacterTextArea.setVisible(false);

    JButton btnCreateYourCharacter = new JButton(„Create your character“);
    btnCreateYourCharacter.setBounds(550, 353, 160, 23);
    contentPane.add(btnCreateYourCharacter);
    btnCreateYourCharacter.setEnabled(false);
    btnCreateYourCharacter.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    //createCharacterButtonActionPerformed(evt);
    gen.randomNumbers();
    //wtf();
    CharacterTextArea.setText(p);

    }
    });

    JComboBox characterChoices = new JComboBox();
    characterChoices.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent evt) {
    //characterChoicesItemStateChanged(evt);

    if (evt.getItem().toString()==“Make your choice!“){
    btnCreateYourCharacter.setEnabled(false);

    // System.out.println(„Warrior“);
    CharacterImage.setIcon(new javax.swing.ImageIcon(getClass().getResource(„/images/default_griffin.png“)));
    CharacterTextArea.setText(„You must choose a class first, before you can create a character.“);
    classCheck=0;
    }

    if (evt.getItem().toString()==“Warrior“){
    btnCreateYourCharacter.setEnabled(true);
    CharacterTextArea.setVisible(true);
    // System.out.println(„Warrior“);
    setClassCheck(1);
    gen.setNum(1);
    CharacterImage.setIcon(new javax.swing.ImageIcon(getClass().getResource(„/images/female_fighter.png“)));
    CharacterTextArea.setText(„The Warrior is skilled in combat, and usually \ncan make use of some of the most powerful \nheavy armor and weaponry in the game. \nAs such, the warrior is well-rounded \nphysical combatant. \nSometimes, the Warrior (or more often \nthe Knight, if it is a separate class) \nmay be able to learn basic magic, but its \ncapabilities in this field are somewhat limited.“);
    classCheck=1;
    }

    if (evt.getItem().toString()==“Mage“){
    //System.out.println(„Mage“);
    CharacterTextArea.setVisible(true);
    btnCreateYourCharacter.setEnabled(true);
    CharacterImage.setIcon(new javax.swing.ImageIcon(getClass().getResource(„/images/male_mage.png“)));
    CharacterTextArea.setText(„Mages are considered to be spellcasters \nwho wield powerful spells, but are \noften physically weak as a trade-off. \nMages are commonly confused with similar \noffensive spellcasting classes such as \nthe Warlock and the Necromancer. \nHowever, a Mage’s power is based on the \narcane and a Warlock or Necromancer’s \npower is based on darkness or death. \nMages are primarily based on wizards from \nassorted fantasy literature.“);
    classCheck=2;
    gen.setNum(2);

    }

    if (evt.getItem().toString()==“Rogue“){
    // System.out.println(„Rogue“);
    CharacterTextArea.setVisible(true);
    btnCreateYourCharacter.setEnabled(true);
    CharacterImage.setIcon(new javax.swing.ImageIcon(getClass().getResource(„/images/male_rogue.png“)));
    CharacterTextArea.setText(„The rogue can be the rather typical thief.\n Someone who makes his living \non the streets of the city, picking pockets \nand snatching goods from the market. \nMore experienced thieves might \nbecome burglars or other more \nspecialized kinds of rogues. \nSome may even train to become \nassassins or bards.“);
    classCheck=3;
    gen.setNum(3);
    }

    if (evt.getItem().toString()==“Cleric“){
    // System.out.println(„Cleric“);
    CharacterTextArea.setVisible(true);
    btnCreateYourCharacter.setEnabled(true);
    CharacterImage.setIcon(new javax.swing.ImageIcon(getClass().getResource(„/images/cleric.jpg“)));
    CharacterTextArea.setText(„The cleric is a healer, usually a priest\n and a holy warrior, originally modeled \non or inspired by the Military Orders. \nClerics are sometimes members of \nreligious orders. \nMost clerics have powers to heal wounds, \nprotect their allies and sometimes \nresurrect the dead, as well as summon, \nmanipulate and banish undead. „);
    classCheck=4;
    gen.setNum(4);
    }

    if(evt.getItem().toString()== „Make your choice!“){
    CharacterImage.setIcon(new javax.swing.ImageIcon(getClass().getResource(„/images/default_griffin.png“)));
    }

    }
    });
    characterChoices.setModel(new DefaultComboBoxModel(new String[] {„Select a Class“, „Warrior“, „Mage“, „Rogue“, „Cleric“, „Select!“}));
    characterChoices.setSelectedIndex(0);
    characterChoices.setBounds(398, 48, 142, 20);
    characterChoices.setToolTipText(„Choose your class“);

    contentPane.add(characterChoices);

    JButton btnReset = new JButton(„Reset“);
    btnReset.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    CharacterTextArea.setText(„“);
    //jLabel1.setIcon(new javax.swing.ImageIcon(„C:\\Users\\Marcus\\Pictures\\default_griffin.png“));
    characterChoices.setSelectedIndex(0);
    //CharacterTextArea.setText(„“);
    CharacterTextArea.setVisible(false);
    btnCreateYourCharacter.setEnabled(false);
    CharacterImage.setIcon(new ImageIcon(GUI_CharacterGenerator.class.getResource(„/images/default_griffin.png“)));

    }
    });
    btnReset.setBounds(714, 353, 73, 23);
    contentPane.add(btnReset);

    String p = „Nothing to see here“;

    }

    Generators gen = new Generators();
    private int classCheck;

    public int getClassCheck() {
    return classCheck;
    }

    public void setClassCheck(int classCheck) {
    this.classCheck = classCheck;
    }

    public static String getP() {
    return p;
    }

    public static void setP(String p) {
    GUI_CharacterGenerator.p = p;
    }

    }

     

    Now, if you copy this code and run it, you will notice the images do not appear, this is because I did not include them. I do not know who the artist is since I do not know anymore, where I got them from. I think it was from DeviantArt, but I was unabe to find them there. Anyway, I used them within the limits of fair use and if you happen to know who it was that created the character images and the Griffon, let me know.