Friday, August 28, 2015

Adobe Flash Player Settings Manager

Adobe Flash Player Settings Manager:

http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager09.html

This works across different browsers.

Thursday, August 27, 2015

Share a folder between windows and linux

To share a linux folder with windows, just use Samba.

To share a windows folder with linux, you can use cifs-utils. Details are below:

    1) Create windows shared folder [2] on windows machine (say MachineX): C:\Shared\
       - now can access \\MachineX\Shared\ on other machines on the same domain.
    2) Download/Install cifs-utils on linux machine:
       - download from [3].
       - unzip and install:
         bzip2 -d cifs-utils-6.4.tar.bz2
         tar xvf cifs-utils-6.4.tar
         cd cifs-utils-6.4
         ./configure --prefix=/usr \
            --disable-pam \
            --disable-systemd
         make
         sudo make install
       - finally, the command is available on linux by: sudo /sbin/mount.cifs
    3) Mount the shared folder on linux:
       - mount:
         cd /mnt
         sudo mkdir MachineX_Shared
         sudo /sbin/mount.cifs  //[MachineX IP address]/Shared  /mnt/MachineX_Shared -o user=[username]
       - now can access the folder and write to it.

References:

[1] http://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/
[2] http://lifehacker.com/288033/mount-a-windows-shared-folder-in-linux
[3] http://www.linuxfromscratch.org/blfs/view/svn/basicnet/cifsutils.html


Sunday, August 23, 2015

Use WordPress as CMS

WordPress is a popular blogging software. It has a lot of nice-looking themes. It will be very nice if it can be used as the framework of a website.

For this purpose, one should be able to create custom roles (user groups), members of such roles may or may not be able to post blogs, but can access custom pages once log in. Several things are crucial:

1) create custom role(s).
2) check if a user is logged in, and access user profile such as ID, login name, user name, email, user type. Based on this, one can add custom database tables and build whatever function that is desired.
3) make use of WordPress theme in custom page.

A study on these requirements proves fruitful. Over the weekend, I was able to build a member page for 4 WordPress themes. It's easy to extend to more themes.

The files are prepared and will be uploaded to github. See:

https://github.com/chenx/WordPress_Extension


Summary:
  • Shows how to check if a user is logged in, and retrieval user information.
  • Shows how to include header/footer of current theme.
  • To add custom links, go to Appearance -> Menus -> Custom Links
  • To allow user register, see [3] below.
    It seems Wordpress allows each user to have one role only. That's less flexible than .NET membership, which allows each user to have any roles.
  • To change default user registeration email, see [4].
  • To allow manage user roles, use the Members plugin [5].
  • To disable comments/discussion on a per-page basis:
    On Edit Page, click Screen Options and check the Discussion box. Then in Discussion section, uncheck "Allow comments".
  • To add a forum, see .
  • Note: installed themes are in wp-content/themes/
  • Note: to imitate other page's layout, see theme's page.php.
  • Note: to customize page title, see wp-includes/post-template.php function get_the_title().
References:
  1. http://codex.wordpress.org/Function_Reference/wp_get_current_user
  2. https://web-design-weekly.com/snippets/load-a-different-header-in-wordpress/
  3. http://www.wpbeginner.com/beginners-guide/how-to-allow-user-registration-on-your-wordpress-site/
  4. https://wordpress.org/plugins/welcome-email-editor/
  5. https://wordpress.org/plugins/members/
  6. wordpress - redirect to target page after log in 

Thursday, August 20, 2015

HTML 5移动开发从入门到精通

HTML 5移动开发从入门到精通

This introduces some HTML5 elements.

Javascript elements:

1. selectors api
2. JSON parse/stringify
3. Hashchage event
4. async.defer for script
5. progress for ajax
6. DeviceOrientation
7. touch events

Html5 Tag elements:

1. progress: <progress max="100" value="30"></progress>
2. mark (highlight text): <mark>This is a mark</mark>
3. address (italic format)
4. Colgoup col
5. keygen
6. fieldset/legend
7. ol.li (reversed, start, type)
8. q (quotation)
9. contenteditable div

Monday, August 17, 2015

Image hover effects & Customize css for different devices

I. Simple but effective and look good:

[1] http://designshack.net/articles/css/joshuajohnson-2/
[2] http://designshack.net/tutorialexamples/imagehovers/index.html


II. Customize css for different devices. Example:

/* >= 768. Desktop. */
@media only screen and (min-width:768px){
    #slide_img1, #slide_img2, #slide_img3
    {
        display: block; max-width: 100%; height:auto;
    }
}

/* < 768px. Mobile. */
@media only screen and (max-width:768px){
    #slide_img1, #slide_img2, #slide_img3
    {
        display: block; max-width: 800px; height: auto;
    }
}


[3] http://stackoverflow.com/questions/22839792/bootstrap-3-custom-css-class-depending-of-devices

