Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Tuesday, December 10, 2019

Build FreeRDP with smartcard on Ubuntu

Compilation instruction
Besides the suggested base dependencies, also install libpcsclite-dev



sudo apt install libpcsclite-dev
cmake -DWITH_PCSC=ON -DWITH_SSE2=ON .

Then follow the Build section in the compilation instruction.

How to use xRDP for remote access to Ubuntu

 
By | February 14, 201
 

Since the current desktop manager of Ubuntu does not work with xRDP, an alternative desktop manager needs to be installed. In this post, we will use XFCE.

Install xRDP and XFCE


sudo apt-get install xrdp xfce4 xfce4-terminal gnome-icon-theme-full tango-icon-theme

Configure xRDP

First, create an .xsession file in the home directory.

echo xfce4-session >~/.xsession
Then edit the startup file for xRDP /etc/xrdp/startwm.sh.








#!/bin/sh
 
if [ -r /etc/default/locale ]; then
  . /etc/default/locale
  export LANG LANGUAGE
fi
 
startxfce4

Restart xRDP


sudo service xrdp restart

Test xRDP

As an example, on Windows, start the Remote Desktop client (mstsc.exe) and enter the IP address of Ubuntu. Then you will see the login screen. After entering the Ubuntu username and password and click “OK”, a window will show the login process. Finally, you’ll have access to your Ubuntu machine.

Saturday, December 7, 2019

Find receipts in Gmail


By | October 8, 2013 
 
 I just found that Gmail can automatically detect receipts from PayPal, Google Play and Google Checkout, order confirmations from eBay, Amazon and other shopping sites. Try to search label:^smartlabel_receipt in your Gmail!!!

Saturday, September 7, 2013

What are the differences between pointers and references in C++?

Pointers and references look very different (pointers use * and ->, while references use .), but they seem to have the same function: both can be used to indirectly point to another object. So when should you use pointers vs. references?
  • The most important thing you should always remember is that, reference can never be assigned NULL directly. A reference has always to refer to an object. Therefore, if you need a variable that needs to point to nothing sometimes, then this variable should be declared as a pointer, not a reference. The fact that reference should always refer to an object makes the program more effective, because it doesn’t need to be tested null before usage.
  • A pointer can be re-assigned to another object, but a reference cannot. A reference must be assigned at initialization.
  • A pointer can points to a 2nd pointer, which points to a 3rd pointer, … This offers extra levels of indirection. Whereas a reference only offers one level of indirection.
  • Pointers can iterate over an array, you can use ++ to go to the next item, and +n to go to the (n+1)th element. This is no matter what size the object is that the pointer points to.
  • The last situation is that when you need to overload an operator, you should use references rather than pointers. A typical overloaded operator is [], by which an object should be returned. For example
    vector<int> v(10);
    v[5] = 10;
    
    If the operator [] returns a pointer, the last line would be
    *v[5] = 10;
    
    This would make v look like a vector of pointers.
Also, a pointer has its own memory address and size on the stack, whereas a reference shares the same memory address with the original variable. So it is safe to think of a reference as another name for the same variable. This difference is important, but I don’t think it is a reason when choosing references vs pointers.

Thursday, September 5, 2013

When to use Comparable and Comparator?

By  | September 8, 2013

Programcreek demonstrates examples of using Comparable and Comparator. The next question will be when to use Comparable and Comparator. Here I list two basic rules (actually only the first one is really important):
  1. If there is a natural ordering of the object, then the class should implement Comparable, e.g., integers, strings (generally in the alphabet order), and points. On the other hand, if an object has multiple ways of ordering, then Comparator interface should be used to specify which way of sorting should take place. For example, HDTV in the Programcreek example can either be sorted by size or band name. In such case, Comparator is should be used. Another advantage is that Comparator can specify which parameter to be used for ordering. It then can be self descriptive. Hence, we can have SizeComparator and BandComparator for comparison, respectively.
  2. If you are not able to change the code of the object, which means you cannot implement Comparable, then Comparator is the only way left.
In summary, order of comparison is very important while implementing objects. Requirements may even change during implementing. For example, strings are generally compared alphabetically, but you may need to compare strings on their lengths as well. Therefore, designing of comparison needs to be very careful. In general, implement Comparable for natural order and write a Comparator for other needs.

Sunday, August 25, 2013

Markdown Editors

http://blog.pengyifan.com/best-markdown-editors-for-windows-linux-and-the-web/

Friday, May 10, 2013

How to change the title of an xterm

  • ESC]0;stringBEL – Set icon name and window title to string
  • ESC]1;stringBEL – Set icon name to string
  • ESC]2;stringBEL – Set window title to string
An xterm title of username@hostname: directory:
    echo -n "\033]0;${USER}@${HOST}\007"

For bash
    case $TERM in
        xterm*)
            PS1="\[\033]0;\u@\h: \w\007\]bash\\$ "
            ;;
        *)
            PS1="bash\\$ "
            ;;
    esac

For zsh
    case $TERM in
        xterm*)
            precmd () {print -Pn "\e]0;%n@%m: %~\a"}
            ;;
    esac

Sunday, April 21, 2013

Ignoring DTD in XMLUnit


