Tuesday, June 11, 2013

Programmer's Survival Guide for Windows

2.  Windows' File System and Basic File/Directory Commands


Windows' file system is NOT case-sensitive

Flow


This is a summary tag
        familial relationships
        collective form of TV watching
        ostracization
        funky clothes
        demeanor
        clique
        expressivity
        deferent waiter
        bittersweet memories
        spontaneous process
        assiduously
        dissipative
        paraplegics
        fulfilling
        terminal illness
        unwavering purpose
        daunt
        suspicion
        epoch

    

Monday, June 10, 2013

Adobe Photoshop CS6 Keyboard Shortcuts


Ubuntu Font on Chrome (Windows)

Three things:
1. Download Ubuntu Font Family
2. Install Ubuntu Font in Windows
3. Chrome Extension

1. Download Ubuntu Font Family

HTML 5 Semantic Element

http://www.w3schools.com/html/html5_semantic_elements.asp

New Semantic Elements in HTML5

They are <div></div> by themselves

Many of existing web sites today contains HTML code like this: <div id="nav">, <div class="header">, or <div id="footer">, to indicate navigation links, header, and footer.
HTML5 offers new semantic elements to clearly define different parts of a web page:
  • <header>
  • <nav>
  • <section>
  • <article>
  • <aside>
  • <figcaption>
  • <figure>
  • <footer>



HTTP Response Error Codes

Error Codes

Because the default handlers handle redirects (codes in the 300 range), and codes in the 100-299 range indicate success, you will usually only see error codes in the 400-599 range.

dbx - Universal Debugger in Unix/Linux

More Advanced Information: http://www-rohan.sdsu.edu/doc/dbx.html

DBX:

C++ map::find() and map::operator[]

// map::find
#include <iostream>
#include <map>

urllib2 -- The Missing Mannual

urllib2 The Missing Mannual

Fetching URLs

The simplest way to use urllib2 is as follows :
import urllib2
response = urllib2.urlopen('http://python.org/')
html = response.read()
Request object

Saturday, June 8, 2013

Reflection in Java (and a little Python)

toString(), iterates through every attributes in a Class


public class Formatter {
    public static String toString(Object aObject) {
        StringBuilder result = new StringBuilder();
        String newLine = System.getProperty("line.separator");
        
        result.append( aObject.getClass().getName() );
        result.append( " Object {" );
        result.append(newLine);
        
        //determine fields declared in aObject class only (no fields of superclass)
        Field[] fields = aObject.getClass().getDeclaredFields();
        
        //print field names paired with their values
        for ( Field field : fields  ) {
            result.append("  ");
            try {
                field.setAccessible(true);
                result.append( field.getName() );
                result.append(": ");
                //requires access to private field:
                result.append( field.get(aObject) );
            } catch ( IllegalAccessException ex ) {
                System.out.println(ex);
            }
            result.append(newLine);
        }
        result.append("}");
        
        return result.toString();
    }

}

Friday, June 7, 2013

Disable auto brightness/ dynamic contrast


  1. ctrl+alt+F12 to call up Intel Graphics->Power->On Battery->Max Performance, Plugged-in->Max Perforamnce
  2. Windows Advanced Power Options -> Display -> turn off "adaptive brightness" 
  3. If it does not work, try to plug and unplug the power supply several times. 

Java Serialization Tutorial

source: http://www.tutorialspoint.com/java/java_serialization.htm

like pickle in Python:
Java provides a mechanism, called object serialization where an object can be represented as a sequence of bytes that includes the object's data as well as information about the object's type and the types of data stored in the object.

Classes ObjectInputStream and ObjectOutputStream are high-level streams that contain the methods for serializing and deserializing an object.

Thursday, June 6, 2013

Permutation in Java and C++

C++

from #include<algorithm>
int a[] = {3,4,6,2,1};
int size = sizeof(a)/sizeof(a[0]);
std::sort(a, a+size);
do {
  // print a's elements
} while(std::next_permutation(a, a+size));

JAVA

