MATLAB draw plot
1 | % Set some nice settings. |
1 | % Set some nice settings. |
Website consists of three components: structure(HTML), representation(CSS), action(Javascript). XHTML is a strict version of HTML. The structure of webpage is previously done based on table, but currently via CSS.
Escape character in HTML source code: <:<, >:>, :space
<p>:paragraph, <br>:break, <blockquote>:indented paragraph, <b>:bold, <i>:italic, <u>:underline, <s>:deleteline, <strong>:emphasize, <ul><li>:unordered list, <ol><li>:ordered list.
<a href="" target="_blank"></a>:hyperlink. <a href="mailto:ustcnewly@gmail.com"></a>. An area on the image can also be used to establish hyperlink based on <map> and <ared>.
Use <frameset> and <frame> to split webpage. Note <frameset> and <frame> belong to the the same level as <body>. <frameset cols="30%, 30%, *"><frame src=left.html>. <frame> is obsolete in HTML5.
<table border="1" cellpadding="4" cellspacing="6" ><tr><td></td><tr></tr></table>. Don’t miss any <tr> or <td>, otherwise the table will be messy. Use <colspan> or <rowspan> to merge cells. For professional table, we can use <caption>, <thead>, <tbody>, and <tfoot>. <table> is now rarely used for layout design.
Insert multimedia elements:
<img src="a.jpg" height="200" width="200" alt="desc"/> <embed src="a.swf" width="490" height="400" wmode="transparent" ></embed> <audio src="a.mp3" hidden="true" autoplay="true" loop="true"></audio><body background="a.png"></body>Css: object, attribute, and value. Refer to official website for details.
1 | h1{ |
Methods to use Css.
a. Directly insert contents into <style></style>.
b. <link href="mycss.css" type="text/css" rel="stylesheet">
c. <style type="text/css">@import "mycss.css"</style>. One html file can import more than one Css files. A Css file can also import other Css files.
The priority of a is higher than b/c. The more special, the higher priority. For the methods with equal priority, override principle is applied. The difference between b and c is that c loads all the Css codes while b only loads the corresponding Css code when necessary.
Some special usage of Css.
p.special{}h1,h2,p{}p span{} for descendents and p>span{} for child. complex embedding mixing tags, classes, and ids: td.out .inside strong{}. The easiest way to recognize this kind of embedding is “(tag)(.class) (tag)(#id)”th+td+td+td{}, the style is applied to the third td.Css formats for some commonly used tags.
1 | body{ |
1 | p{ |
1 | img{ |
<div> box layout from inside to outside: content, padding, border, margin. Note width and height are for content instead of the whole box. margin can be assigned negative values. Assigning attribute values in clock-wise order. Missing values are equal to the values of opposite side. We should first understand the standard flow without the constraints of boxes.
<ul>, <li>, <div>inline (horizontal arrangement): <strong>,<a>, <span>
<div> and <span> are both blocks. <div> is vertial while <span> is horizontal. <span> can be used where no other proper tags can be used,s for instance, <span><img src="a.jpg"></span>.
when using <div>, the margin between the top block and bottom block is max(top_block.bottom_margin,bottom_block.top_margin). when using <span>, the margin between the top block and bottom block is top_block.bottom_margin+bottom_block.top_margin.
floating box: Arrange the non-floating boxes first and then float the floating box to the left or right in the father content. The stuff in the non-floating boxes surrounds the floating box. For floating box: float:left. For non-floating box: clear:left.
box location: static(default), relative, absolute
relative: position:relative; left:30px; top:30px. Relative shift from original position. Relative has no impact on father box and sibling box.
absolute: position:absolute; top:0px; right:0px. Absolute coordinate in the nearest non-static ancestor. Other boxes treat this absolute box as non-existence.
<div style="display:inline"></div>, <span style="display:block"></span>, use display to modifiy the vertical or horizontal order. Set as none to make it invisible.
For hyperlink, a has pseudo classes:link, visited, hover, for example:
1 | #navigation li a:link, #navigation li a:visited |
Use div to split columns
absolute method: left column uses absolute position (Note to change the position of father div to relative) and right column use left margin. The drawback is that bottom row will ignore the left column.
float method: float left and float right. It is easy for fixed width or fixed ratio. For the mixed width such as 100%-30px, use the wrapper trick (negative margin).
1 | <script> |
variable types
null: empty variableparseFloat(string), parseInt(string), str.substring(0,3), str.slice(3,5), str.charAt(0), str.bold(), str.fontcolor("red"), str.lengthMath.PI, Math.max, isNaN(value),true or falseArray: can be a mixture of numbers and strings, var a = new Array(10, 20, "newly")
1 | for(n in actorAry) |
myarr.toString(), myarr.join('-'), myarr.concat(tailarr), myarr.reverse(), myarr.sort(cmpfunc), slice, splice
stack&&queue operations: myarr.push("newstr"), myarr.pop(), myarr.shift()(dequeue), myarr.unshift()(pushfront)
Structure: There is no concept: class. Use function to construct an object. var mycard = Card("newly", 20), showCardInof.call(mycard,arg1,arg2) or mycard.showCardInfo(arg1,arg2), mycard=null
1 | function showCardInfo(arg1,arg2) |
type related: nameList instanceof Array, typeof("newly")
commonly used built-in functions or classes
alert dialogue: alert("msg")
input diaglogue: var age=prompt("Input your age", "0")
confirm dialogue: confirm("Are you sure?")
Date and time:
1 | var cur = new Date(); |
1 | var e = new Error(); |
operate on the html elements
<img src="./images/web_fig.jpg" width=500px>
The whole HTML page is a DOM tree.
Visit the DOM elements
1 | document.myform.elements[0].value //myform is the form name |
Since id is unique, we use single form element for Id, but plural form elements for Name and TagName.
Change the DOM elements
1 | var docBody = document.getElementById("DocBody"); |
use Javascript to modify the CSS style, document.vlinkColor, document.linkColor, document.alinkColor, document.bgColor, document.fgColor, document.body.text, name1.vspace, name1.hspace.
event handling: we can set event triggering function for certain element or a class of elements.
onblur, onchange, onclick, onfocus, onload, onmouseover, onmouseout, onmousedown, onmouseup, onselect, onsubmit, onunload. Form-related events: myform.onReset, myform.onSubmit, myform.action="mailto:ustcnewly@gmail.com"onlick="javascript:alert("msg")" //javascript: can be eliminatedonkeyup = "OnKeyUp()" 1 | function OnKeyUp(_e) |
1 | <script for="document" event="oncontextmenu"> |
time control:to=window.setTimeout("func()",3000), clearTimeout(to), tm=setInterval("func()",1000), clearInterval(tm)
redirect href location or set anchor point:window.location.href="www.baidu.com", <a name="anchor1"></a>
history: history.back(), history.forward(), history.go(n), n>0 means go back n pages, otherwise go forward n pages.
cookie contains key-value pairs: document.cookie="user=newly;passwd=hehe;"
C: build a library1
2gcc -c -fPIC libtest.c
gcc -shared libtest.o -o libtest.so
Python: load the library1
2
3from ctypes import *
libtest = cdll.LoadLibrary(libtest.so')
print libtest.func(arg_list)
Makefile sample and python sample code
For the types without need to know the detailed layout, we can just use c_void_p, especially when we cannot find the strictly matched self-defined type such as LP_cfloat_1024.
POINTER is used for defining type.
pointer and byref function similarly. However, pointer does a lot more work since it constructs a real pointer object, so it is faster to use byref if you don’t need the pointer object in Python itself.
write free function in C code1
2
3
4
5void freeme(char *ptr)
{
printf("freeing address: %p\n", ptr);
free(ptr);
}
call free function in Python1
2
3
4lib = cdll.LoadLibrary('./string.so')
lib.freeme.argtypes = c_void_p,
lib.freeme.restype = None
lib.freeme(ptr)
Fundamental Stuff:
Key Notes:
Required Packages:
BLAS: (Basic Linear Algebra Subprograms)
operations like matrix multiplication, matrix addition,
both implementation for CPU(cBLAS) and GPU(cuBLAS).
provided by MKL(INTEL), ATLAS, openBLAS, etc.
Boost: a c++ library, use some of its math functions and shared_pointer.
glog,gflags:provide logging & command line utilities. Essential for debugging.
leveldblmdb: database io for your program. Need to know this for preparing your own data.
protobuf: an efficient and flexible way to define data structure. Need to know this for defining new layers.
1 | #include< boost/tokenizer.hpp> |
split string: default space
1 | string s = "This is, a test"; |
split string: drop delimiter
1 | typedef boost::tokenizer<boost::char_separator<char>> tokenizer; |
split string: drop delimiter and keep delimiter
1 | typedef boost::tokenizer< boost::char_separator< char> > tokenizer; |
special kinds of tokenizer
1 | int offsets[] = {2,2,4}; //three segment length |
1 | #include < boost/regex.hpp> |
regex_match
1 | regex expression("^select ([a-zA-Z]*) from ([a-zA-Z]*)"); |
regex_search
1 | boost::regex r("(a+)"); |
Note regex_match(in.c_str(), what, expression) is for complete match while regex_match(in.c_str(), what, expression) is for incomplete match.
regex_match(in.c_str(), expression, target_exp).
special setting for regex
1 | boost::regex e2(my_expression, boost::regex::icase); \\case insensitive |
1 | #include < boost/lexical_cast.hpp> |
conversion between number and string: replace the atoi, itoa, and etc
1 | cout<< lexical_cast< string>(i)<< endl; |
mixed types: for type generalization
1 | #include < boost/fusion/adapted/boost_tuple.hpp> |
Problem: When installing boost, “cl not found”. Or unresolved reference.
Solution: cd Microsoft Visual Studio 11.0\VC, run vcvarsall.bat amd64. add Microsoft Visual Studio 11.0\VC\bin into environmental Path. Refer to http://www.boost.org/doc/libs/1_59_0/more/getting_started/windows.html for installation details.
Note that 32 bit and 64 bit should be treated differently when using b2.exe. For 32 bit, run b2 toolset=msvc-11.0 --build-type=complete --libdir=C:\Boost\lib\i386 stage. For 64 bit, run b2 toolset=msvc-11.0 --build-type=complete --libdir=C:\Boost\lib\x64 architecture=x86 address-model=64 stage.
To put it simple, download binary files from http://sourceforge.net/projects/boost/files/boost-binaries/. Boost is auto-link which means you don’t need to add all lib files manually.
If you have installed boost, using it in a VC project just takes two steps:
C/C++->General: Additional Include Directories D:\Program_Files\boost_1_59_0_binary\boost;
Linker->General: Additional Library Directories D:\Program_Files\boost_1_59_0_binary\lib64-msvc-11.0;
Add D:\Program_Files\boost_1_59_0_binary\lib64-msvc-11.0 in the environmental variable Path.
Notes:
1 | #include < boost/filesystem.hpp> |
file name operation
1 | //Note the difference between /= and +=, /= means appending directory, += means string concatenation |
file operation: rename, remove, copy
1 | exists(path); |
shallow visit directory
1 | path dir2("c:\\Windows\\System32"); |
deep visit directory: like DFS, stack push&&pop
1 | typedef recursive_directory_iterator rd_iterator; |
catch error
1 | try |