Total Pageviews

Wednesday, June 4, 2014

Java/Android Notes


  • How is Java program created/built/executed?
    • Create Hello.java.
      • Create class Hello.
      • Inside the Hello class, create a static method main with the signature:
        • public static void main(String[] args)
      • Inside the main method, use System.out.println("Hello world!"); to write to standard output.
    • Use javac Hello.java to create Hello.class.
    • Use java Hello to run Hello.class, notice no .class extension when using java to execute a class.
  • Write a Java program that defines/uses package.
    • Assume current directory is hello.
    • mkdir -p a/b/c && cd a/b/c
    • Inside a/b/c, create a file Add.java.
    • Inside Add.java file, declare the package it belongs to:
      • package a.b.c;
    • Inside Add.java file, create a public class Add.
    • Inside class Add, create a public static method add with the signature:
      • public static int add(int a, int b)
    • Go back to hello directory: cd hello.
    • Create a file AddTest.java.
    • Inside the AddTest.java file, import class Add from package a.b.c:
      • import a.b.c.Add;
    • Inside the AddTest.java file, create a public static main method with the signature:
      • public static void main(String[] args)
    • The main method:
      • Read arguments from the command line.
      • Use Integer.parseInt to convert them to int.
      • Call Add.add to compute the sum.
      • Call System.out.println to print the result to standard output.
    • In directory hello, compile the AddTest.java file by javac AddTest.java, it generates AddTest.class.
    • Run the program: java AddTest 1 2, should see the result 3 printed to the standard output.
  • Java's member access rule:
  • Modifier    | Class | Package | Subclass | World
    ————————————+———————+—————————+——————————+———————
    public      |  y    |    y    |    y     |   y
    ————————————+———————+—————————+——————————+———————
    protected   |  y    |    y    |    y     |   n
    ————————————+———————+—————————+——————————+———————
    no modifier |  y    |    y    |    n     |   n
    ————————————+———————+—————————+——————————+———————
    private     |  y    |    n    |    n     |   n
    
    y: accessible
    n: not accessible
  • How to import .jar in ADT
    • Download the library .jar file x to folder p.
    • In the `Package Explorer', find libs folder (if not exists, create one: New -> Folder).
    • Right click libs, Import -> General -> File System.
    • Navigate to folder p, find x in the right panel. Check the check-box. Click Finish.
    • If libs is already in the build path, we are done. Otherwise, Right click the project, Build Path -> Configure Build Path..., select Libraries tab. Click Add JARs..., find the x, click ok.
  • How to setup jni? (TODO)
  • How to call c/c++ procedure from Java through jni? (TODO)
  • How to call Java procedure from c/c++ through jni? (TODO)

Friday, October 25, 2013

Ruby notes from Javascript coder


  • Symbols begins with :
  • function call do not need (), just mention it.
  • If you want to get the function object instead of the result of calling it, use method(:function_name), obj.method(:method_name) or class.instance_method(:method_name).
  • no curly braces, use `end` key word.
  • string enclosed by "" can be perform fancy variable substitute; with '', no substitute.
  • substitute: #{variable_name}, #{variable_name.method}
  • Inside class, @prop means `this.prop`
  • To define class properties: attr_accessor, attr_reader, atter_writer
  • Result of the last express in a method definition will be the return value.
  • Can define constants by using upper case letter as variable name. It is still mutable, but the interpreter will complain.
  • By convention, methods end with ? are predicates, they all return a boolean value.
  • By convention, methods end with ! would perform some mutation to the object.
    • list.sort => return a new list
    • list.sort! => sort the list in place
  • Variable naming and their scope:
    • begin with $ => global
    • begin with @ => instance variable
    • begin with @@ => class variable
    • begin with [a-z_] => local
    • begin with [A-Z] => constant
  • Special global variables: $@, $_, $., ..., http://www.tutorialspoint.com/ruby/ruby_predefined_variables.htm
  • Function arguments:
    • variable length of arguments, (*args), then args will be a Enumerable
    • default value def method(a=1, b)
  • Operate on collection (Enumerable class): http://ruby-doc.org/core-2.0.0/Enumerable.html, mapping from Javascript Array methods:
    • filter <=> select
    • reduce <=> reduce, inject
    • map <=> map, collect
    • every <=> all?
    • some <=> any?
    • flat_map == collect_concat
  • Lambda expression:
    • function(x){return x*2;} => {|x| x*2}, do |x| x*2 end
  • Ranges:
    • (1..10) , double dot, includes 10
    • (1...10), triple dot, does not include 10
  • JSON like hash syntax works on later version of ruby. But the original syntax looks like:
    • my_hash = { :a => 1, "b" => 2, 3 => 3 }
  • Array decomposition can be used to pull out values from a array and assign them to variables:
    • a, (b, *c), *d = 1, [2, 3, 4], 5, 6
  • Support modifier form for if, unless, while, until
    • a += 1 if a.zero?
    • a += 1 while a < 10
    • a += 1 until a > 10
    • begin a+= 1 end while a < 10
  • Ruby use `next` key word instead of `continue`
  • Regex:
    • create syntax => same as Javascript:  /[0-9a-z]/i
    • re.test( 'some string' ) <=> re === 'some string'











Tuesday, June 11, 2013

Download all pdf links from ASCE search page


- Search the articles by key word
- Get a web page that list all the pdf links
- Inspect the pdf link element, looks like this:
    <a class="ref nowrap" target="_blank" title="Opens new window" href="/doi/pdf/10.1061/%28ASCE%290733-9488%282001%29127%3A3%28118%29">PDF (1569 KB)</a>
- Open browser console, use jQuery select the pdf links based on its class/text/or other features
    pdfLinks = [];
    $('.ref:contains("PDF")').each( function() {  pdfLinks.push( $(this).attr( 'href' ); ) } ) ;
    pdfLinks.join( '\n' )
- Copy the output text from browser console, and save it to a text file list.txt.
- Use wget to get all the links:
    cat list.txt | xargs -I{} wget http://ascelibrary.org{}

Thursday, January 24, 2013

Install WordPress on linux server

Here are the instructions for setting up your own WordPress server. In this example, the server runs CentOS 6.3. Before you get started, switch to root user first, since most of the instructions below require a root privilege.
  1. Install related softwares: yum install httpd mysql-server mysql php php-mysql
  2. Start httpd and mysql: service start httpd service start mysqld Now open http://localhost, you should see a test page that indicates the server is working.
  3. Set up mysql server: Use mysqladmin utility to do the job: mysqladmin -u root -p password 123456 Then a prompt 'Enter password:' should appear, just hit enter since the default root user has no password. After this step, the mysql server has been setup. There is a user 'root' with the password 123456 (of course, you can change it).
  4. Install database manage tool phpMyAdmin: This tool provide a web gui interface to manage the mysql database.
    • Download the latest version of phpMyAdmin and put into the document root of Apache server(usually is /var/www/html): cd /var/www/html wget 'http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/3.5.5/phpMyAdmin-3.5.5-all-languages.tar.bz2/download#!md5!3f77e1a608939224a7dce97caf860f46'
    • Uncompress the file to phpmyadmin folder and remove the downloaded file: tar xvf phpMyAdmin-3.5.5-all-languages.tar.bz2 mv phpMyAdmin-3.5.5-all-languages phpmyadmin rm -rf phpMyAdmin-3.5.5-all-languages.tar.bz2
    • Now open http://localhost/phpmyadmin in the browser, you should see a login interface. Login with username root and password 123456 (configured in step (3))
  5. Create a new user and database for wordpress: In phpMyAdmin page:
    • Login phpMyAdmin as root.
    • In phpMyAdmin, click 'Users' tab on home page.
    • Click 'Add User'
    • In 'Add User' form, fill in the user information.
    • User name: choose 'User text field', fill in 'wordpress'
    • Host: choose 'Local'
    • Hit generate password, copy the generated password to somewhere else for future use. In this example, the password is jcqu9LH5C82h238c
    • Under 'Database for user' tab, choose second option: 'Create database with same name and grant all privileges'
    • Hit 'Add User', now the user 'wordpress' and database 'wordpress' is added to the mysql database.
  6. Install wordpress:
    1. Download and uncompress the lastest version of wordpress into document root:cd /var/www/html wget http://wordpress.org/latest.tar.gz tar xfv latest.tar.gz wordpress rm -rf latest.tar.gz Now a folder name 'wordpress' is placed under the document root.
    2. Create the config file by copying the sample file: cd wordpress cp wp-config-sample.php wp-config.php
    3. Configure database:
      • Use your favourite text editor, open wp-config.php file: emacs ./wp-config.php
      • Replace the corresponding lines in the file with your own database settings: define('DB_NAME', 'wordpress'); define('DB_USER', 'wordpress'); define('DB_PASSWORD', 'jcqu9LH5C82h238c');
      • Save the file
    4. Web interface install:
      1. Launch http://localhost/wordpress, now you should see a welcome page of wordpress.
      2. Follow the instruction in wordpress install page, choose site title, i.e., set up admin password, fill in your email address, then hit 'Install Wordpress'.
      3. If everything above goes well, it will redirect to a page that tells you WordPress has been successfully installed. Now you can log in the wordpress as 'admin' and configure you website via WordPress web interface.
  7. Set up proper folder permissions: Usually you need setup a ftp server to manage plugins. But it can be configured in such a way that the plugins install directly into /wp-content/plugins folder, which is easier. To do so:
    • Add a line in wp-config.php: define('FS_METHOD', 'direct');
    • Change the owner of /wp-content folder to apache server: chown -R apache:apache wp-content

Friday, March 11, 2011

Tuesday, March 8, 2011

install flashplayer on Linux 64 machine

In linux 64 firefox, you can not browse flash content by default, you will have to download the linux 64 version library libflashplayer.so from http://labs.adobe.com/downloads/flashplayer10_square.html, then search libflashplayer.so in the computer and replace them with the 64 bit version.

Sunday, March 6, 2011

how to acquire 3D point cloud from multiple camera views

Microsoft's photosynth can do that. How do they calibrate the camera?

In CV class, I learned to reconstruct 3D scenes from two views. In two camera views case, without camera calibration, projected structure is best you can get. If you want to recover the original structure, you have to suppress your knowledge of the real structure such as parallel, perpendicular, or more than five points' coordinates.  Usually we need to use check-boards to calibrate the camera.

In photosynth, we are not asked to choose the lines that a orthogonal or parallel, neither to take photos with a check-board. But we offer more than two views. What will we benefit from that? Can we calibrate the camera without providing any extra information beyond the pixels? Andrew says maybe they can get the parameters of camera from the photo itself. Well, it is a possible way, but what if we don't have the information?