Removing All Triggers in a Database

We were re-structuring our current database here in work and there was a need of removing triggers. Here is how it is done in bash for mysql:

mysql -u<dbuser> -p<dbpassword> –skip-column-names <dbname> -e ‘SHOW TRIGGERS;’| cut -f1|sed -r ‘s/(.*)/DROP TRIGGER IF EXISTS \1;/’| mysql -u<dbuser> -p<dbpassword> <dbname>

Call to a member function on a non-object error in Symfony2

There is this error that I was having trouble with in my project. It was an implementation of ZeroMQ and RatchetPHP on Symfony2. The web socket service I did was keep on crashing caused by this error

Error: Call to a member function broadcast() on a nonobject

The command it was executing was $topic->broadcast($msg). I tried doing a try catch but the error still occurs. After some reading, seems that the issue was on the variable $topic. Next thing I did was to check of what type was the variable $topic by:

echo get_class($topic) and it returned ‘Ratchet\Wamp\Topic‘.

After determining it’s correct type, I added a condition to check before doing the broadcast if it was of the correct object type:

if(is_a($topic, ‘Ratchet\Wamp\Topic’)) { $topic->broadcast($msg); }

Now, the service doesn’t crash anymore. Seems that at times it was returning a NULL object class when the $msg was actually empty.

 

Creating custom systemd Service File

I had a requirement at work where in I need to create linux systemd custom services. But when I try to enable them by “systemctl enable abc.service”, an error is displayed:

“Failed to issue method call: No such file or directory”

Normally, we look for these custom files in the /etc/systemd/system/ directory and everything should work, though not sure why it doesn’t work now. Based on a post I read, systemd would look at the /usr/lib/systemd/system as well. So what I did is I added my custom service files in that directory, run “systemctl enable abc.service” again and alas! it did work. It is somehow a dirty solution but it did fix my problem, whew.

 

 

MySQL Proc Crashed

One day when I powered up my machine, I had a trouble with accessing my database. After tailing on the logs, I found this error : Table ‘./mysql/proc’ is marked as crashed and should be repaired. Based on replies from forums, my database has been corrupted and needed fix by myisamcheck, assuming mysql data directory is on /var/lib/mysql/mysql:

myisamchk -q -r /var/lib/mysql/mysql/proc

 

 

Mysql: Editing only the date in datetime

Recently I was looking for a way to do data testing in my project which involves data with date time. Since it was querying for the current day and my data was older, I wanted to change the date part of the datetime column. Anyways, here is how I did it:

UPDATE tablename SET fieldname = concat('2015-04-14 ', time(fieldname)) WHERE DATE(fieldname) = '2015-04-10'

‘2015-04-14’ is the new date we want to apply and ‘2015-04-10’ is the old date that we want to look for.

Hanging Pidgin When Generating Private Keys on Ubuntu

Ei Guys, have you ever encountered this error? When using the OTR(Off-The-Record) Plugin in Pidgin, when enabling it and it generates private keys, it suddenly hang and freezes? The culprit is the /dev/random in which it takes too long for it to process the generation. One solution I found on the wild is to install haveged which helps the /dev/random to generate faster. To install, simple use sudo apt-get install haveged

How to get Javascript parameters or values from JSF ManagedBean

Our current project right now uses JSF and we are trying to use Primefaces and utilize its features. One function we are trying to use is the RemoteCommand, in which you can pass Javascript parameters directly to a ManagedBean java class. We had a difficulty implementing this at first as Primefaces’ showcase hasn’t given us that much demo on how to extend its use. After some time, I was able to make it work, and here is how I did it:

 

You have to do changes to 3 files, your javascript, jsf(xhtml) file, and the ManagedBean java class:

  • In your js file, add a sample function:
    function testCommand() {
    	getjsParams([{name:'param1', value:'value1'}, {name:'param2', value:'value2'}]);
    }

     

  • In your ManagedBean java class, add:
    public void getParams(){
    	FacesContext context = FacesContext.getCurrentInstance();
    	Map<String,String> params = context.getExternalContext.getRequestParameterMap();
    	String param1 = params.get("param1");
    	String param2 = params.get("param2");
     
    	System.out.println(param1);
    	System.out.println(param2);
    }
  • Then lastly, in your xhtml:
    <h:form>
    	<p:remoteCommand name="getjsParams" action="#{yourMB.getParams}" />
    	<p:commandButton type="button" value="Test Remote Command" onclick="testCommand();" />
    </h:form>

Output on terminal will be “value1” and “value2”.

Just an off-topic Advertisement

My wife just joined in a group which endorses beauty and skin care products here in the Philippines. The product brand is still new but its products are promising. The name of the brand is Aura. It offers several products which distinctly addresses common skin issues. But wait, I don’t want to be the one to market this. If these products are of your interest, or maybe, you too are interested in selling/redistributing, you can email my wife at gallardo.maefatima@gmail.com, send her an SMS or even give her a call at +639255507755.

To give you some basic information on what Aura offers, click the image below. Don’t worry, it’s clean and definitely not virus infested. 😀

Aura Products

Crashing Thunderbird

I’m not really sure if the issue is new or not but lately, my Thunderbird keeps on crashing when I try to retrieve mail. I tried running it via terminal so as I can see the error message it returns and here is what I got:

(thunderbird:12496): GLib-GIO-ERROR **: g_menu_item_set_detailed_action: Detailed action name ‘mailbox:///home/lhan/.thunderbird/Profiles/x1cm2x83.default/Mail/mail.stm.com.ph/Inbox’ has invalid format

Trace/breakpoint trap (core dumped)

Not really sure what invalid format it complains as I never did any changes to its settings lately. I found out in a certain post on a community website that to fix it, you must disable Add-Ons. I tried it, and it worked. So if you have the same issue, just try to disable Thunderbird Add-Ons and see if it resolves it. You can disable it via Help > Restart with Add-ons Disabled on Thunderbird menu.