Skip to main content

Posts

Showing posts from March, 2010

Starting MySQL with XAMPP on Mac

Had a problem with XAMPP on mac especially on MySQL, where it tells you to check the log files on the errors? I had the same problem and the way if fix it is through the terminal typing this command

/Applications/XAMPP/xamppfiles/share/mysql/mysql.server start

To stop it
/Applications/XAMPP/xamppfiles/share/mysql/mysql.server stop

Transaction on CakePHP when using Oracle

Following my post on http://monmonja.com/blog/2008/07/transaction-on-cakephp-12/ where i use CakePHP and MySQL to do transaction, now i'm using oracle and $this->Model->begin() is not working and the fix for that is

$this->Model->begin();
$returnQuery = $this->Model->getDataSource()->query($query);
if($returnQuery !== false){
$this->Model->getDataSource()->commit();
}else{
$this->Model->getDataSource()->rollback();
}

Hope this helps

Closure - goog.ui.ColorPicker example

Been playing around Google's Closure library and i have to say the API looks good with ofcourse some exception like i dont know how to render a component, sometime you call render, decorate or the constructor itself. And when i was browsing through the code i was curious with ColorPicker and to my dismay there was no example, having searching on the web here is how to do it

Include
goog.require('goog.dom');
goog.require('goog.ui.ColorPicker');


<style>
<!-- http://gitorious.org/element/element/commit/6f9a6373727ff6478f6e78ec4917289b6523b5ad -->
.goog-palette-cell{height:20px;width:20px;margin:0;border:0;text-align:center;vertical-align:middle;border-right:1px solid #666;font-size:1px}
.goog-palette-colorswatch{position:relative;height:20px;width:20px;border:1px solid #666}
</style>

var cp = new goog.ui.ColorPicker();
cp.setSize(7);
cp.setColors(goog.ui.ColorPicker.SIMPLE_GRID_COLORS);
cp.addEventListener(goog.ui.ColorPicker.EventType.CHAN…

show and hide functions in closure

I'm a huge fan of jQuery and while closure is new, its pretty interesting, there are things that are easier to do in jQuery like showing or hiding DOM or DOM manipulations. $ in jQuery is goog.dom.query in closure (they used dojo, i hope they just used sizzle instead). So in order to do something like $("img .oldImages").hide() you have to include third party deps.js
<script src="third_party/closure/goog/deps.js"></script>

We need to import the following:
goog.require('goog.fx');
goog.require('goog.fx.dom');
goog.require('goog.dom.query');
goog.require('goog.fx.AnimationQueue');

function hide(dom){
var anims = new goog.fx.AnimationParallelQueue();
var items = goog.dom.query(dom);
goog.array.forEach(items,function(item){
var anim = new goog.fx.dom.FadeOutAndHide(item, 1000);
anims.add(anim);
});
anims.play();
}

function show(dom){
var anims = new goog.fx.AnimationParallelQueue();
var items = goog.dom.query(dom);
goog.ar…

Get Geocode straight from Google Map

There are times where you have to find the geocode of one location on the earth, there are many sites that have this features, you can find them here. Now i found an easy way to find geocode straight from Google Map.

1) Go to Google Map
2) Search for the location, for example let's search for "Cavite, Philippines", the place where i studied ComSci.
3) On the top right, there is a Send button. Click that one.
4) On your message textbox you can find the string "sll=<lat>,<long>"
Example:
..../maps?f=q&hl=en&geocode=&q=cavite,+philippines&sll=14.480642,120.894729&sspn=0.002722,0.006974&ie=UTF8&t=h&g=cavite,+philippines&z=16&iwloc=addr>

There you go, hope it helps

Ext Grid rowdblclick and rowclick fix

Ext is a great javascript library but ofcourse there are times where some things doesn't work and one of them is the rowdblclick and rowclick listener. Here is how i fixed it when i've encountered this problem.

var grid = new Ext.grid.GridPanel({
store: <your datastore>,
columns:[<your columns>],
renderTo:'example-grid',
height:200,
listeners:{
rowdblclick : function(grid,row){
alert("rowdblclick")
},
rowclick:function(grid,row){
alert('rowclick')
}
}
});

