ABN 25 173 915 011 markomedia - web development

markomedia - web development

  • Home
  • Contact
  • Blog

Blog

  • markomedia
Share |
  • Compile PHP pcntl module on OS X Lion

    April 24, 2012

    I had some trouble compiling pcntl PHP module on OS X Lion so I thought I’d share this solution. In fact, you can use these steps to compile any other PHP module.

    First download the latest php source from PHP.NET
    cd into your php src directory, then:

    cd ext/pcntl
    phpize
    ./configure --enable-pcntl

    When I ran the last step (configure), I got the following error:

    ‘PHP_FE_END’ undeclared here (not in a function)

    To get around the problem, you need to specify your system architecture before configuring your extension:

    CFLAGS='-arch x86_64' CXXFLAGS='-arch x86_64' LDFLAGS='-arch x86_64' ./configure --enable-pcntl

    Copy compiled modules into PHP extensions:

    cp modules/pcntl.so /usr/lib/php/extensions/

    Enable the extension:

    echo "extension=pcntl.so" >> /etc/php.ini

    Marko

    Author
    Marko Tomic
    Category
    PHP
    Tags
    Lion, PHP
    Comments
    0
    Top
  • MySQL cursors in stored procedures

    March 14, 2012

    I’ve wanted to write a few stored procedures in MySQL for a while now, but I found it very fiddly and was unable to come up with one very quickly. Tonight I was determined to read up on MySQL documentation and get one going.

    For my reference only, this stored procedure will loop through a recordset and update a single row in a table upon a single row lookup in another table.

    DELIMITER // 
     
    DROP PROCEDURE IF EXISTS sp_test //
     
    CREATE PROCEDURE sp_test ()
    BEGIN
    	DECLARE done INT DEFAULT FALSE;
    	DECLARE myid INT;
    	DECLARE cur1 CURSOR FOR SELECT id from table1 WHERE firstname IS NULL;
    	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
     
    	OPEN cur1;
     
    	read_loop: LOOP
    		IF done THEN
    			LEAVE read_loop;
    		END IF;
     
    		FETCH cur1 INTO myid;
    		UPDATE table1 SET firstname = (SELECT firstname from table2 WHERE id = myid)
    		WHERE id = myid;
    	END LOOP;
     
    	close cur1;
    END;
    //

    Once I got the procedure to compile, executing it was as simple as:

    call sp_test

    Marko

    Author
    Marko Tomic
    Category
    MySQL
    Tags
    cursors, MySQL, StoredProcedures
    Comments
    0
    Top
  • IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

    February 10, 2012

    Today I discovered a nice tool on Github which installs free Windows virtual machines using VirtualBox on OS X. The only reason I’d use these virtual machines is to have different versions of Internet Explorer browsers running side by side for testing purposes.

    So here’s what you need to do:
    1. Download VirtualBox if you don’t have it already.
    2. Choose what version of Internet Explorer to install. Then type the following commands in your terminal window:
    Install ALL versions of Internet Explorer: IE6, IE7, IE 8, and IE 9

    curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | bash

    Install Internet Explorer 7 Only

    curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS="7" bash

    Install Internet Explorer 8 Only

    curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS="8" bash

    Install Internet Explorer 9 Only

    curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS="9" bash

    3. Open VirtualBox and launch your virtual machine. You will be prompted to type in account password, which is “Password1″. The password is also in the “Passowd hint” field if you forget it.

    Cheers
    Marko

    Author
    Marko Tomic
    Category
    OS X
    Tags
    IE6, IE7, IE8, IE9, virtualbox
    Comments
    0
    Top
  • opendiff and FileMerge on OS X

    January 15, 2012

    Today I discovered opendiff tool that’s native to OS X – provided you have installed the Xcode on your system. It allows you to compare 2 directories and perform actions such as merge-left, merge-right etc…

    Opendiff simply launches FileMerge OS X utility, which is another one I didn’t know about, and displays differences between 2 selected directories.

    The very simple command to compare 2 directories is:

    opendiff dir1 dir2

    This will then launch FileMerge utility and give you a nice visual representation of differences in your folders:
    FileMerge
    FileMerge

    Marko

    Author
    Marko Tomic
    Category
    OS X
    Tags
    difftool, filemerge, opendiff, utilities
    Comments
    0
    Top
  • Bandwidth throttling on OS X

    December 19, 2011

    I’ve been using Charles HTTTP Proxy for bandwidth throttling and network monitoring in general. It’s a great little tool, but when it comes to bandwidth throttling, it will only throttle HTTP and HTTPS traffic on ports 80 and 443 respectively.

    I thought there had to be a way to throttle bandwidth on any port using the native IP firewall and traffic shaper program. After reading up the documentation for ipfw, I figured out a way to throttle speed on any outgoing port.

    For example, the following example will create a pipe that will allow 25Kb/s to go through port 1935.

    sudo ipfw pipe 1 config bw 25KByte/s
    sudo ipfw add 1 pipe 1 src-port 1935

    To disable throttling, simply delete the throttling rule:

    sudo ipfw delete 1

    Marko

    Author
    Marko Tomic
    Category
    Networking
    Tags
    bash, networking, OS X
    Comments
    0
    Top
  • bash script useful tips

    November 30, 2011

    At Learnosity I’ve spent last 2 days scripting virtual server deployment on Amazon cloud. For my reference, these are some useful commands I had to use to get the job done.
    1. Hash “Hello World” string using SHA256 algorithm

    echo -n "Hello World" | shasum -a 256

    You can also hash a file

    shasum -a 256 myfile.ext

    2. Display server IP address by stripping out all other network information, including the local 127.0.0.1 IP

    ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'

    3. Read out first 64 characters from a long string

    ${mystring:0:64}

    4. While loop with 10 iterations

    i=0;
    while [ $i -lt 10 ]
    do
        echo $i
        i=$[$i+1]
    done

    5. Replace contents of a file. For example search for string1, replace with string2 in myfile.txt

    sed -e "s/string1/string2/g" myfile.txt > myfile.txt_temp
    mv myfile.txt_temp myfile.txt

    6. Display number of CPU processors on Linux
    The command simply pulls out all instances of the word ‘processor’ from /proc/cpuinfo and returns the word count of it.

    cat /proc/cpuinfo | grep processor | wc -l

    Marko

    Author
    Marko Tomic
    Category
    Linux, Shell
    Tags
    bash
    Comments
    0
    Top
  • apr_sockaddr_info_get() failed for mydomain.com

    November 24, 2011

    I recently changed my ISP from Optus to TPG and when I tried to start my local apache instance and I got this error

    httpd: apr_sockaddr_info_get() failed for 192-168-1-107.tpgi.com.au
    httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

    That gave me a hint that my local hostname had changed. I reset it back to what it was originally like this:

    sudo hostname myoldhostname.local

    Restarted apache and it was smooth sailing again.

    Marko

    Author
    Marko Tomic
    Category
    Apache
    Tags
    Apache
    Comments
    0
    Top
  • AES-128 padded encryption/decryption with Railo, Java and AS3

    October 15, 2011

    I’ve recently been working on text file decryption using Railo server. My files were encrypted in ActionScript 3 with the powerful AES-128 algorithm. For more info on AS3 encryption see Hurlant Crypto demo.

    My challenge was to decypt this heavily encrypted content on a different platform, i.e. Railo with underlying Java Cipher capabilities.

    The 6 things I knew about the encrypted content were:
    1. Encryption Method – AES
    2. Mode – CBC (Cipher-block chaining)
    3. Padding – PKCS5
    4. Initialisation Vector (IV) – given hex string
    5. Passphrase – given hex string
    6. Encrypted text file saved in base64 encoded string.

    For my records, this is how I went about decrypting on Railo:

    <cfscript>
    // Create some java objects
    IvParameterSpec = createObject("java", "javax.crypto.spec.IvParameterSpec");
    Cipher = createObject("java", "javax.crypto.Cipher");
    SecretKeySpec = createObject("java", "javax.crypto.spec.SecretKeySpec");
    BASE64Decoder = createObject("java", "sun.misc.BASE64Decoder");
    Str = createObject("java", "java.lang.String");
    MessageDigest = createObject("java", "java.security.MessageDigest");
     
    encryptedFileContent = "base64encodedcontent";
    password = binarydecode("somehexpassphrase", "hex");
    iv = binarydecode("somehexivstring", "hex");
     
    skeySpec = SecretKeySpec.init(password, "AES");
    ivSpec = IvParameterSpec.init(iv);
    cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
     
    encryptedContent = BASE64Decoder.decodeBuffer(encryptedFileContent);
    cipher.init(Cipher.DECRYPT_MODE,skeySpec,ivSpec);
    decryptedBytes = cipher.doFinal(encryptedContent);
    decryptedString = Str.init(decryptedBytes);
    </cfscript>

    Now that we know how the decryption works, encrypting data on Railo should be a piece of cake. For example:

    <cfscript>
    password = "somepassphrase";
    stringToEncrypt = "stringToEncrypt";
    md = MessageDigest.getInstance("MD5");
    md.update(password.getBytes("UTF-8"), 0, password.length());
    rawKey = md.digest();
     
    skeySpec = SecretKeySpec.init(rawKey, "AES");
    ivSpec = IvParameterSpec.init(rawKey);
    cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivSpec);
     
    encryptedbytes = cipher.doFinal(stringToEncrypt.getBytes());
    </cfscript>

    The only thing you need to be aware of is the format of parameters passed into encryption/decryption logic, and convert them appropriately. These parameters can be either plain, base64 or hex strings.

    Who would’ve thought that reverse engineering could be som much fun :)

    Cheers
    Marko

    Author
    Marko Tomic
    Category
    AS3, Java, Railo
    Tags
    AS3, java, Railo
    Comments
    0
    Top
  • Compile Apache2 from source on OS X

    October 8, 2011

    I’ve had to reinstall apache server on my Mac and the only way to do it cleanly was to nuke my existing apache installation and compile a fresh one from source.

    That’s all cool, but I could never remember what modules I needed and how to enable them.  If you don’t load any modules at compile time, this is the most likely error you’ll get when you start apache web server:

    Invalid command 'Order', perhaps misspelled or defined by a module not included in the server configuration

    So the following steps worked well for me.

    1. Download Apache 2.2 source code

    2. Extract the source code and configure apache with required modules. These modules are the ones I normally need. You can customise this to your needs:

    ./configure  --prefix=/usr/local/apache2 \
    --enable-mods-shared=all \
    --enable-shared \
    --enable-deflate \
    --enable-proxy \
    --enable-proxy-http \
    --enable-ssl \
    --enable-cgi \
    --enable-cgid \
    --enable-cache
     
    make \
     
    make install \

    Check /usr/local/apache2/modules directory and make sure required modules have been installed.

    Marko

    Author
    Marko Tomic
    Category
    Apache
    Tags
    Apache
    Comments
    0
    Top
  • Extract z01 files on Mac OS X – howto

    September 22, 2011

    The first of multiple files that make up a split archive created with WinZip; uses the same compression as a standard .ZIP file, but must be decompressed along with the related split archives (.Z02, .Z03, etc.).

    Split archives are often used to shrink the size of large files for e-mail attachments or file downloads. They can only be decompressed if all the split archive segments are available.

    To decompress a series of z01, z02… files you need to do the following

    1) Change all .z01, .z02 extensions to .001, .002 and so on.
    2) The last extension in compressed series will have a .zip extension. If you have 8 segments, change .zip to .008.
    3) Join all segments using “MacHacha”
    4) Change the extension of the file produced by MacHacha to .zip
    5) Use “The Unarchiver” to decompress the .zip file produced by MacHacha.

    References:
    http://www.fileinfo.com/extension/z01

    Author
    Marko Tomic
    Category
    HOWTO, OS X
    Tags
    HOWTO, OS X
    Comments
    0
    Top
  • 1
  • 2
  • 3
  • 4
  • >

