Tuesday, 14 August 2012

SVN Tip

SVN Patch

Run command in project root

1. Create a patch
svn diff > mypatch.diff

2. apply a patch
download patch

patch -p0 -i fix_path.diff

3. reverse patch
 patch -p0 -R -i fix_path.diff

4.  How to revert svn commit:
The following two commands will do the trick

svn merge -r 101:100 http://svn.example.com/repos/calc/trunk
svn ci



5. SVN Blame

svn blame svn://repositoy/filename
                       

Thursday, 2 August 2012

Set up localhost server

  1. npm init
  2. npm install express
  3. create a index.html and index.js
  4. node index.js
  5. http://localhost:5000
//index.js
const express = require('express');
const app = express();
const port = 5000;

app.get('/', (req, res) => {
    res.sendFile('index.html', {root: __dirname});
});

app.listen(port, () => {
    console.log(`Now listening on port ${port}`);
});

Create a post api using express

const express = require('express');
const app = express();

//middleware to parse incoming request with json payload
app.use(express.json());

//middleware to parse incoming request with url encoded payload
app.use(express.urlencoded({ extended: true }));

const port = 5000;

app.get('/', (req, res) => {
    res.sendFile('index.html', { root: __dirname });
});

app.listen(port, () => {
    console.log(`Now listening on port ${port}`);
});

app.post('/api/create_transaction', (req, res) => {
    const body = req.body;
    console.log("body:", body);
    res.status(201).json([]);
});

Sunday, 29 July 2012

Change wireless password

1. connect a computer with router by cable
2. go to http://192.168.1.254
3. log in as admin
4. go to wireless ->security
5. change password

Wednesday, 21 December 2011

Propel Memo

Set up project

  1. create database scheme xml from an existing database > propel-gen reverse
  2. create model classes > propel-gen om
  3. create config file > propel-gen convert-conf

Update Database

After database scheme XML is modified, we need to update database. Also need to generate model class again and running time conf

  1. ../Propel/generator/bin/propel-gen sql
  2. ../Propel/generator/bin/propel-gen insert-sql
  3. ../Propel/generator/bin/propel-gen om
  4. ../Propel/generator/bin/propel-gen convert-conf

Tuesday, 20 December 2011

MySql tips

Connect

#enter password manually
mysql --host='10.22.999.162' --user=leo --password

#password in command
mysql -h 10.49.41.213 -u leo --password='mysecret'
Show comments

1. Find table structure
> show columns from book;
> desc book;

get more details
> show create table book;

2 . Find table index
> show index from book;

3. Find permission of user
>  show grants;

show grants for 'cs_user'@'10.32.%.%' 
4. Find stored procedures
>  show procedure status

5. Find triggers
>  show triggers

6. Find more shows

More show commands

> help show;

Date time functions

 >  select date_format(convert_tz(from_unixtime(1370132292), "UTC", "America/Vancouver"), "%Y %m %d");

Stored Procedure

1. create procedure
drop procedure if exists countbook;

DELIMITER //

create procedure countbook()
BEGIN
    select count(*)
    from book;
END //

DELIMITER ;


2. call procedure
> call countbook() 

3. more notes
Stored procedure can take parameters. Parameters can be inputs or outputs. Inside procedure, can declare function (see ben forta MySql crash course)


More Store Procedure

 //find procedure
show procedure status where db="myDW"\G

//show procedure details
show create procedure load_dim_date\G

//flip that from security_type=definer to the invoker
ALTER PROCEDURE update_dim_date SQL SECURITY INVOKER;

More show process list

show full processlist
# 1234 is process id coming from show processlist
kill 1234

Find mysql server hostname

show variables where Variable_name = 'hostname';
+---------------+--------------------------------------+
| Variable_name | Value                                |
+---------------+--------------------------------------+
| hostname      | ip-10-32-210-21.corp.leotest.com |
+---------------+--------------------------------------+
1 row in set (0.09 sec)

Find mysql users

select * from mysql.user \G

Find mysql version

select version();

Update allowed ip for a user

