You are here

Programming

UTF-8 ISO8859-1 quick cheatsheet

Not so frequently asked questions and stuff: 

Here is a quick reference about utf-8 decoding/encoding:

Image

Create a complete solid cylinder with GLUT.

Not so frequently asked questions and stuff: 

Code:

//Output a cylinder with both lids.
//Erwan Martin 
#define SOLID_CLOSED_CYLINDER(QUAD, BASE, TOP, HEIGHT, SLICES, STACKS) \
gluCylinder(QUAD, BASE, TOP, HEIGHT, SLICES, STACKS); \
glRotatef(180, 1,0,0); \
gluDisk(QUAD, 0.0f, BASE, SLICES, 1); \
glRotatef(180, 1,0,0); \
glTranslatef(0.0f, 0.0f, HEIGHT); \
gluDisk(QUAD, 0.0f, TOP, SLICES, 1); \
glTranslatef(0.0f, 0.0f, -HEIGHT);

Usage:

  GLUquadric *quadric = gluNewQuadric();
  gluQuadricDrawStyle(quadric, GLU_FILL);
  gluQuadricOrientation(quadric, GLU_INSIDE);
  SOLID_CLOSED_CYLINDER(quadric, 0.17f, 0.17f, 0.15f, 20, 20)
  gluDeleteQuadric(quadric);

Reference:

  • http://www.eclipse.org/articles/Article-SWT-OpenGL/opengl.html
  • http://www.dei.isep.ipp.pt/~matos/cg/docs/manual/gluCylinder.3G.html

How to parse CSV data with Regular Expressions.

Not so frequently asked questions and stuff: 

The following regexp will return the different fields in a CVS row:

/((?:,|^)(?!,)(?:"(.*?(?

Here is an example in PHP:


Output:
Array
(
    [0] => zerzer
    [1] => abcd
    [2] => sd(fsdf"dsfsfsd
    [3] => sdf,e)zr,ertnfdg
    [4] =>
    [5] =>
    [6] =>
    [7] => ssfsdfsdf
    [8] => sdfsdfsdf
    [9] => sfsdfs
)

XSLT - How To Change the URL of a Namespace

Not so frequently asked questions and stuff: 

Problem

You've got an XML document, like this one:

 some content 

However, the person who wrote it didn't know that the true identifier of the namespace of the document is not http://zewaren.net/old_location/, but rather http://zewaren.net/new_location/. So you need a style sheet to update the url.

Solution

This style sheet will re-output all the elements and attributes of the old namespace, and assign them a new namespace with the correct URL.

Matching a string with escaped quotes with regular expressions

Not so frequently asked questions and stuff: 

The regexp:

(?<!\\)'.*?(?<!\\)'

and the string:

SELECT 'sdfsdfsd\'zerzerzer\'sdfsdfzer"zerzerz
erzer`zerzerzer`sfz
eioipoip"', 'saucisse magique avec 
des quotes: \'\' "\"zerzerzre' FROM rien

will match:

  • 'sdfsdfsd\'zerzerzer\'sdfsdfzer"zerzerz
    erzer`zerzerzer`sfz
    eioipoip"'

    and

  • 'saucisse magique avec 
    des quotes: \'\' "\"zerzerzre'

Remove unwanted blank pages inserted after a Word table

Not so frequently asked questions and stuff: 

When you create a table that ends at the bottom margin, Word automatically inserts a new blank page. If you turn on the Show/Hide button, it reveals a paragraph mark after the table.

If you don’t need the extra page, your first instinct may be to delete the paragraph mark, but Word prevents you from doing so because the mark is part of the document’s table format. Your next step may be to reformat the page so the paragraph mark fits on the page, but there is a third solution. Follow these steps to eliminate the extra page:

1. Select the paragraph mark on the second page.
2. Click in the Font size box in the Formatting toolbar. (In Word 2007, click in the Font size box in the Font group in the Home tab.)
3. Replace the font size with 1. Press [Enter].

If the paragraph mark is still on the blank page, follow these steps:

1. Select the paragraph mark.
2. Go to Format | Paragraph.
3. Click the Indents And Spacing tab.
4. In the Spacing section, change any spacing before or after the paragraph to 0.
5. Click in the Line Spacing box, select Single and then click OK.

The paragraph mark should now be almost invisible, but positioned on the same page as the table.

Source:

* http://blogs.techrepublic.com.com/msoffice/?p=341

How to get the number of digits of a number

Not so frequently asked questions and stuff: 
int number_digit_count(int input)
{
    if (input == 0) 
        return 1;
   return (int)(floor(log10((double)input)) + 1.0);
}

How to return the sum of all the digits of a number

Not so frequently asked questions and stuff: 
int sum_digits(int input)
//return the sum of all the digits of a number
{
  int sum = 0;
    int remainder = 0;

  while ((remainder=input%10)!=0)
 {
       //remainder contains the current digit
      sum += remainder;
       input /= 10;
    }
   return sum;
}

How to reactivate the "project outline" in Zend Studio for Eclipse

Not so frequently asked questions and stuff: 

Beware of the .project

org.eclipse.php.core.PHPNature

Source: http://lenss.nl/2008/09/zend-studio-project-outline-missing/

How to make libsmblient only open one connection per server

Not so frequently asked questions and stuff: 

Windows XP only accept 10 smb connections. When you parse a computer, you will only be able to open 10 shares, since samba doesn't close them at the right time.

Solution, initiate the library and modify the right parameter.

err = smbc_init(auth_fn, 1);
SMBCCTX  *hContext = smbc_set_context(NULL);

//Choose the working one between:
smbc_setOptionOneSharePerServer(hContext, 1);
//And
hContext->options.one_share_per_server = 1;

Pages

Subscribe to Programming