Recent Notes
Displaying keyword search results 1 - 10
Created by magnum on September 24, 2011 13:14:37
Last update: September 28, 2011 18:08:35
There are two sides to an IP socket: the local side and the remote side:
The getpeername function retrieves the peer address of the specified socket.
#include <sys/socket.h>
int getpeername(int soc...
Example:
struct sockaddr_in addr;
socklen_t socklen = si...
The getsockname function retrieves the locally-bound name of the specified socket.
#include <sys/socket.h>
int getsockname(int soc...
Example:
struct sockaddr_in addr;
socklen_t socklen = si...
Created by magnum on September 11, 2011 19:46:09
Last update: September 11, 2011 19:46:09
A pair of C functions convert between an Internet address and a string (ASCII):
#include <arpa/inet.h>
/*
* Returns a poin...
However , these functions do not support IPv6. The new pair is:
#include <arpa/inet.h>
/* Convert a Internet ad...
Examples:
#include <sys/socket.h>
#include <netinet/in.h>...
Created by James on May 01, 2011 21:57:33
Last update: May 01, 2011 21:57:33
Both visibility:hidden and display:none hides an element in the DOM. But elements with visibility:hidden still takes up space, while display:none does not.
Example (click the divs to hide or show):
<!doctype html>
<html>
<head>
<style t...
Created by James on May 01, 2011 21:40:35
Last update: May 01, 2011 21:47:18
It's a shame that double click events are always accompanied by click events in JavaScript. When you double click on an element, JavaScript fires two click events followed by one double click event. So if you attach both click and double click event handlers to the same element, both event handlers will be called when you double click. This is a utility function to alleviate the problem somewhat:
<!doctype html> <html> <head> <script ... Note that there's still a possibility that both clicks and double clicks fired at the same time. This is because the timer used above may not be identical to the double click timer configured at the OS level. It's impossible to fix this problem in application code since each user may...
Created by jinx on April 16, 2011 15:03:17
Last update: April 16, 2011 15:03:17
The PHP function str_split splits a string to an array of strings with a max length. So the first n-1 elements will have the max length, the last element will have either the max length or less.
Example:
<?php
$colors = "red, green , ,, blue";
...
Prints:
array(5) {
[0]=>
string(5) "red, "
...
Created by jinx on April 10, 2011 14:36:44
Last update: April 10, 2011 14:37:03
The C-like function strlen gives the length of a string.
<?php
// 10
echo strlen('hfskdflgsd');
...
Created by jinx on April 10, 2011 14:14:29
Last update: April 10, 2011 14:14:46
The count function can be used to get the length of a PHP array. In PHP, there's no difference between an array with integer indexes and a map with string keys. Strings and integers are used interchangeably, '100' and 100 are the same when used as keys to an (associative) array.
sizeof is an alias of count .
<?php
$a[100] = '100';
echo "Length of \$a: ...
Outputs:
Length of $a: 1
Length of $a: 2
Length of $a...
Created by James on March 29, 2011 11:37:53
Last update: March 29, 2011 11:37:53
The test page below reports the column and row indexes of the table cell you clicked.
<!DOCTYPE html>
<html>
<head>
<title>jQu...
Created by James on March 29, 2011 11:28:33
Last update: March 29, 2011 11:30:12
The test page below shows how to count the number of columns for a given table row with jQuery:
$('table tr:eq('+row+') td').length
<!DOCTYPE html>
<html>
<head>
<title>jQu...
Created by James on March 29, 2011 11:25:35
Last update: March 29, 2011 11:25:35
With jQuery, it is pretty easy to access a table cell: just use the $('table tr:eq('+row+') td:eq('+column+')') selector. Below is a test page:
<!DOCTYPE html>
<html>
<head>
<title>jQu...