kenics.net

Technical notes on perl, python, php, sql, cgi, c/c++, q/kdb+, unix/shell, revision control tools, data structures & algorithms, and their applications into web services and other various forms of software engineering.

misc

########################################## 
###   how to prevent an ssh timeout    ### 
########################################## 
 
## 
##   in general 
## 
 
$ cat  ~/.ssh/config 
ServerAliveInterval 60 
ServerAliveCountMax 180 
 
# this just says send a keepalive packet every 60 seconds, and repeat it 180 times. (which means 3hrs in this case) 
 
or you can specify it as a parameter to the ssh cmd itself. 
 
$ ssh <user_name>@<host_name> -o ServerAliveInterval=60       // this is in seconds 
 
or there may be a default env var TMOUT set to some value. e.g. TMOUT=3600  your sessions exists after 1hr of inactivity 
set TMOUT=0 to prevent it. 
 
## 
##   putty 
## 
 
(ref) 
http://www.smerret.com/computers/linux/how-to-prevent-an-ssh-timeout-in-putty 
 
in "setting" menu, go to "Connection" tab, find "Sending of null packets to keep session active" section. 
 
there is a "Seconds between keepalives (0 to turn off)" cfg box. default is 0, so set it to some non-zero value. 
(you dont wanna flood your server with too frequent keepalive packets, so maybe 180 sec should be good to begin with, then adjust later as needed) 
 
 
######################## 
####   ssh setup    #### 
######################## 
 
putty is great in both generating public/private keys and ssh'ing. 
 
or do it natively on cmd line 
$ ssh-keygen -t rsa 
$ Enter file in which to save the key (/home/<user_name>/.ssh/id_rsa): 
$ Enter passphrase (empty for no passphrase): 
 
# get your pub key copied onto ~/.ssh/authorized_keys on the server 
# pub key is saved onto /home/<user_name>/.ssh/id_rsa.pub 
 
 
 
################################# 
####  ssh into your macbook   ### 
################################# 
 
System Preferences - Sharing (enable "remote login") # this will open port22 for ssh 
 
 
################################# 
####     mac / BSD notes     #### 
################################# 
 
because mac is a BSD derivatives, some commands behave differently than standard linux distrib. 
 
e.g. 
 
sed -i    's/{/[/' foo.py     # linux 
sed -i '' 's/{/[/' foo.py     # mac 
 
 
 
################################### 
###   free online html editor   ### 
################################### 
 
https://htmledit.squarefree.com/         # this is great 
 
 
################################### 
###   free real time compiler   ### 
################################### 
 
https://ideone.com/       # this is great, supports 60 languages 
 
 
############################################ 
###   how to save PDF files onto iphone  ### 
############################################ 
 
open the PDF file on safari browser or email app, then hover over the top area, then click on "open in" then choose iBooks or Kindle, it will copy locally to your iphone. 
 
 
####################################### 
####   keyboard for iphone/ipad    #### 
####################################### 
 
i used "DN-11219" by Shanghai Donya. very smooth. only guaranteed to work on iOS 7.1.1 
 
(ref) 
http://news.kakaku.com/prdnews/cd=pc/ctcd=0150/id=38619/ 
 
there are soooo many keyboards-for-iphone/ipad using bluetooth which i personally dont like because of battery needs for bluetooth. 
 
 
############################## 
#####   iphone t-shoot    #### 
############################## 
 
- when iphone home button gets hot, and the screen blacks out, and does not respond to anything, press both home button and the power button for 10 secs, then it will revive. 
 
 
###################################################### 
####   how to use ssh terminal from iphone/ipad   #### 
###################################################### 
 
there are quite a few iOS ssh clients, both free and non-free. 
i used serverauditor free edition. it's very good. it can save sessions, import private RSA key (which you can transfer from itunes on PC). 
 
(ref) 
https://www.serverauditor.com/ 
 
but one thing to note is it accepts openSSH format key, so we need to convert putty format key to openssh using puttyGEN. I will just blatantly quote from this link. 
 
(ref) 
https://help.cloudforge.com/entries/23248702-Converting-PuTTY-private-keys-to-OpenSSH-format) 
 