Search

QR Code

Recent Posts

  • Compile pcntl PHP extension

    Compile PHP pcntl module on OS X Lion

  • Stored Procedures

    MySQL cursors in stored procedures

  • IE 8 and IE6 on OS X VirtualBox

    IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

Popular

  • Verizon Activates 2.2 Million iPhones in First Quarter

  • Amazon Server Trouble, Obama’s Facebook Visit.

  • Best Practices for Android Developers

Comments

  • Ionel Alexandru on Flash to Flex ComponentEvent coercion error solved
  • Marko Tomic on Zen Cart to VirtueMart csv export
  • snake on Zen Cart to VirtueMart csv export
  • Marko Tomic on Flash to Flex ComponentEvent coercion error solved
  • Thomas on Flash to Flex ComponentEvent coercion error solved

Tags

  • Apache6
  • AS36
  • bash2
  • ColdFusion2
  • command1
  • difftool1
  • DVD1
  • filemerge1
  • Flash3
  • Flex6
  • general2
  • Handbreak1
  • HOWTO8
  • IE61
  • IE71
  • IE81
  • IE91
  • iPhone1
  • iTunes1
  • Jaber1
  • java5
  • Linux3
  • MySQL4
  • networking1
  • opendiff1
  • OS X8
  • PHP4
  • Railo4
  • Red52
  • S31
  • shell3
  • SQL1
  • SSH2
  • SSL1
  • SVN1
  • tar1
  • Terminal3
  • Tigase1
  • Tomcat2
  • Ubuntu2
  • utilities1
  • VirtueMart1
  • XMPP1
  • ZenCart2
  • zip1

Contact us

  • Call us

Archive

  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009

Navigation

  • Home
  • Contact
  • Blog

Archives

  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009

From the blog

  • Compile PHP pcntl module on OS X Lion

  • MySQL cursors in stored procedures

  • IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

  • opendiff and FileMerge on OS X

  • Bandwidth throttling on OS X

About us

Marko Tomic - Web professional and an Adobe Certified Expert with over 10 years of commercial experience using variety of technologies.

Connect

Facebook icon Twitter icon Email icon RSS icon