Create a new function that pre-fill in an argument to another function.
Use it like this:
// a function that generates a new function for adding numbers
function addGenerator(num) {
return function(toAdd) {
return num + toAdd;
}
}
// using above, make this function
var addFive = addGenerator(5);
alert(addFive(4) == 9);
.
myProgrammingNote
Wednesday, April 6, 2011
Saturday, February 5, 2011
XML - namespace
<!-- "xmlns" This is default namespace consturctor.
"xmlns:xhtml" This is prefixed, and belongs xhtml.
"xmlns:my"
-->
<feed xlmns="http://www.w3.org/2005/Atom"
xmlns:xhtml="http://xml.w3.org/1999/xhtml"
xmlns:my="hthp://xmlportfolio.com/xmlmyguid-examples">
<title>Example Feed</title>
<!--
"right" is an element.
"type" is attribute.
"my" can be any word, and makes no difference
-->
<right type="xhtml" my:type="silly">
<xhtml:div>
You may not read, utter, interpret, or otherwise
contained in this feed...
</xhtml:div>
</right>
</feed>
"xmlns:xhtml" This is prefixed, and belongs xhtml.
"xmlns:my"
-->
<feed xlmns="http://www.w3.org/2005/Atom"
xmlns:xhtml="http://xml.w3.org/1999/xhtml"
xmlns:my="hthp://xmlportfolio.com/xmlmyguid-examples">
<title>Example Feed</title>
<!--
"right" is an element.
"type" is attribute.
"my" can be any word, and makes no difference
-->
<right type="xhtml" my:type="silly">
<xhtml:div>
You may not read, utter, interpret, or otherwise
contained in this feed...
</xhtml:div>
</right>
</feed>
Thursday, February 3, 2011
CSS - Fixed Width In a Span
Although the assignment was for the Javascript class, I just wanted make it look pretty, and that started this whole thing...
I wanted the ouput to look like:
Name: Pretty Chindonya
ID: 19191919
Assignment: #01
Date: 02/03/2011
I thought since the table stuff is going under the drain, why not use div stuff? It sounded great at start. The key is use <li> and <span>, and in <span> in CSS file, fix the width.
Like this in HTML file:
<li><span>Assignment:</span>#01</li>
Like this in CSS file:
span
{
width: 100px;
}
It worked with Internet Explorer, but it didn't with Firefox. Firefox ignored the width assigned. ummmmm. To fix the Firefox problem, added "inline-block".
span
{
display: inline-block;
width: 100px;
}
This solved the problem.
Note that, while I was at it, I noticed the difference between Internet Explorer and Firefox. Firefox has the extra space at the left side of text. After spending time for try and error, I found out the I had to explicitly make padding 0 for "ul". Does this mean Firefox's default configuration for "ul" will add extra space at left? Must be, right?
Here is the working code.
HTML File:
<body>
<div id ="wrapper">
<div class ="assignmentTitle">
<ul>
<li><span>Name:</span>Pretty Chindonya</li>
</ul>
<ul>
<li><span>ID:</span>191919</li>
</ul>
<ul>
<li><span>Assignment:</span>#01</li>
</ul>
<ul>
<li><span>Date:</span>02/03/2011</li>
</ul>
</div>
</div>
</body>
</html>
CSS File:
body
{
background: #ffffff;
text-align: center;
font-size: medium;
font-family: Sans-serif;
color: #505050;
}
#wrapper{
margin: auto;
width: 900px;
text-align: left;
background: #f0f0f0;
}
.assignmentTitle
{
color: #505050;
font-size: medium;
}
.assignmentTitle ul
{
list-style: none;
font-size: 15px;
font-family: Sans-serif;
list-style: none;
margin: 0 0 0 4px;
/* With Firefox,
there is an extra space at left.
below "padding: 0;" helped to get rid of it */
padding: 0;
}
.assignmentTitle li
{
/* used them for just debugging,
but ie did NOT display the outline.
ummmmm...
outline-style: solid;
outline-width: 1px; */
/* With Firefox,
there is an extra space at left.
below did not help to get rid of it
margin-left: 0;
padding-left: 0; */
}
.assignmentTitle span
{
/* For Firefox,
this "inline-block" is needed.
without it, it will not reserve the space */
display: inline-block;
width: 100px;
/* With Firefox,
there is an extra space at left.
below did not help to get rid of it.
margin-left: 0; */
}
I wanted the ouput to look like:
Name: Pretty Chindonya
ID: 19191919
Assignment: #01
Date: 02/03/2011
I thought since the table stuff is going under the drain, why not use div stuff? It sounded great at start. The key is use <li> and <span>, and in <span> in CSS file, fix the width.
Like this in HTML file:
<li><span>Assignment:</span>#01</li>
Like this in CSS file:
span
{
width: 100px;
}
It worked with Internet Explorer, but it didn't with Firefox. Firefox ignored the width assigned. ummmmm. To fix the Firefox problem, added "inline-block".
span
{
display: inline-block;
width: 100px;
}
This solved the problem.
Note that, while I was at it, I noticed the difference between Internet Explorer and Firefox. Firefox has the extra space at the left side of text. After spending time for try and error, I found out the I had to explicitly make padding 0 for "ul". Does this mean Firefox's default configuration for "ul" will add extra space at left? Must be, right?
Here is the working code.
HTML File:
<body>
<div id ="wrapper">
<div class ="assignmentTitle">
<ul>
<li><span>Name:</span>Pretty Chindonya</li>
</ul>
<ul>
<li><span>ID:</span>191919</li>
</ul>
<ul>
<li><span>Assignment:</span>#01</li>
</ul>
<ul>
<li><span>Date:</span>02/03/2011</li>
</ul>
</div>
</div>
</body>
</html>
CSS File:
body
{
background: #ffffff;
text-align: center;
font-size: medium;
font-family: Sans-serif;
color: #505050;
}
#wrapper{
margin: auto;
width: 900px;
text-align: left;
background: #f0f0f0;
}
.assignmentTitle
{
color: #505050;
font-size: medium;
}
.assignmentTitle ul
{
list-style: none;
font-size: 15px;
font-family: Sans-serif;
list-style: none;
margin: 0 0 0 4px;
/* With Firefox,
there is an extra space at left.
below "padding: 0;" helped to get rid of it */
padding: 0;
}
.assignmentTitle li
{
/* used them for just debugging,
but ie did NOT display the outline.
ummmmm...
outline-style: solid;
outline-width: 1px; */
/* With Firefox,
there is an extra space at left.
below did not help to get rid of it
margin-left: 0;
padding-left: 0; */
}
.assignmentTitle span
{
/* For Firefox,
this "inline-block" is needed.
without it, it will not reserve the space */
display: inline-block;
width: 100px;
/* With Firefox,
there is an extra space at left.
below did not help to get rid of it.
margin-left: 0; */
}
XML - New Line
I had a heck of time with putting a new line for XML.
Why?
Here is an assignment for the XML class that I was (and still am) taking.
Let’s start with something that we all should know how to do.
Write an XML document and a Cascading Style Sheet (CSS) that will display your name, the date, and the assignment number, all on separate lines.
No kiddin' :O
I didn't have a clue. Searched everywhere, including W3C site, but no one, no where else shows me how to put a new line. There are a lot of discussions about it, but none worked. So, after several hours of agony, this is what I came up with.
CSS File:
body
{
background-color: #ffffff;
font-size: medium;
font-family: Sans-serif;
}
Col
{
width: 100%;
}
nameHead, dateHead, assignmentHead
{
/* clear: left; */
color: #505050;
width: 160px;
}
name, date, assignment
{
color: #505050;
}
XML File:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/css" href="StyleSheet1.css"?>
<body>
<col>
<nameHead>
Name:
</nameHead>
<name>
Tetsuro Hirouji
</name>
</col>
<col>
<dateHead>
Date:
</dateHead>
<date>
02/02/2011
</date>
</col>
<col>
<assignmentHead>
Assignment #:
</assignmentHead>
<assignment>
1
</assignment>
</col>
</body>
The key is to use a container with 100% width, and put the text inside. I don't know how else to do it.
Why?
Here is an assignment for the XML class that I was (and still am) taking.
Let’s start with something that we all should know how to do.
Write an XML document and a Cascading Style Sheet (CSS) that will display your name, the date, and the assignment number, all on separate lines.
No kiddin' :O
I didn't have a clue. Searched everywhere, including W3C site, but no one, no where else shows me how to put a new line. There are a lot of discussions about it, but none worked. So, after several hours of agony, this is what I came up with.
CSS File:
body
{
background-color: #ffffff;
font-size: medium;
font-family: Sans-serif;
}
Col
{
width: 100%;
}
nameHead, dateHead, assignmentHead
{
/* clear: left; */
color: #505050;
width: 160px;
}
name, date, assignment
{
color: #505050;
}
XML File:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/css" href="StyleSheet1.css"?>
<body>
<col>
<nameHead>
Name:
</nameHead>
<name>
Tetsuro Hirouji
</name>
</col>
<col>
<dateHead>
Date:
</dateHead>
<date>
02/02/2011
</date>
</col>
<col>
<assignmentHead>
Assignment #:
</assignmentHead>
<assignment>
1
</assignment>
</col>
</body>
The key is to use a container with 100% width, and put the text inside. I don't know how else to do it.
Saturday, January 29, 2011
WAMP and IIS
If both WAMP and IIS7 are installed, IIS7 will be displayed.
To solve this problem, do this:
To change WAMP,
click on WAMP Server icon on taskbar and go to Apache > httpd.conf
Change ‘Listen 80’ to ‘Listen 8080’ (As shown in the screenshot). Save and restart WAMP.
Reference:
http://www.programmerfish.com/how-to-run-wamp-server-parallel-with-iis-7-on-windows/
Now WAMP Server is accessible on http://localhost:8080/
Added Note:
With above change only, I have to manually enter 8080 to "http://localhost/"
I am going to edit the same file, "httpd.conf" file.
Original:
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:80
Changed:
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:8080
This did NOT do anything.
Put back the original setting.
Change it back to:Listen 80
(it was changed to "Listen 8080")
Then, DO this, instead!
Theory, you can have both, but IIS and Apache/Wamp are both web server and might conflict in some way, so you have to disable IIS in order for Wamp to work
Disable IIS in Vista:
Control Panel, Uninstall Programs, Turn Widows Features On or Off, uncheck Internet Information Services
In the I"Uninstall or Change Program" window, click "repair" icon, then uncheck "Internet Information Services".
To solve this problem, do this:
- WAMP to run on http://localhost:8080/
- IIS7 to run on http://localhost/ (no change)
To change WAMP,
click on WAMP Server icon on taskbar and go to Apache > httpd.conf
Change ‘Listen 80’ to ‘Listen 8080’ (As shown in the screenshot). Save and restart WAMP.
Reference:
http://www.programmerfish.com/how-to-run-wamp-server-parallel-with-iis-7-on-windows/
Now WAMP Server is accessible on http://localhost:8080/
Added Note:
With above change only, I have to manually enter 8080 to "http://localhost/"
I am going to edit the same file, "httpd.conf" file.
Original:
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:80
Changed:
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:8080
This did NOT do anything.
Put back the original setting.
Change it back to:Listen 80
(it was changed to "Listen 8080")
Then, DO this, instead!
Theory, you can have both, but IIS and Apache/Wamp are both web server and might conflict in some way, so you have to disable IIS in order for Wamp to work
Disable IIS in Vista:
Control Panel, Uninstall Programs, Turn Widows Features On or Off, uncheck Internet Information Services
In the I"Uninstall or Change Program" window, click "repair" icon, then uncheck "Internet Information Services".
Monday, January 24, 2011
visual studio 2010 C++ note
Problem: start without debugging missing in visual studio 2010 C++
When use ctrl-F5, it automatically closes console window.
To fix this, do the following:
When use ctrl-F5, it automatically closes console window.
To fix this, do the following:
- right click the project name,
- go to Properties page,
- expand Configuration Properties -> Linker -> System,
- select Console (/SUBSYSTEM:CONSOLE) in SubSystem dropdown.
Friday, January 7, 2011
php - working with function (2)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
//
// accept a list of email address,
// split address, add domain part to another array
//
function getUniqueDomains($list){
$domains=array();
foreach($list as $l){
//
// separate xxx@yyy, and save arr[0]=xxx, arr[1]=yyy
//
$arr=explode("@", $l);
//
// save yyy into domain[]
//
$domains[]=trim($arr[1]);
}
//
// array_unique() removes duplicates elements
//
return array_unique($domains);
}
// read the file with email list
$fileContents=file("data.txt");
// pass the deliminated array
$returnedArray=getUniqueDomains($fileContents);
// print returned array
foreach($returnedArray as $d){
print "$d<br />";
}
?>
</body>
</html>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
//
// accept a list of email address,
// split address, add domain part to another array
//
function getUniqueDomains($list){
$domains=array();
foreach($list as $l){
//
// separate xxx@yyy, and save arr[0]=xxx, arr[1]=yyy
//
$arr=explode("@", $l);
//
// save yyy into domain[]
//
$domains[]=trim($arr[1]);
}
//
// array_unique() removes duplicates elements
//
return array_unique($domains);
}
// read the file with email list
$fileContents=file("data.txt");
// pass the deliminated array
$returnedArray=getUniqueDomains($fileContents);
// print returned array
foreach($returnedArray as $d){
print "$d<br />";
}
?>
</body>
</html>
Subscribe to:
Posts (Atom)