public class Permute{
    static void permute(java.util.List<Integer> arr, int k){
        for(int i = k; i < arr.size(); i++){
            java.util.Collections.swap(arr, i, k);
            permute(arr, k+1);
            java.util.Collections.swap(arr, k, i);
        }
        if (k == arr.size() -1){
            System.out.println(java.util.Arrays.toString(arr.toArray()));
        }
    }
    public static void main(String[] args){
        Permute.permute(java.util.Arrays.asList(3,4,6,2,1), 0);
    }
}
You take first element of an array (k=0) and exchange it with any element (i) of the array. Then you recursively apply permutation on array starting with second element. This way you get all permutations starting with i-th element. The tricky part is that after recursive call you must swap i-th element with first element back, otherwise you could get repeated values at the first spot. By swapping it back we restore order of elements (basically you do backtracking).
done

Wednesday, June 5, 2013

File IO in Java

Write: close the BufferWriter as well as FileWriter
Code:
//TODO

Notes 5 June 2013

SQL

start;
rollback;
commit;

core dump

used for dbx

linux

ls -ltr

C++ string empty

don't use =="' || ==NULL
use str.length()<=0;

Tuesday, June 4, 2013

stringstream to cout

std::stringstream ss;
unsigned long long ll = (unsigned long long)&ss;
cout << ll;
That said when you want to cout a stringstream you should use the str() function as follows:
cout << ss.str();

from DB to C++ util::StringTokenizer

void ADEngine::updateConfigs(map<string, string>& prefMap){
    ADYardConfig* config = this->getYardConfig();
    ///< _deleteShiftCntrI
    bool deleteShiftCntrI = DEFAULT_DELETE_SHIFT_CNTR; ///< default value
    if(prefMap.find(DELETESHIFTCNTR)!=prefMap.end()){
        deleteShiftCntrI = atoi(prefMap[DELETESHIFTCNTR].data());
    }
///< _excludeCategory:set<string>
    string excludeCategories = DEFAULT_EXCLUDE_CATEGORY_C;
    if (prefMap.find(EXCLUDECATEGORYC) != prefMap.end()){
        excludeCategories = prefMap[EXCLUDECATEGORYC];
    }
    util::StringTokenizer stringTokenizer(excludeCategories,",");
    while(stringTokenizer.hasMoreTokens()){
        config->addExcludeCategory(stringTokenizer.nextToken());
    }
}

Monday, June 3, 2013

Thinking in Java

Cleanup: finalization (finialize()) and garbage collection 

  1. Your object might not get garbage collected 
  2. Garbage collection is not destruction 
  3. Garbage collection is only about memory
Force garbage collection:
System.gc();

use of finalize:
protected void finalize(){
  if(some conditions)
      errorMessage;
}

Array 

int[] a; 
Random rand = new Random(47); 
a = new int[rand.nextInt(20)]; 

Inner Class

inner class and surrounding class 
public class Parcel1 { class Contents { //protected, also can be + -; private int attribute; public int method() { return 0; } }









OuterClassName.InnerClassName

Out.Inner inner = out.getInner(); 


In addition, inner classes have access rights (link) to all the elements in the enclosing class. (different from C++ which does not have links) 
done

Saturday, June 1, 2013

CSS Collection 1

Web开发技术每年都在革新,浏览器已逐渐支持CSS3特性,并且网站设计师和前端开发者普遍采用这种新技术进行设计与开发。但仍然有一些开发者迷恋着一些CSS2代码。
本文将分享20段非常专业的CSS2/CSS3代码供大家使用,你可以把它们保存在IDE里、或者存储在CSS文档里,这些代码片段绝对会给你带来意外的惊喜。

1. CSS Resets

网络上关于CSS重置的代码非常多。本段代码是根据Eric Meyer’s reset codes进行改编的,里面包含一点响应式图片和所有核心元素的边界框设置,这样就可以保持页边距和填充可以很好地对齐。

CSS Collection 2

http://www.csdn.net/article/2013-05-29/2815470-css-snippets-for-designers
上周,研发频道发表了一篇“ Web开发者不容错过的20段CSS代码”,大家一致觉得很实用。该文是笔者对后30个的翻译,希望对大家有帮助。
1.花式连字符(&)
这个类应该在span元素里使用,并且里面包括&字符。它使用经典的serif字体和斜体来增强&符号。
1
2
3
4
5
.amp {
    font-family: Baskerville, 'Goudy Old Style', Palatino, 'Book Antiqua'serif;
    font-styleitalic;
    font-weightnormal;
}
源码地址: http://css-tricks.com/snippets/css/fancy-ampersand/