-   Open your private key in PuTTYGen 
-   Top menu "Conversions"->"Export OpenSSH key". 
-   Save the new OpenSSH key when prompted. 
 
# NOTE: dont forget to change your color scheme at "setting" tab before you logon. 
 
 
 
 
################################# 
####     git resource      ###### 
################################# 
 
http://git-scm.com/book/en/ 
http://justinhileman.info/article/git-pretty/full/ 
https://gist.github.com/ceeeKay/311f35c0012d637a6f48 
 
 
 
######################################################### 
#####      how to retrieve auto-fill passwords      ##### 
######################################################### 
 
when you let your browser auto-fill the passwords to any services, you will never have to type your passwords again, then eventually forget your passwords, and will need to retrieve somehow the passwords from the browser. 
 
chrome://settings/passwords 
 
 
 
############################ 
####      MAC OS X      #### 
############################ 
 
MAC OS is based on BSD, not linux. Hence a few differences here and there. 
 

#  ~/.bashrc  and ~/.bash_profile 

 
MAC OS X terminal by default loads .bash_profile 
 

#  ls -G          and ls --color=auto 
#  LSCOLORS(bsd)  and LS_COLORS (linux) 
 
http://linux-sxs.org/housekeeping/lscolors.html 
http://geoff.greer.fm/lscolors/ 
 

#   GREP_COLOR='1;31' 

 

# use option/alt as meta key 

set it from terminal/preferences 
 

#  jpn-english IME swtich 

 
by default; 
english  :   "control" + "shift" + ";" 
japanese :   "control" + "shift" + "j" 
 

#  page up/down 

 
fn + arrow 
 
 
 
##################################### 
###   how to install PIL on mac   ### 
##################################### 
 
PIL = python imaging library 
 
sudo easy_install pip 
sudo pip install pil --allow-external pil --allow-unverified pil 
 
 
 
 
############################################# 
###   how to install numpy/opencv on mac  ### 
############################################# 
 
numpy = (python scientific number manipulator) 
opencv = open source computer vision lib 
 
install (1) Xcode, (2)mac ports, (3) numpy and cv2 
 
(1) xcode 
go to AppStore, and download Xcode. 
 
(2) mac ports (simply download the installer and click on it, the rest is automatic) 
http://www.macports.org/install.php 
 
 
(3) numpy and cv2 
 
https://compphotography.wordpress.com/2013/04/08/macos-python-install-macports/ 
 
sudo port selfupdate 
sudo port install python27 py27-numpy py27-scipy 
sudo port install opencv +python27 
sudo port select --set python python27 
 
# steps to validate 
$ python 
import numpy 
import scipy 
import cv2 
numpy.__version__ 
scipy.__version__ 
cv2.__version__ 
 
 
 
################################# 
####   method VS function    #### 
################################# 
 
essentially the same. 
a function defined within a class is called a method. (or "member function" in C++) 
in practice, unlike a function, a method can access member variables without them being explicitly specified as input parameters. 
 
 
############# 
###  SDP  ### 
############# 
 
Unit test        : testing of a single module, e.g. a function within a class 
Integration test : testing of more than one modules 
 
blackbox test : testing where we dont have access to the internal/src of the subject 
whitebox test : opposite to blackbox 
 
test perspectives: functional, capacity, UI 
 
 
######################### 
###   photo backup    ### 
######################### 
 
as of 2019, 
 
Google Photo lets you back up an unlimited number of photos for free, with at most 16 mega pixel per photo (which covers any normal smartphone photo resolution) 
 
icloud is ok (only 5GB free space). dropbox is ok (only 2GB free space). 
 
 
############################################################ 
###  how to mount NTFS in writable mode on mac computer  ### 
############################################################ 
 
note: this is apparently a hack, and potentially disruptive, and could corrupt your NTFS data 
add this line in /etc/fstab     # you may have to run sudo vifs  to edit it 
LABEL=foobar none ntfs rw,auto,nobrowse 
 
note: replace foobar with the actual name of the NTFS drive 
      once done writing to NTFS, remove the above. 
 
 

  1. 2015-02-05 23:29:08 |
  2. Category : unix
  3. Page View:

Google Ads