Skip to main content

Posts

Showing posts from January, 2012

Blogspot Code Syntax Highlighter

Here is the code to highlight syntax of the code hosted on the blogspot. <script src="http://yandex.st/highlightjs/6.1/highlight.min.js"></script> <link rel="stylesheet" href="http://yandex.st/highlightjs/6.1/styles/default.min.css"> <link rel="stylesheet" href="http://yandex.st/highlightjs/6.1/styles/idea.min.css"> <script> hljs.initHighlightingOnLoad(); </script> <br /> <!-- Here will be the description --> <pre style="border: 1px dashed #CCCCCC; overflow: auto;"><code style="word-wrap: normal;"> <!-- Here will be the source code --> </code></pre>

PHP: Session based RAM

Here is a session based RAM. <? /** * @Class: CContainerManager.class.php * @Author: Abhishek Kumar (c) 2008. **/ class ContainerManager { function __construct() { session_start(); Get(); } function Get() { global $Container; $Container = array(); if (isset($_SESSION['RAM'])) { $Container = unserialize($_SESSION['RAM']); } } function Set() { $_SESSION['RAM'] = serialize($GLOBALS['Container']); } function Clean() { if (isset($_SESSION['RAM'])) { unset($_SESSION['RAM']); unset($GLOBALS['Container']); } } function Add($Associate, $Value) { global $Container; if (!isset($Container[$Associate])) { $Container[$Associate] = $Value; return true; } else { return false; } } function Modify($Associate, $Value) { global $Container; if (isset($Container[$Associate])) { $Container[$Associate] = $Value; return true; } els

AS3: Data Transporter

A data tansporter class. package engine { /** * @file CTransporter.as * @author Abhishek Kumar */ import engine.CCommunicator; import engine.CTemplate; import engine.CQuery; import engine.CUrl; public class CTransporter { private var oCommunicator:Object; private var oTemplate:Object; /* Ex: * private var oTransporter:Object = new CTransporter(); */ public function CTransporter():void { oCommunicator = new CCommunicator(); oTemplate = new CTemplate(); } /* Ex: * oTransporter.deliver('URL01', true, 'QT001', { Username:'admin', Password:'pass' }, this.receiver); */ public function deliver(iWebService:String, iReturn:Boolean, iQueryName:String, iQueryElement:Object, iReceiver:Function):void { oCommunicator.setUrl(CUrl.WebAppRoot + CUrl[iWebService]); oCommunicator.initialize(); oCommunicator.setProceed(iReceiver); var queryString:String = oTemplate.setInTemplate(CQu

AS3: Form Verifier

A form verifier class. package engine { /** * @file CFormVerifier.as * @author Abhishek Kumar */ import mx.controls.Alert; public class CFormVerifier { private var formItems:Array; public function CFormVerifier() { formItems = []; } public function push(itemId:int):void { formItems[itemId] = 1; } public function pop(itemId:int):void { formItems[itemId] = 0; } public function check(filledItems:int):Boolean { for (var i:int = 0, sum:int = 0; i < formItems.length; i++) { sum += formItems[i]; } return ((sum == filledItems) ? true : false); } public function alert():void { Alert.show('Please fill-up all the required fields!', 'Alert'); } } }

AS3: Form Validator

A form validator class package engine { /** * @file CFormValidator.as * @author Abhishek Kumar */ import mx.controls.Alert; public class CFormValidator { private var formItems:Array; public function CFormValidator() { formItems = []; } private function checkFormId(formId:String):void { if (formItems[formId] == null) formItems[formId] = []; } public function push(formId:String, elementId:Number):void { checkFormId(formId); formItems[formId][elementId] = 1; } public function pop(formId:String, elementId:Number):void { checkFormId(formId); formItems[formId][elementId] = 0; } public function check(formId:String, elementId:Number):Boolean { checkFormId(formId); for (var i:Number = 0, sum:Number = 0; i < formItems[formId].length; i++) { sum += formItems[formId][i]; } return ((sum == elementId) ? true : false); } public function alert():void { Alert.show('Please f

AS3: Date-Time Query

A Date-time query methods. package engine { /** * @file CDateTimeQuery.as * @author Abhishek Kumar */ public class CDateTimeQuery { public function CDateTimeQuery() { } public static function isExpired(yyyy:Number, mm:Number, dd:Number):Boolean { var today:Date = new Date(); var expiry:Date = new Date(yyyy, mm - 1, dd); var decision:Boolean = (today > expiry) ? true : false; return (decision); } public static function isValid(year:Number, month:Number, date:Number):Boolean { if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { return ((date >= 1 && date <= 31)?true:false); } else if (month == 4 || month == 6 || month == 9 || month == 11) { return ((date >= 1 && date <= 30)?true:false); } else if (month == 2) { if (year%100 == 0) { return ((year % 400 == 0) ? ((date >= 1 && date <= 29)?true:f

AS3: Data-tube ... an evolved concept

A data-tube concept based class. package engine { /** * @file CDataTube.as * @author Abhishek Kumar */ public class CDataTube { public function CDataTube() { } public function manageItem(iCommand:Boolean, iItem:*, iList:*):Array { if (iList == undefined) { iList = []; iList = addItem(iItem, iList); } else iList = (iCommand)? addItem(iItem, iList) : deleteItem(isPresent(iItem, iList), iList); return iList; } private function addItem(iItem:*, iList:Array):Array { iList.push(iItem); return iList; } private function deleteItem(iIndex:int, iList:Array):Array { for (var j:int = iIndex; j < iList.length; j++) iList[j] = iList[j + 1]; iList.length--; return iList; } private function isPresent(iItem:*, iList:Array):int { for (var i:int = 0; i < iList.length; i++ ) if (iList[i] == iItem) return i; return -1; } } }

AS3: Cryptography Methods

Few cryptography methods. package engine { /** * @file CCryptography.as * @author Abhishek Kumar */ import com.hurlant.util.Hex; import com.hurlant.util.Base64; public class CCryptography { public function CCryptography() { } public static function encrypt(iMsg:String):String { return Hex.fromString(Base64.encode(XOR(iMsg))); } public static function decrypt(iMsg:String):String { return XOR(Base64.decode(Hex.toString(iMsg))); } private static function XOR(source:String):String { var key:String = "HjRUPxRjRUPxRdVDYFdVDFS0HjRUPxRdVDYF6PkFBK3YlXjc"; var result:String = new String(); for (var i:Number = 0; i < source.length; i++) { if (i > (key.length - 1)) { key += key; } result += String.fromCharCode(source.charCodeAt(i) ^ key.charCodeAt(i)); } return result; } } }

AS3: Flex to Web-service Communicator

Here is a flex to web-service communicator. It dispatches a package of data to the server and receives the result in response from the server. package engine { /** * @file CCommunicator.as * @author Abhishek Kumar */ import mx.rpc.http.HTTPService; import com.sephiroth.Serializer; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.controls.Alert; import engine.CUtility; public class CCommunicator { private var communicationAgent:HTTPService; private var communicationUrl:String; private var communicationProceed:Function; /* Ex: * public var oCommunicator:Object = new CCommunicator(); */ public function CCommunicator():void { //trace('CCommunicator'); } /* Ex: * <mx:HTTPService id="transmittingAgent" url="<url-link>" result="oCommunicator.receiveDataFromServer(event);" fault="oCommunicator.handleCommunicationFault(event);" useProxy="false

PHP: Webpage Publisher

A webpage publishing class. <?php /** * @Class: CPublisher.class.php * @Author: Abhishek Kumar **/ require_once("CTemplate.class.php"); require_once("CFile.class.php"); class CPublisher { private static $oTemplate; public static function initialize() { self::$oTemplate = new CTemplate(); self::$oTemplate->setTemplatePath('asset/template'); } public static function Publish($iContent, $iInclude) { self::initialize(); $Output = self::$oTemplate->ModifyAndDump('Container.dt', array( 'Header'=>self::getHeader($iInclude), 'Content'=>self::$oTemplate->ModifyAndDump('ContainerBody.dt', array( 'Header'=>self::$oTemplate->Dump('Header.st'), 'Content'=>$iContent, 'Footer'=>self::$oTemplate->Dump('Footer.st') ) ), ) ); return $Output; } private static function getHeader($iI

PHP: Image Uploader

Here is an image uploader with re-sizing methods <?php /** * @file ImageUploader.php * @author Abhishek Kumar **/ $tempFile = $_FILES['Filedata']['tmp_name']; $fileName = $_FILES['Filedata']['name']; $fileSize = $_FILES['Filedata']['size']; $timestamp = date("YmdHis"); $new_fileName = "IMG".$timestamp.strtolower(getFileExtension($fileName)); move_uploaded_file($tempFile, "warehouse/" . $new_fileName); echo $new_fileName; function getFileExtension($iFile) { $iExtension = strrpos($iFile, "."); $oExtension = substr($iFile, $iExtension, strlen($iFile)); $oString = strtolower($oExtension); return $oString; } function imageResizer($image) { //$image = "Database/Foto/IMG_001.jpg"; // Name of the source image list($PictureWidth, $PictureHeight) = getimagesize($image); // Get original size of source image $PictureAspectRatio = $PictureWidth/$PictureHeight; $Width = 160;

PHP: Directory Handlers

Directory handling methods. <?php /** * @Class: CDirectory.class.php * @Author: Abhishek Kumar **/ require_once("CTemplate.class.php"); require_once("CFile.class.php"); class CDirectory { private $VoTemplate; private $VoCFile; private $Avoid; public function __construct() { $this->VoTemplate = new CTemplate(); $this->VoCFile = new CFile(); $this->Avoid = array(); $this->Avoid['Directory'] = array(); $this->Avoid['File'] = array(".", ".."); $this->Avoid['Extension'] = array(); } public function Directory($iCommand, $iDir) { switch($iCommand) { case 'CREATE': mkdir($iDir, 0700); $oStatus = true; break; case 'REMOVE': rmdir($iDir); $oStatus = true; break; case 'DELETE': $this->deleteDir($iDir); $oStatus = true; break; default: $oStatus = false; } return $oStatus; } private

PHP: File Utilities Methods

Utility methods for file handling. <?php /** * @Class: CFile.class.php * @Author: Abhishek Kumar **/ class CFile { public function getFileExtension($iFile) { $iExtension = strrpos($iFile, "."); $oExtension = substr($iFile, $iExtension, strlen($iFile)); $oString = strtolower($oExtension); return $oString; } public function getFileName($iFile) { $iExtension = strrpos($iFile, "."); $oFileName = substr($iFile, 0, $iExtension); return $oFileName; } public function getFileExtensionAlt($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } public function getFileNameAlt($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $filename = substr($str,0,$i); return $filename; } public function CreateFile($iFileName) { if (!$handle = fopen($iFileName, 'w+')) { return "Error: Ca

PHP: Template Setter

A template setting class for a webpage. <?php /** * @Class: CTemplate.class.php * @Author: Abhishek Kumar **/ require_once("CFile.class.php"); class CTemplate { private $HandleFile; private $Template; private $TemplatePath; public function __construct() { $this->HandleFile = new CFile(); } public function __destruct() { unset($this->HandleFile); } public function FitIn($iTemplate, $iTemplateArgument) { $this->Template = $iTemplate; $this->Template = $this->setTemplate($iTemplateArgument); return $this->Template; } public function ModifyAndDump($iTemplateName, $iTemplateArgument) { $this->Template = $this->getTemplate($iTemplateName); $this->Template = $this->setTemplate($iTemplateArgument); return $this->Template; } public function Dump($iTemplateName) { $this->Template = $this->getTemplate($iTemplateName); return $this->Template; } public function setTemplatePath($iPath

PHP: Web-service for communicating with MySQL database

Here is a php to mysql communication gateway packaged as a web-service. Gateway.php <?php require_once('Config.php'); require_once('engine/CMySqlManager.class.php'); $VoCMySqlManager = new CMySqlManager(); $VoCMySqlManager->Connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_SCHEMA); $_POST['message'] = (!isset($_POST['message']))? null : $_POST['message']; $_GET['message'] = (!isset($_GET['message']))? null : $_GET['message']; $C2S_message = ($_POST['message'] == null)? $_GET['message'] : $_POST['message']; $S2S_information = unserialize(stripslashes(urldecode($C2S_message))); if(isset($S2S_information->COMMAND) && isset($S2S_information->QUERY)) { $S2C_output = array(); $S2C_output = $VoCMySqlManager->Process($S2S_information->QUERY, $S2S_information->COMMAND); if($S2S_information->COMMAND) array_pop($S2C_output); echo urlencode(serialize($S2C_out

Android: Country's ISD Code

Recently, I got a very short missed call from an unknown foreign number. I traced back the location of that number via ISD code. From this, I got the idea of creating a program to detect this on the go (offline). So I'd created the application in flex for android platform. Below is the snapshot of that application: Here is a link to download the file: Link:  CountryISDCode.apk Download it either directly on your mobile-device or transfer it from computer to the device. Then, install it via Application Installer of the device.

AS3: Swf Communicator

This class could be used for two-way communication in between parent swf and child swf; where the child swf is loaded inside the parent swf. SOURCE CODE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 package { import CEvent ; import flash.events.Event ; import flash.events.IEventDispatcher ; import mx.events.FlexEvent ; import mx.managers.SystemManager ; import spark.components.Application ; /** * @file CSwfCommunicator.as * @author Abhishe

AS3: Swf Loader

A new class for loading swf files with events. SOURCE CODE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 package { import flash.events.Event ; import flash.events.HTTPStatusEvent ; import flash.events.IEventDispatcher ; import flash.events.IOErrorEvent ; import flash.events.ProgressEvent ; import flash.events.SecurityErrorEvent ; /** * @file CSwfLoader.as * @author Abhishek Kumar */ public class CSwfLoader { public var prepare: Function ; public var progress: Function ; public var proceed: Function ; public var instance :*; public function CSwfLoader () { trace ( "CSwfLoader -> constructor" ); } public function retrieve ( src : String ): void { inst

AS3: Xml Stack Loader

The class is used to load multiple xml/text files in a queue. SOURCE CODE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 package { import CSingleFileLoader ; /** * @file CXmlStackLoader.as * @author Abhishek Kumar */ public class CXmlStackLoader { public var prepare: Function ; public var progress: Function ; public var proceed: Function ; public function CXmlStackLoader () { trace ( "CXmlStackLoader -> constructor" ); } public function retrieve ( src : String ): void { trace ( "CXmlStackLoader -> retrieve src" , src ); var oSingleFileLoader: CSingleFileLoader = new CSingleFileLoader (); oSingleFileLoader . prepare = prepare ; oSingleFileLoader . progress = progress ; oSingleFileLoader . proceed = onLoad_XmlStack ; oSingleFileLoader . retrieve

AS3: Multiple File Loader

Single file loader for type like txt, xml, etc. SOURCE CODE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 package { import CSingleFileLoader ; /** * @file CMultipleFileLoader.as * @author Abhishek Kumar */ public class CMultipleFileLoader { public var prepare: Function ; public var progress: Function ; public var proceed: Function ; private var filelist: Array ; private var stack: Array ; private var count: int ; private var limit: int ; public function CMultipleFileLoader () { trace ( "CMultipleFileLoader -> constructor" ); } public function retrieve ( list : Array ): void { trace ( "CMultipleFileLoader -> retrieve" ); // initialize filelist = list ; stack = []; count = 0 ; limit = filelist .