Normalize.css, an alternative to CSS resets

From [1]:

Normalize.css is a small CSS file that provides better cross-browser consistency in the default styling of HTML elements. It’s a modern, HTML5-ready, alternative to the traditional CSS reset.

From [7]:

A CSS Reset (or “Reset CSS”) is a short, often compressed (minified) set of CSS rules that resets the styling of all HTML elements to a consistent baseline.

In case you didn’t know, every browser has its own default ‘user agent’ stylesheet, that it uses to make unstyled websites appear more legible. For example, most browsers by default make links blue and visited links purple, give tables a certain amount of border and padding, apply variable font-sizes to H1, H2, H3 etc. and a certain amount of padding to almost everything. Ever wondered why Submit buttons look different in every browser?

Obviously this creates a certain amount of headaches for CSS authors, who can’t work out how to make their websites look the same in every browser. (NB: article coming soon about why this is a false notion!)

Using a CSS Reset, CSS authors can force every browser to have all its styles reset to null, thus avoiding cross-browser differences as much as possible.


[1] About normalize.css
[2] https://github.com/necolas/normalize.css/
[3] https://necolas.github.io/normalize.css/
[4] Applying Normalize.css Browser Reset CSS (video)

[5] CSS Tools: Reset CSS
[6] http://cssreset.com 2015’s most popular CSS Reset scripts, all in one place.
[7] What Is A CSS Reset?
[8] http://stackoverflow.com/questions/6887336/what-is-the-difference-between-normalize-css-and-reset-css

Monday, August 10, 2015

Paging with SQL

In MySQL, this can be easily done with:

SELECT * FROM tbl limit [start], [end]

In MSSQL, this can be done as in [1] :

1.Paging rows with Limit (MSSQL 2005 or later)

--VIEWING THE PAGE "2" WITH 5 ROWS
DECLARE @PageNumber AS INT, @RowspPage AS INT
SET @PageNumber = 2
SET @RowspPage = 5 SELECT * FROM (
             SELECT ROW_NUMBER() OVER(ORDER BY ID_EXAMPLE) AS NUMBER,
                    ID_EXAMPLE, NM_EXAMPLE, DT_CREATE FROM TB_EXAMPLE
               ) AS TBL
WHERE NUMBER BETWEEN ((@PageNumber - 1) * @RowspPage + 1) AND (@PageNumber * @RowspPage)
ORDER BY ID_EXAMPLE


2. Paging in SQL Server 2012, with FETCH/OFFSET

--CREATING A PAGING WITH OFFSET and FETCH clauses IN "SQL SERVER 2012"
DECLARE @PageNumber AS INT, @RowspPage AS INT
SET @PageNumber = 2
SET @RowspPage = 10 

SELECT ID_EXAMPLE, NM_EXAMPLE, DT_CREATE
FROM TB_EXAMPLE
ORDER BY ID_EXAMPLE
OFFSET ((@PageNumber - 1) * @RowspPage) ROWS
FETCH NEXT @RowspPage ROWS ONLY;


For performance, 2 is better than 1. Both are better than getting all rows and use specific range.

[1] http://social.technet.microsoft.com/wiki/contents/articles/23811.paging-a-query-with-sql-server.aspx


Monday, August 3, 2015

A little Software Engineering - Collect LOC metrics

To manage one's project, one thing is to collect metrics.

To count line of code in all project files, the CLOC [1] command line utility is easy to use.

For example, you can setup a batch file on windows for this purpose. On windows, you can put the cloc.exe executable in C:\windows\ so it's available anywhere in DOS.  Next, in general you need 2 files: 1) a exclude-list file, 2) a batch file to call the CLOC.exe utility.


-- cloc_exclude_list.txt --

c:\inetpub\wwwroot\my_site\backup
c:\inetpub\wwwroot\my_site\images

(Note you cannot put a back slash after the folder name.)


-- run_cloc.bat --

@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
echo Today is: %mydate%
echo.

cloc c:\inetpub\wwwroot\my_site --exclude-list-file=cloc_exclude_list.txt -out=cloc_log\short_%mydate%.txt
cloc c:\inetpub\wwwroot\my_site --exclude-list-file=cloc_exclude_list.txt -out=cloc_log\short_%mydate%.csv --csv

cloc c:\inetpub\wwwroot\my_site --exclude-list-file=cloc_exclude_list.txt --by-file -out=cloc_log\long_%mydate%.txt
cloc c:\inetpub\wwwroot\my_site --exclude-list-file=cloc_exclude_list.txt --by-file -out=cloc_log\long_%mydate%.csv --csv

(This will create 4 output files, for the combination of full/short list and txt/csv format,
prefixed by today's date. So you could setup a schedule task for this to run automatically everyday.)


[1] http://sourceforge.net/projects/cloc/
[2] http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us


Blog Archive

Followers