Regular expressions snippets

preg_match_all('/([0-9]{1,2})\.([0-9]{1,2})/','12.56',$my, PREG_SET_ORDER);

$ => Array (1)
(
| ['0'] => Array (3)
| (
| | ['0'] = String(5) "12.56"
| | ['1'] = String(2) "12"
| | ['2'] = String(2) "56"
| )
)

Installing mbstrings

How to install mbstrings:

- log in as root to your SSH
- fire off these commands:
1.yum install php-mbstring
2. echo 'extension=mbstring.so' >> /usr/local/lxlabs/ext/php/etc/php.ini
3. /etc/init.d/lxadmin restart
- restart your vps (optional)

Note: this was tested on my VPS (centos-5-i386-lxadmin)

The type signature for `qwerty' lacks an accompanying binding

The type signature for `qwerty' lacks an accompanying binding

It seems that this errors appears when you have a data type definition but no corresponding function definition. For example

eval :: [(Var,Double)] -> Expr -> Double

Status: Connection attempt failed with “EAI_NONAME - Neither nodename nor servname provided, or not known”.

Status: Connection attempt failed with “EAI_NONAME - Neither nodename nor servname provided, or not known” -- FileZilla (FTP client)

If you're getting this error, chances are you're using the wrong hostname. Remember that when restoring a CPanel backup into a new account, your hostname, login and password will also be from the old backup. (Unless an employee of a hosting account changed the hostname for you.)

Useful Array Functions in PHP

Dear readers, I present some of the most useful functions to operate on arrays.

Please, comment :)

Finding all keys of an array

<?php
$myArray=array(1=>"em"),6=>"value";

array_keys($myArray); //returns array(1,6)
?>

Running through all values of an array

<?php
$myFriends=array('Mike','Jake','Helen');

foreach($myFriends as $friend){
  echo $friend . ' is my friend <br>';
}
?>

Some of the more obvious ones.

Checking if an array is empty

<?php
$Arr = array('value');

Bubble Sort in C

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
 
  int a[25] = {5,14,2,21,1,6,4,2,34,5,546,23,23,4,5,21,1,5,6,7,888};
 
  //calculating the number of elements in array a
  int n=0;
  while(a[n] != '\0'){
    n++;
 }
// decrementing n because array index starts with 0, not 1
n--;
 
  int swapped,temp;
 
  for(int i=0; i < n;i++){
    swapped=0;
   
    for(int j=0;j <n-i;j++){
      if (a[j] > a[j+1]){
        // swapping elements
        temp = a[j+1];
        a[j+1] = a[j];
        a[j] = temp;
       
        swapped = 1;

The Best Haskell Editor

I'm starting to do some programming in Haskell for my classes. Therefore the need for a good Haskell editor has emerged... I have just found a really neat editor, it's called NotePad++. What I like about this editor is the ability to select from a number of computer languages, so you have a nice color highlighting/coloring for most computer languages.

I'm pretty sure it's not the only good thing about this editor.

Internationalization (i18n) functions

1.

echo _i18n_get_original_path();

Gets the path of the current page. For this one it is: en/internationalization-i18n-functions

2.

echo i18n_get_normal_path(_i18n_get_original_path());

This function outputs the most basic path, meaning: node/, user/. For this page it is: node/9.

i18n_get_normal_path takes a path alias as an argument.

3.

echo i18n_path( i18n_get_normal_path(_i18n_get_original_path()),'de')

Algebra problem solved 3

Problem: "Show that if each element in a group is its own inverse then the group is abelian.

That's an easy one.

ab = e(ab)e = bb(ab)aa = b(ba)(ba)a = beea = ba

Algebra problem solved 2

Problem: "Prove that a finite monoid in which the cancellation law holds is a group. "

To prove it, we must show that for all a there is an inverse element.

We know that the monoid in question is finite so:

 \forall a \exists n such that an = e where e is the identity element.

This stems from the fact that monoids are closed under their operation.

an= e implies an-1a= e. So the inverse element is an-1

Syndicate content