Monday, October 27, 2014

Guava Files class

Sometimes you are still in the Java 1.6 land and you just to want to read the entire file into a list. Guava can help you:
File file = new File("trades_3.txt");
List<String> lines = Files.readLines(file, Charset.defaultCharset());
The Files class doc.

Saturday, October 11, 2014

Foundation and Empire


  1. Part I: The General
    1. Search for Magicians
    2. The Magicians
    3. The Dead Hand
    4. The Emperor
    5. The War Begins
    6. The Favorite
    7. Bribery
    8. To Trantor
    9. On Trantor
    10. The War Ends
  2. Part II The Mule
    1. Bride and Groom
    2. Captain and Mayor
    3. Lieutenant and Clown
    4. The Mutant
    5. The Psychologist
    6. Conference
    7. The Visi-Sonor
    8. Fall of the Foundation
    9. Start of the Search
    10. Conspirator
    11. Interlude in Space
    12. Death on Neotrantor
    13. The Ruins of Trantor
    14. Convert
    15. Death of a Psychologist
    16. End of the Search

Friday, October 3, 2014

IPTABLES

# List the rules with line numbers,
# the -n disables the DNS reverse lookup
iptables -n --list --line-numbers

# Block a specific IP
iptables -A INPUT -s 192.168.0.1 -j DROP

# Allow SSH for a specific IP
iptables -A INPUT -s 192.168.0.2 -p tcp -m tcp --dport 22 -j ACCEPT

# Delete a rule based on its number
iptables -D INPUT 8

# Insert rule before other certain one
# For example before line # 3
iptables -I INPUT 3 -s 192.168.0.2 -p tcp -m tcp --dport 22 -j ACCEPT


Thursday, September 25, 2014

Java 8 installation on Fedora 14


  1. Download Java SDK/JRE from Oracle: http://www.oracle.com/technetwork/java/javase/downloads/server-jre8-downloads-2133154.html. (I selected the server version).
  2. Extract the files into /usr/local/java. (I created the java directory).
  3. Use the alternatives program to create the necessary links:
    • [root@Fedora-test ~]# alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_20/bin/java 20000
    • Run the alternatives config command:
[root@Fedora-test ~]# alternatives --config java
Select the option for Java 8
    • Test it:
[root@Fedora-test ~]# java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
The following link was useful: http://www.dafoot.co.uk/index.php/menuitemcomputing/linux/101-fedora-12-alternatives-program-to-manage-java-runtimes-jdkjre

Thursday, September 11, 2014

Dumping computer’s DMI (SMBIOS) in Linux

dmidecode

dmidecode -t

The SMBIOS specification defines the following DMI types:

       Type   Information
       --------------------------------------------
          0   BIOS
          1   System
          2   Baseboard
          3   Chassis
          4   Processor
          5   Memory Controller
          6   Memory Module
          7   Cache
          8   Port Connector
          9   System Slots
         10   On Board Devices
         11   OEM Strings
         12   System Configuration Options
         13   BIOS Language
         14   Group Associations
         15   System Event Log
         16   Physical Memory Array
         17   Memory Device
         18   32-bit Memory Error
         19   Memory Array Mapped Address
         20   Memory Device Mapped Address
         21   Built-in Pointing Device
         22   Portable Battery
         23   System Reset
         24   Hardware Security
         25   System Power Controls
         26   Voltage Probe
         27   Cooling Device
         28   Temperature Probe
         29   Electrical Current Probe
         30   Out-of-band Remote Access
         31   Boot Integrity Services
         32   System Boot
         33   64-bit Memory Error
         34   Management Device
         35   Management Device Component
         36   Management Device Threshold Data
         37   Memory Channel
         38   IPMI Device
         39   Power Supply
         40   Additional Information
         41   Onboard Devices Extended Information
         42   Management Controller Host Interface

Additionally, type 126 is used for disabled entries and type 127 is an end-of-table marker. Types 128 to 255 are for OEM-specific data.

Keywords can be used instead of type numbers with --type.  Each keyword is equivalent to a list of type numbers:

       Keyword     Types
       ------------------------------
       bios        0, 13
       system      1, 12, 15, 23, 32
       baseboard   2, 10, 41
       chassis     3
       processor   4
       memory      5, 6, 16, 17
       cache       7
       connector   8
       slot        9

Wednesday, August 13, 2014

Excel Regular Expressions

Sub RegEx_Tester()
    Dim objRegExp_1 As Object
    Dim regExp_Matches As Object
    
    Dim strToSearch As String
    
    Set objRegExp_1 = CreateObject("vbscript.regexp")
    objRegExp_1.Global = True
    objRegExp_1.IgnoreCase = True
    objRegExp_1.Pattern = "[a-z,A-Z]*@[a-z,A-Z]*.com"
    
    strToSearch = "ABC@xyz.com"
    
    Set regExp_Matches = objRegExp_1.Execute(strToSearch)
    
    If regExp_Matches.Count = 1 Then
        MsgBox ("This string is a valid email address.")
    End If
    
End Sub