New Video Tutorials - Looking for Topic Suggestions

Discussion in 'Programming' started by Dennis M., Aug 7, 2011.

  1. #1
    Hello everyone,

    I have just released a new video tutorial service. I currently have 2 lessons up in a series I am writing known as "Teach Me To Program C++"

    I am looking for interested users in submitting video requests of tutorials they would like to see. I will try to complete the requests as quickly and as thoroughly as possible. Do not worry about the level of difficult of your request; I am not necessarily looking for "beginner topics," but rather, anything that people seem to be interested in (i.e. I do need to add every topic to a "Teach Me..." series video).

    I will be more than happy to mention the user in the video and comments and provide a link-back to the user who requested a given topic if I create a video on it.

    Anyway, please post suggestions here in this post or via PM!

    Thanks for your help.

    Topics I am looking for:
    • C
    • C++
    • PHP
    • MySQL
    • Java
    • Javascript
    • HTML
    • AJAX

    Note: I will take other topics into consideration as well, however.


    Regards,
    Dennis M.

    P.S. The channel is located here: Microsonic Development Videos
     
    Dennis M., Aug 7, 2011 IP
  2. dthoai

    dthoai Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    38
    #2
    I would like to parse java source code and convert it to apex source code. Could you please teach me how to do?
     
    dthoai, Aug 7, 2011 IP
  3. Dennis M.

    Dennis M. Active Member

    Messages:
    119
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Certainly - however, are you looking for a simple solution or just how to do such a thing (and do you mean java or javascript)? In order to write a parser, you would have to go through every uncommon function for each language and have a valid conversion. Ultimately, this would be no easy task - you would have to understand both languages very well. Can you please elaborate a little more on what you expect? I can then let you know whether it is out of the scope of a "tutorial" or not.

    Regards,
    Dennis M.
     
    Dennis M., Aug 8, 2011 IP
  4. dthoai

    dthoai Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    38
    #4
    Thanks for your reply. I'm not sure my request is in of the scope of "tutorial" because it's complex and hard.

     
    I would like to know how to do such a thing. I mean java.

     
    Actually, I would like to convert Lotus Script, JavaScript, VBScript and @formula in Lotus Notes form to Apex classes and Visualforce pages. But it's complex. I would like to see an example for converting java code to apex code. Learning from that example, I will develop my converter.
     
    dthoai, Aug 8, 2011 IP
  5. Dennis M.

    Dennis M. Active Member

    Messages:
    119
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Well in terms of Java and Apex, the languages are really very similar. Some types are different (i.e. int vs. Integer for basic integer-type). Do you have a relatively short Java class or something you would like converted? Below I have a very trivial conversion (including a test case for Apex), however, it may be too trivial for actual use. If you can give me an example of something which you would like to convert, I may be able to help better by converting that class (again, it should be a single class which is relatively small). Also note, Apex has "implement" and things of that nature like Java for abstract classes.

    Java:
    public class SomeNumber
    {
      private int number;
    
      public int getNumber()
      {
        return this.number;
      }
    
      public void setNumber(int number)
      {
        this.number = number;
      }
    
      public static void main(String[] args)
      {
        Main t = new Main();
        t.setNumber(20);
        System.out.println(t.getNumber());
      }
    }
    
    Code (markup):
    Apex:
    
    public class SomeNumber
    {
      private Integer num;
      
      public void setNumber(Integer num)
      {
        this.num = num;
      }
      
      public Integer getNumber()
      {
        return this.num;
      }
      
      static testMethod void testSomeNumber()
      {
        SomeNumber n = new SomeNumber();
        n.setNumber(20);
        System.assert(n.getNumber() == 20);
        n.setNumber(32);
        System.assert(n.getNumber() == 32);
      }
    }
    
    Code (markup):
    Regards,
    Dennis M.
     
    Dennis M., Aug 8, 2011 IP
  6. dthoai

    dthoai Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    38
    #6
    I would like to see example of converting following java class to apex class.

    
    package com.bhivef.gomoku.core;
    
    
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.security.GeneralSecurityException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Properties;
    
    
    import javax.crypto.Cipher;
    import javax.crypto.spec.SecretKeySpec;
    
    
    public class Config {
    
    
        public static final boolean BOOLEAN_DEFAULT = false;
        public static final double DOUBLE_DEFAULT = 0.0;
        public static final float FLOAT_DEFAULT = 0.0f;
        public static final int INT_DEFAULT = 0;
        public static final long LONG_DEFAULT = 0L;
        public static final byte BYTE_DEFAULT = 0;
        public static final String STRING_DEFAULT = "";
        public static final String PASSWORD_DEFAULT = "";
        
        public static final String TRUE = "true";
        public static final String FALSE = "false";
    
    
        public static final DateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        
        public static final String SERVER_URL = "server.url";
        public static final String SERVER_USERNAME = "server.username";
        public static final String SERVER_PASSWORD = "server.password";
        public static final String SERVER_EXTENSION = "server.extension";
        public static final String SEARCH_DEPTH = "search.depth";
        public static final String FIRST_TYPE = "type.first";
        public static final String SECOND_TYPE = "type.second";
        public static final String BOARD_WIDTH = "board.width";
        public static final String BOARD_HEIGHT = "board.height";
        public static final String CURRENT_GAME = "game.current";
    
    
        private final static String KEY = "968AD25B96915DD9267110A56E37D838";
        
        private Properties properties;
    
    
        public Config() {
            this.properties = new Properties();
        }
        
        public boolean getBoolean(String name) {
            String value = properties.getProperty(name);
            if (value == null || value.length() == 0) return BOOLEAN_DEFAULT;
            if (value.equals(Config.TRUE)) return true;
            return false;
        }
        
        public double getDouble(String name) {
            String value = properties.getProperty(name);
            if (value == null || value.length() == 0) return DOUBLE_DEFAULT;
            double ival = DOUBLE_DEFAULT;
            try {
                ival = new Double(value).doubleValue();
            } catch (Exception e) {
                ival = DOUBLE_DEFAULT;
            }
            return ival;
        }
    
    
        public float getFloat(String name) {
            String value = properties.getProperty(name);
            if (value == null || value.length() == 0) return FLOAT_DEFAULT;
            float ival = FLOAT_DEFAULT;
            try {
                ival = new Float(value).floatValue();
            } catch (Exception e) {
                ival = FLOAT_DEFAULT;
            }
            return ival;
        }
    
    
        public int getInt(String name) {
            String value = properties.getProperty(name);
            if (value == null || value.length() == 0) return INT_DEFAULT;
            int ival = INT_DEFAULT;
            try {
                ival = Integer.parseInt(value);
            } catch (Exception e) {
                ival = INT_DEFAULT;
            }
            return ival;
        }
    
    
        public byte getByte(String name) {
            String value = properties.getProperty(name);
            if (value == null || value.length() == 0) return BYTE_DEFAULT;
            byte ival = BYTE_DEFAULT;
            try {
                ival = Byte.parseByte(value);
            } catch (Exception e) {
                ival = BYTE_DEFAULT;
            }
            return ival;
        }
        
        public long getLong(String name) {
            String value = properties.getProperty(name);
            if (value == null || value.length() == 0) return LONG_DEFAULT;
            long ival = LONG_DEFAULT;
            try {
                ival = Long.parseLong(value);
            } catch (Exception e) {
                ival = LONG_DEFAULT;
            }
            return ival;
        }
        
        public String getString(String name) {
            String value = properties.getProperty(name);
            if (value == null) return STRING_DEFAULT;
            return value;
        }
        
        public String getPassword(String name) {
            String src = getString(name);
            String tag = PASSWORD_DEFAULT;
            try {
                tag = decrypt(src, KEY);
            } catch (Exception e) {
                tag = PASSWORD_DEFAULT;
            }
            return tag;
        }
        
        public Date getDate(String name) {
            String value = properties.getProperty(name);
            if (value == null || value.length() == 0) return Calendar.getInstance().getTime();
            Date dval = Calendar.getInstance().getTime();
            try {
                dval = DATE_FORMATTER.parse(value);
            } catch (Exception e) {
                dval = Calendar.getInstance().getTime();
            }
            return dval;
        }
        
        public void setValue(String name, double value) {
            double oldValue = getDouble(name);
            if (oldValue != value) {
                properties.put(name, Double.toString(value));
            }
        }
    
    
        public void setValue(String name, float value) {
            float oldValue = getFloat(name);
            if (oldValue != value) {
                properties.put(name, Float.toString(value));
            }
        }
    
    
        public void setValue(String name, int value) {
            int oldValue = getInt(name);
            if (oldValue != value) {
                properties.put(name, Integer.toString(value));
            }
        }
    
    
        public void setValue(String name, byte value) {
            int oldValue = getByte(name);
            if (oldValue != value) {
                properties.put(name, Byte.toString(value));
            }
        }
        
        public void setValue(String name, long value) {
            long oldValue = getLong(name);
            if (oldValue != value) {
                properties.put(name, Long.toString(value));
            }
        }
    
    
        public void setValue(String name, String value) {
            String oldValue = getString(name);
            if (oldValue == null || !oldValue.equals(value)) {
                if (value != null) {
                    properties.put(name, value);
                }
            }
        }
    
    
        public void setPassword(String name, String value) {
            String oldValue = getPassword(name);
            if (!oldValue.equals(value)) {
                if (value != null) {
                    try {
                        properties.put(name, encrypt(value, KEY));
                    } catch (Exception e) {
                    }
                }
            }
        }
        
        public void setValue(String name, boolean value) {
            boolean oldValue = getBoolean(name);
            if (oldValue != value) {
                properties.put(name, value == true ? Config.TRUE : Config.FALSE);
            }
        }
    
    
        public void setValue(String name, Date value) {
            Date oldValue = getDate(name);
            if (oldValue != value) {
                properties.put(name, DATE_FORMATTER.format(value));
            }
        }
    
    
        public void save(String filename) {
            try {
                properties.store(new FileOutputStream(filename), "Gomoku Config");
            } catch (Exception e) {
            }
        }
        
        public void load(String filename) {
            try {
                properties.load(new FileInputStream(filename));
            } catch (Exception e) {
            }
        }
        
        public static String encrypt(String value, String key) throws GeneralSecurityException {
            SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(key), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.ENCRYPT_MODE, sks, cipher.getParameters());
            byte[] encrypted = cipher.doFinal(value.getBytes());
            return byteArrayToHexString(encrypted);
        }
        
        public static String decrypt(String message, String key) throws GeneralSecurityException {
            SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(key), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, sks);
            byte[] decrypted = cipher.doFinal(hexStringToByteArray(message));
            return new String(decrypted);
        }
        
        private static String byteArrayToHexString(byte[] b){
            StringBuffer sb = new StringBuffer(b.length * 2);
            for (int i = 0; i < b.length; i++){
                int v = b[i] & 0xff;
                if (v < 16) {
                    sb.append('0');
                }
                sb.append(Integer.toHexString(v));
            }
            return sb.toString().toUpperCase();
        }
    
    
        private static byte[] hexStringToByteArray(String s) {
            byte[] b = new byte[s.length() / 2];
            for (int i = 0; i < b.length; i++){
                int index = i * 2;
                int v = Integer.parseInt(s.substring(index, index + 2), 16);
                b[i] = (byte)v;
            }
            return b;
        }
        
    }
    
    Code (markup):
     
    dthoai, Aug 8, 2011 IP
  7. Dennis M.

    Dennis M. Active Member

    Messages:
    119
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Sorry, I was not around yesterday. This document is rather large for a quick conversion; is there a particular part that I could do for you that would help you? Certain items may have to be reconstructed (i.e. Java's Properties class does not have an Apex counter-part to my knowledge).

    Regards,
    Dennis M.
     
    Dennis M., Aug 10, 2011 IP
  8. dthoai

    dthoai Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    38
    #8
    If you can parse source into tree of elements, eg. package name, list of import,  list of inner class, list of constants, list of member variables, list of methods, ... this would help me.
     
    dthoai, Aug 10, 2011 IP