# if version 5.7.8 and up, can use remame statement
RENAME USER 'qrhen'@'10.17.259.170' TO 'qrhen'@'10.31.248.110';

Grant permission to user

GRANT SELECT ON `MyTabble`.* TO `lyhen`@`10.33.264.%`;



FLUSH PRIVILEGES;

SHOW GRANTS FOR `lyhen`@`10.33.264.%`;

#show grants for current logged in user
show grants;

Check which process owns 3306

lsof -i :3306

Saturday, 26 November 2011

jQuery cheat sheet

  • parent()
  • parents()
  • closest() find the parent element nearest to the selected element
  • children()
  • siblings()
  • prev()
  • next()
  • remove() $("p").remove() remove p elements
  • empty() $("p").empty() delete content in ps
  • detache() $elememts = $("p").detache() remove and hold
  • replacewith()
  • before()
  • after()
  • first()
  • eq()
  • last()
  • slice()
  • filter()
  • not()

Thursday, 24 November 2011

Create a SVN repository

Assume SVN server name is apple

1. ssh to  apple
svnadmin create /var/svn/project_name

2. go back to my machine, cd to  project_name/
svn import svn+ssh://apple/var/svn/project_name

3. check out
svn co svn+ssh://apple/var/svn/project_name

Wednesday, 23 November 2011

Regular Expression

Special Symbol
 \d is digit
\s is white space
. any char
\w equal [A-Za-z0-9_]


boundary
^ is start of string
$ is end of string
\b word boundary

how many times (for previous item)
?  0 or 1
* 0 or more
+ 1 or more
{n} n times
{n,} at least n times
{n,m} n<=match times<=m

group
(pattern) group as one item
(x|y) x or y
[abc] either a,b or c
[^abc] any char except a,b,c
[a-d] match a,b.c or d

PHP related function
preg_match("/mypatter/i", $subject) return 1 if match; otherwise, return 0.  i is a flag for case insensitive search.

Example

all combinations of digits chars and spaces  /^([a-zA-Z\d\s]+)+$/  For this regular expression, empty string will fail







Sample bashrc file

export CVS_RSH=ssh
export CVSROOT=:ext:cvs.somedomain.com:/var/cvs/cvsroot/php
export PATH=/homes/lshen/bin/:/usr/local/lib/jre1.6.0_22/bin/:/usr/bin/:/usr/bin/php/bin/:$PATH
export CLASSPATH=/usr/local/lib/jdk1.6.0_22/bin/:.
export JAVA_HOME=/usr/local/lib/jdk1.6.0_22/bin/
export EDITOR=/usr/bin/vim
export LC_CTYPE=en_US.UTF-8

xset b off

alias ls='ls --color=tty'
alias phpcs='phpcs --standard=Zend';
alias vi='vim'
alias lpr='lpr -P Ricoh'

Some useful command (Mysql Vi etc) Memo

My SQL

Grant a user to a database
mysql>grant all on db_name.* to 'db_username'@'localhost' identified by 'db_userpasswd'
dump a database to a sql file
mysqldump -u root -p --opt leo_db>dump.sql

vi

Auto replace string in vi
:%s/pattern_search_for/new_string_to_be_used/gc

Open and create compressed files

Open files
tar zxvf filename.tar.gz
unzip filename.zip
tar -xvf my.tar
bunzip2 studybuzz.bz2
bzip2 -d studybuzz.bz2
tar jxvf studybuzz.tar.bz2
unrar e test.rar

Create a zip file without parent directory

/test/test.txt
/test/test2.txt
cd test
zip -r -j my.zip *
Create files
zip -r filename.zip filedir
tar -cvf my.tar filedir
Print Env Variables
printenv
curl
curl -H "x-api-key:1234" http://myapi.com/user/1

#The -v option activates verbose mode, revealing detailed communication logs between the client and server
curl -v -H "x-api-key:1234" http://myapi.com/user/1

#curl does not follow HTTP redirects by default. Use the -L, --location option to tell it to do that
curl -L -H "x-api-key:1234" http://myapi.com/user/1