@BeforeClass
public static void onlyOnce() {

 XMLUnit.setIgnoreWhitespace(true);
 XMLUnit.setIgnoreComments(true);
 XMLUnit.setIgnoreAttributeOrder(true);

 // don't validate dtd
 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 dbf.setValidating(false);
 try {
   dbf.setFeature("http://xml.org/sax/features/namespaces", false);
   dbf.setFeature("http://xml.org/sax/features/validation", false);
   dbf.setFeature(
       "http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
       false);
   dbf.setFeature(
       "http://apache.org/xml/features/nonvalidating/load-external-dtd",
       false);
 } catch (ParserConfigurationException e) {
   e.printStackTrace();
 }

 XMLUnit.setTestDocumentBuilderFactory(dbf);
 XMLUnit.setControlDocumentBuilderFactory(dbf);
}

Saturday, April 13, 2013

Texlive and CJK

  1. suppose texlive and CJK is installed correctly
  2. install fontforge
    sudo apt-get install fontforge
    
  3. download font.tar.bz2
  4. prepare font song.ttc, and generate font files
    fontforge -script subfonts.pe simsun.ttc song Unicode.sfd
    
  5. create bash script makemap.sh, run the script to generate map file
    if [ -f song.map ]; then
        rm song.map
    fi
    for i in *.tfm
    do
        echo "${i%.tfm} ${i%.tfm} <${i%.tfm}.pfb" >> song.map
    done
    
  6. create c70song.fd
    % This is c70song.fd for CJK package.
    % created by Edward G.J. Lee
    % modify by Yue Wang
    \ProvidesFile{c70song.fd}
    \DeclareFontFamily{C70}{song}{\hyphenchar \font\m@ne}
    \DeclareFontShape{C70}{song}{m}{n}{<-> CJK * song}{}
    \DeclareFontShape{C70}{song}{bx}{n}{<-> CJKb * song}{\CJKbold}
    \endinput
    
  7. check system conf file location
    kpsewhich texmf.cnf
    
  8. change TEXMFHOME to
    TEXMFHOME = $HOME/texmf
    
  9. change TEXMFDBS to
    TEXMFDBS = $TEXMFHOME;$TEXMFLOCAL;$TEXMFMAIN;$VARTEXFONTS;$TEXMFSYSVAR;$TEXMFDIST
    
  10. mimic texmf tree and copy fonts and configs. texmf should match those in TEXMFHOME
    mkdir -p ~/texmf/fonts/map/dvips/CJK
    mkdir -p ~/texmf/fonts/tfm/CJK/song
    mkdir -p ~/texmf/fonts/type1/CJK/song
    mkdir -p ~/texmf/tex/latex/CJK/UTF8
    
    cp song.map   ~/texmf/fonts/map/dvips/CJK
    cp *.tfm      ~/texmf/fonts/tfm/CJK/song
    cp *.pfb      ~/texmf/fonts/type1/CJK/song
    cp c70song.fd ~/texmf/tex/latex/CJK/UTF8
    
  11. update system conf
    sudo texhash
    updmap
    
  12. in $HOME/texmf/fonts/map/pdftex/updmap/pdftex.map, append content in song.map

Wednesday, April 10, 2013

How to adjust height of an old Steelcase chair (454311M)?

The chairs do not have the pneumatic mechanism to adjust the height of the chair. The height is adjusted by turning the chair in circles around the base. The base post contains a screw mechanism that gives 2-3″ of adjustment.

Tuesday, April 9, 2013

Bash IO redirection

> filename
>> filename
1> filename
1>> filename
2> filename
2>> filename
&> filename
2>> &1

Monday, March 11, 2013

Cygwin SSH tip


if you use ssh-keygen to generate public key, use ssh-copy-id, and get the following msg while logging in remote device,
permission for id_rsa are too open
try
1. cd .ssh
2. chmod 600 id_rsa known_hosts

if you can not change the permission of id_rsa, try
1. chgrp -r Users id_rsa
2. chmod 600 id_rsa

if you define hostname aliases in SSH config, and get msg
Bad owner or permissions on /home/[username]/.ssh/config
try
1. chgrp -r Users config
2. chmod 600 config

Friday, February 22, 2013

Mount Nikon D5100 on Ubuntu 12.10


0. install gphoto2 

1. lsusb

Bus 001 Device 003: ID 046d:c31c Logitech, Inc. Keyboard K120 for Business
Bus 002 Device 007: ID 04b0:0429 Nikon Corp.
Bus 002 Device 003: ID 03f0:a407 Hewlett-Packard
Bus 002 Device 004: ID 03f0:0d17 Hewlett-Packard LaserJet 1012


2. gvfs-mount "gphoto2://[usb,002,007]", with quotes
    002 is the Bus number, 007 is the Device number

3. check /run/user/[username]/gvfs or ~/.gvfs

Saturday, December 15, 2012

Setup remote Git repository

suppose the remote server is username@foo.com
suppose the repository is xxx.git

1. set up remote git repository
$mkdir ~/git-rep
$cd ~/git-rep
$mkdir xxx.git
$cd xxx.git
$git init --bare


2. on your local machine, add a remote repository aliases
$git remote add [ALIASES_NAME] username@foo.com
# check
$git remote -v


3. push your copy to the remote repository
# check branch
$git branch
$git push [ALIASES_NAME] master


4. Undo git add before the first commit
$git rm -r --cached .

5. repo inside a repo
$git submodule add [URL]
$git submodule init
$git submodule update

Note:
if you got an error: "bash: git-receive-pack: command not found", try
$git push [ALIASES_NAME] master --receive-pack=[REMOTE_PATH]/git-receive-pack

to avoid it, dump enviroment in .ssh/environment
env > .ssh/environment

Please note that setting up PATH in either .bashrc and .bash_profile does NOT work!