As you can see instead of doing
grid.getSelectionModel().addListener("click",
function(grid,row){ alert(''click'); })
or
grid.on("rowdblclick",function(grid,row){ alert('dblclick'); });
we added the listeners to the options when creating a new grid, there are disadvantage to this approach like when we need the listeners to be more dynamic but in case addListener and on doesn't work, try this approach.

Hope it helps

Converting MTS to AVI in Ubuntu Linux

There are a lot ways on converting MTS files in ubuntu linux to AVI (or any format), examples are programs like ffmpeg, mencoder, m2tstoavi, while these method did work for other people on the web, it wasn't my case. So i keep with looking at solution and found that does work for me, its HandBrake. The beauty of this one is that is completely open source and its available atleast to windows, mac and ubuntu (haven't try it on other linux distribution). Another neat feature is that it has a GUI version and a command line version. The GUI version is pretty neat and so does the command line one.

The reason why i needed the command line is that i need to convert one folder full of MTS files to AVI and they GUI is too time consuming for me. So instead I written a script to convert all the MTS on a folder into AVI. Here is the script (download the CLI version at Handbrake)
#!/bin/bash
for file in *.MTS
do
outfile=${file%.MTS}.avi
./HandBrakeCLI -i $file -o $outfile
done

For t…

Create animated gif from movie on command line

I saw a post where it was creating an sequence image from command line then using gimp to combine it, the post is at http://t.webofgoo.com/2009/02/27/create-animated-gif-from-video-in-ubuntu-linux-using-mplayer-and-gimp/comment-page-1/ and http://blog.ahfr.org/2008/03/making-animated-gifs-with-free-software.html. Now lets have more fun with it by just using command line for all the process.

You might need MPlayer and ImageMagick for this
sudo apt-get install mplayer imagemagick

The for the animated gif
mplayer -ao null -ss 0:00:01 -endpos 4 /path/to/video -vo jpeg:outdir=Extracted
cd Extracted
convert -delay 10 *.jpg -loop 0 animate.gif

If you want your full video to be converted to gif you could use this (byexamples archives)
mplayer -vo gif89a /path/to/video

For the explanation of the mplayer part please see the referenced site, for the convert please see http://www.imagemagick.org/Usage/anim_basics/.

Read Clipboard in Ubuntu

If your like me lazy in reading stuff then TTS like espeak, festival is perfect. For me it doesn't matter if it speaks like computer but as long as someone thing can read it for me its perfect. So in this journey i had made 2 scripts that could help you. This was testing in Ubuntu 9.04 with python, espeak and metacity as default.

First, create a python script or download this file, please rename the file to your folder of choice, for our example we would use /home/almondmendoza/clipboard/getClipboardContents.py
import gtk
clip = gtk.clipboard_get(selection='PRIMARY')
print clip.wait_for_text()

The previous script would get our clipboard, now to speak it we would use espeak coz its build in by default, we would have to created a shell script or download this (this change voice to en-r and speed to 200), please rename the file, for our example /home/almondmendoza/clipboard/speakClipboard.sh
#!/bin/sh
word=`/usr/bin/python /home/almondmendoza/clipboard/getClipboardContents.py…

Factorial in ActionScript 3

Here is factorial function in Actionscipt 3,

package{
public class MyMath{
public static function factorial(index:uint) : uint {
var total:uint = index;
if(index > 0){
total += MyMath.factorial(index - 1);
}
return total;
}
}
}

To use it
trace(MyMath.factorial(3));
Hope it helps

ps3-flash-util not found

Installing other os (Ubuntu in this article) on ps3 is a super easy thing to do, just download the iso and follow the instruction on this site http://psubuntu.com/, switching back to the original os is also as simple as boot-game-os, But there may be a time where you might have an error, and if the error goes something like /usr/sbin/ps3-flash-util: not found, you might want to consider the following steps to fix it:
* type sh
* /usr/sbin/boot-game-os

Thats all, on my ps3, there were an error that the system was reading boot-game-os from /sbin while its reading the ps3-flash-util from /usr/sbin and it so happen that boot-game-os from /usr/sbin is reading the ps3-flash-util from the same folder.

Hope this helps

Stream media from Mac Leopard to ps3

Lately i have been experimenting with my ps3 and one of which is streaming my mac to ps3. As i guy who believed in free stuff, i found a software called MediaTomb which would stream my media from *nix (unix,linux and mac) to ps3. On mac you can follow this guide to have your media streamed.
http://www.applesource.com.au/how-to/soa/How-to-Stream-media-to-a-PS3-from-a-Mac/0,2000451082,339287550,00.htm

The problem i had after installing xcode, fink and mediaTomb is that the ip address given by mediatomb is not the same subnet of the lan network. While most of the blog would ask you to change the ip using "mediatomb -ip=192.168.1.2" this alerted an error on my mac. Its the 203 error, and to fix this:

* Open config.xml under ~/.mediatomb/
* under the server node, add the following:
<interface>en0</interface>
Now i don't really know what it means i just found it on a comment somewhere. Hope it helps

Converting CakePHP array to xml

Here is a small function to convert cakephp's array from find statements to xml.

function cakeArrayToXML($arr,$keyParent = "rows"){
$arrayRow = "<$keyParent>";
foreach($arr as $tkey => $trow){
if(is_numeric($tkey)){
$arrayRow .= $this->cakeArrayToXML($trow,"row");
}elseif(is_array($trow)){
$arrayRow .= $this->cakeArrayToXML($trow,$tkey);
}else{
$arrayRow .= "<$tkey><![CDATA[$trow]]></$tkey>";
}
}
$arrayRow .= "</$keyParent>";
return $arrayRow;
}

To use it you would do something like
header("Content-type: text/xml;charset:UTF-8");
echo '<?xml version="1.0" ?>';
echo $this->EcOutput->cakeArrayToXML($this->Lyric->find("all",array("limit"=>2)));


Output would be an xml with a parent node of rows and a node name of row on each row, i guess you just have to test it to understand what i mean, haha.
Hope it helps.

Fixing ExtJS setStyle problem in IE

Back with programming post, if you use ExtJS and you had a problem with IE then see if the setStyle is the one issuing it. To fix this :

Find
H=="opacity"
or find the line that have
H=="opacity"?this.setOpacity(I):this.dom.style[w(H)]=I

Replace it with
if(H=="opacity"){this.setOpacity(I)}else{try{this.dom.style[w(H)]=I}catch(e){}}

Hope this helps

How to disable textfield on AS3

This took me 2 hours to find out how to disable textfield on AS3, its not the perfect solution but it seems to be the only solution.

private var txtField:Textfield;
...
this.txtField = this.getChildByName("txtField");
this.txtField.mouseEnabled = false;
this.txtField.tabEnabled = false;

and to turn it enable again:
this.txtField.mouseEnabled = true;
this.txtField.tabEnabled = true;

You could also do this
//disable input
myTextField.selectable = false;
myTextField.type = TextFieldType.DYNAMIC;

//enable input
myTextField.selectable = true;
myTextField.type = TextFieldType.INPUT;


While this sound cheap coz you have to disable the mouse and the tab of that component and not the component itself, it seems to be the only solution. Thanks Adobe!!!!!!!!

jqModal IE7 Drop All Contents at the bottom fix

This seems to be a fix for jqModal when IE7 drops all to the bottom of the page while the top of the page is the jqModal.

Open the css that came with jqModal and change to the following codes
.jqmOverlay {
background-color: #000;
+position:absolute !important;
}

The +position:absolute !important is a css targeted for IE7, i know its a hack, if you don't what that you can include a css specially design for IE


Open the javascript and search for if(ie6){$('html,body') and change it to if(ie6||ie7){$('html,body'), resulting in
if(ie6||ie7){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}

Lastly still on the javascript search for ie6=$.browser.msie&&($.browser.version == "6.0") and change to ie6=$.b…

Regular Expression for inserting codes at the end of a function

This is a regular expression that i used to insert codes at the end of a function, the original code was created for actionscript 3, and you tweak it a  little to match your language, that is if its a C-based language.

reg  = "("+funcName+"\\([\\s\\S]*?\\)[\\s\\S]*?{[\\s\\S]*?)(?=(})[\\s\\S]*?((protected override|private|public) function))";

re = new RegExp(reg);newCode = oldCode.replace(re, "$1 " + code);

The regular expression is
(yourFunc([\s\S]*?)[\s\S]*?{[\s\S]*?)(?=(})[\s\S]*?((protected override|private|public) function))

Explanation
(yourFunc([\s\S]*?)[\s\S]*?{[\s\S]*?)
First it finds the function named yourFunc followed by (
Then finds the arguements but stop finding mor, the *?, once it finds the first )
Then it continues to find anything, in as3 this is the : thing, and stops after it finds {
Lastly it finds everything after {, literally everything till the last one and to stop it you have to see the next pattern

(?=(})[\\s\\S]*?((protected override…

Will Be Moving AlmondMendoza and Monmonja

I Decided that having a hosting is too expensive and would rather move all the contents to a free one, but to keep the transition smooth, would do it over a year or so, so why sudden change?

Besides its expensive to have a hosting, google docs can upload anything now, so one of the main reason why i brought a hosting is now not appropriate.  Second, blogger is free so why just not use it, and blogger just release draft.blogger.com where you can customize the look further then previous. Third, Blogger has integrated adsense and amazon affiliate into the site which are the 2 of services that i use. Fourth, its annoying on hostmonster that you pay for the extension of the domain but its not reflected to the domain manager.And probably the biggest decision on why moving is that i want to focus more on the content, thus removing the mindset of maintaining the software, maintaining the backend and maintaining the hosting.

Hope this was a good move. :)