Search This Blog

2017/12/04

Vagrant:不要なboxを削除

boxを確認する
vagrant box list
vagrant global-status

例:
centos/7 (virtualbox, 1705.01)
centos/7 (virtualbox, 1707.01)
centos/7 (virtualbox, 1710.01)

1705.01のバージョンを削除する
vagrant box remove centos/7 --box-version 1705.01

強制的に、下記のオプションを付ける
-f / --force

全部削除
vagrant box isremove centos/7 --all

2017/11/27

Change local URL | Vagrant plugins: Update host

Access local site vi website address like xxx.xx, not ip.
ローカルのURLをカスタマイズする
Use vagrant plugin: vagrant-hostsupdater

vagrant plugin install vagrant-hostsupdater

2017/11/26

REPT函数、10种可视化图表!

使用REPT函数来做单元格里的条形图,也可以叫数据条。

1、REPT函数原理介绍
REPT 应是单词 repeat(重复)的缩写,它对指定的字符重复指定的次数,返回一个字符串。例,公式:=REPT("★",5) 结果:★★★★★

2、单元格里的数据条
如果:=REPT("|",50)
现在得到50条稀疏的小竖线。如果给单元格设置playbill 字体,就得到了无缝隙的单元格里的数据条!
公式:=REPT("|",C6/MAX($C$6:$C$10)*200)
即根据指标数值大小按比例折算重复的次数,最大的数值重复200次(可自定)。然后设置为playbill 字体,8磅,灰色。
把这个方法简记为【REPT("|",n)+playbill】,方便记忆和运用。

3、倾斜字体的数据条
设置字体为倾斜,刀片一样的数据条,锋利,很有个性!

4、使用斜杠的数据条
不使用小竖线,而使用斜杠符号 / 。

5、单元格里的柱形图
单元格格式里设置文本的方向为 90 度

6、单元格里的漏斗图
单元格文本除了字体设置,还可以设置对齐方向。把这些单元格里的文本设置居中对齐,就得到了一个漏斗图。

7、单元格里的蝴蝶图
蝴蝶图是一种左右对比的条形图,使用 REPT 函数分别作出两列数据条,然后分别设置右对齐和左对齐。
例:
左侧:=C6&" " & REPT("|",C6/MAX($C$6:$D$13)*50),右对齐
右侧:=REPT("|",D6/MAX($C$6:$D$13)*50) & " "&D6,左对齐

8、单元格里的甘特图
项目管理里的甘特图,也可以用 REPT("|",n) 方法来做,因为它也是单元格里的条形图。
公式:=REPT(" ",(C6-MIN($C$6:$C$14))*$H$7) & REPT("|",1.5*(D6-C6+1)*$H$7)
前半截重复空格占位,重复次数为该行的开始日期-整个项目的最小开始日期。后半截重复小竖线绘制甘特图,重复次数为工期数*1.5。
为什么要乘1.5?因为在Arial 字体、8磅大小下,一个空格的宽度(大约)是小竖线“|”的1.5倍,因此我们重复小竖线的时候就放大1.5倍。
这里H7是一个调节系数,我用来控制进度图的长度合适。

9、单元格里的瀑布图
瀑布图是麦肯锡公司发明,用来反映从一个数据到另一个数据的变化过程。
REPT 出这样的瀑布图,要准备1列辅助的占位数据。公式:
=REPT(" ",G6*$C$19)&REPT("|",ABS(C6)*$C$19*1.5)
其中,小竖线的重复次数也要放大1.5倍,也要设置 Arial 字体、8磅大小。
由于指标数量级可能很大也可能很小,需要使用一个系数来折算出合理的重复次数,这里是C19。

10、单元格里的圆点百分比图

公式:=REPT("●",B6*100)
设置单元格自动换行,调整列宽,使每行刚好能容纳10个黑点。

2017/10/31

Set up laravel Homestead by vagrant

Prepare installation: VirtualBox 5.1; Vagrant; composer

$ vagrant box add laravel/homestead

$ cd ~

$ cd Homestead
$ git checkout v6.5.0

Init homestead
// Mac / Linux...
$ bash init.sh
// Windows...
$ init.bat

Modify file "Homestead.yaml"
folders:
    - map: /the/path/in/pc
      to: /home/vagrant/code

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
$ eval "$(ssh-agent -s)"
$ ssh-add -k ~/.ssh/id_rsa

$ cd /the/path/in/pc
$ composer create-project laravel/laravel projectName

Init and set up vagrant
$ vagrant up

Stop vagrant
$ vagrant halt

Connect to vagrant env
$ vagrant ssh

Restart vagrant
$ vagrant reload

2017/10/25

Install pip by python

CentOS:
yum -y install wget
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

Mac: Restart MySQL by command line


Apache:
sudo rm /Applications/XAMPP/xamppfiles/bin/mysql.server
sudo ln -s /Applications/XAMPP/xamppfiles/share/mysql/mysql.server /Applications/XAMPP/xamppfiles/bin/mysql.server 

2017/10/24

PHP: set timezone and date format

Use date_timezone_set to set 2017/10/24 00:00:00 in timezone Asia/Tokyo.
$date = '2017-10-24';
$timezone = 'Asia/Tokyo';
$tokyoTime = date_timezone_set(new DateTime($date), new DateTimeZone($timezone));
echo $tokyoTime;

If $date is null, $tokyoTime will be the time of right now in Tokyo.
Set $tokyoTime to null when $date is null.
$tokyoTime = empty($date) ? '' : date_timezone_set(new DateTime($date), new DateTimeZone($timezone));

Set format
$tokyoTime = empty($date) ? '' : date_format(date_timezone_set(new DateTime($date), new DateTimeZone($timezone)), 'Ymd H:i');

2017/10/12

Escape html <=> chr list

&#32; (Space) &#33; !
&#34; " &#35; #
&#36; $ &#37; %
&#38; & &#39; '
&#40; ( &#41; )
&#42; * &#43; +
&#44; , &#45; -
&#46; . &#47; /
&#48; 0 &#49;~&#57; 1~9
&#58; : &#59; ;
&#60; < &#61; =
&#62; > &#63; ?
&#64; @ &#65;~&#90; A~Z
&#91; [ &#92; \
&#93; ] &#94; ^
&#95; _ &#96; `
&#97;~&#122; a~z &#123; {
&#124; | &#125; }
&#126; ~ &#127; DEL
全角スペース:&#x3000;

2017/09/28

Ajax Sample

2017/09/16

Vagrant error: the "vboxsf" file system is not available

Solution:
Install plugin vagrant-vbguest (https://github.com/dotless-de/vagrant-vbguest)

Command line:
vagrant plugin install vagrant-vbguest

Other Post:
Vagrant: Update host 

2017/09/06

Unzip .tar .gz file

.tar file: tar zxvf fileName.tar
.gz file: gunzip fileName.gz

zip a .gz file:gzip targetFile

2017/09/04

ODBCデータの漢字が化ける解決策

CSEなどを使ってMySqlへ接続する際、データに漢字を化ける件

WINDOWのスタート>control panel(設定)>検索欄に「ODBCデータベースのセットアップ」
対象する接続先の設定を編集>詳細>文字コードを選択(SIIJ / UTF8)>確定する

尚、CSEが32ビットのバーションの場合、ODBCも32ビットしなければなりません。
ODBCが64ビットの場合、32ビットのCSEがMySqlを使いません。

2017/08/26

删除驱动精灵的dgbased服务组件

卸载驱动精灵后,软件并没有完全删除干净,留下了dgbased服务组件。

删除方法:
开始 》 运行 》 输入"regedit"并确定 》 找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services下的dgbased 》 右键点击选择删除

另,360的为同文件夹HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services下的scan

Delete 360 security software service from pc

彻底删除“360 杀毒全盘扫描辅助服务”服务

When you uninstall 360 security software, there are something need to delete manually. Like full scan service.

360 security software will register full scan under name of microsoft Co, not 360 XXX.

How to check?
start > run > input "msconfig" and enter > tab [service]
Then you may find it as "360 杀毒全盘扫描辅助服务"

How to delete?
start > run > input "regedit" and enter > navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services > find it and right click to delete
It may be name as "scan". HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\scan

how to add/remove iis7 in win7

1.
start > control panel > program > window service
[or]
ctrl+r  > input "cmd" and enter > input "control panel" and enter > program > window service

2.
check/uncheck intnet information service

3.
reboot pc and done.

2017/08/24

Forbid file but css/js/img etc. by htaccess

By FILE
<Files ~ "^.*">   # to all files/すべでのファイルに対する
  Deny from all    # forbid access/すべで禁止
</Files>

<Files ~ "^index\.php|css|js|.*\.png|.*\.jpg|.*\.gif">  # the kind of files/ファイルの種類
  Allow from all   # allow access/全部許可する
# Allow from [ip]  # allow from special ip or other/特定なIPなどからのみ許可
</Files>

In this way, you can still use include/fopen to get the css/js/png in php.

2017/08/05

vue.js: templateのclassを変数をつける

loopでarrayを出力する際、vueのclassをデータより変わりたい場合がある。
下記のようにarrayのデータをclassにつける。(':' + つけたいattr名) = "設定したい値"

array = [[value => value1],[value => value2]]

<Template>
<div v-for:"data in array">
<a href="" :class="'link' + data.value">
</div>
</Template>

実際出力の内容:
<div>
<a href="" class="link value1">
</div>
<div>
<a href="" class="link value2">
</div>
...

そのた:<img :src="データ値">

2017/08/01

curl command line

curl https://randinblogger.blogspot.com/
curl --head --header "User-Agent: agentName" https://randinblogger.blogspot.com/

2017/07/28

htaccess blacklist

By user agent
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(<|>|'|%0A|%0D|%27|%3C|%3E|).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(HTTrack|clshttp|archiver|loader|email|nikto|miner|python).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(winhttp|libwww\-perl|curl|wget|harvest|scan|grab|extract).* [NC]
RewriteRule ^(.*)$ - [F,L]

By query string
RewriteEngine On
RewriteCond %{QUERY_STRING} ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(\.|\*|;|<|>|'|"|\)|%0A|%0D|%22|%27|%3C|%3E|).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(md5|benchmark|union|select|insert|cast|set|declare|drop|update).* [NC]
RewriteRule ^(.*)$ - [F,L]

By request url
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*(,|;|:|<|>|">|"<|\.\.\.).* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*(\=|\@|\[|\]|\^|\`|\{|\}|\~).* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*(\'|%0A|%0D|%27|%3C|%3E|).* [NC]
RewriteRule ^(.*)$ - [F,L]

By cookie
RewriteEngine On
RewriteCond %{HTTP_COOKIE} ^.*(<|>|'|%0A|%0D|%27|%3C|%3E|).* [NC]
RewriteRule ^(.*)$ - [F,L]

By referer
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^(.*)(<|>|'|%0A|%0D|%27|%3C|%3E|).* [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-|.)?adult(-|.).*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-|.)?poker(-|.).*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-|.)?drugs(-|.).*$ [NC]
RewriteRule ^(.*)$ - [F,L]

By request
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*(\\r|\\n|%0A|%0D).* [NC]
RewriteRule ^(.*)$ - [F,L]

By method
RewriteEngine On
ServerSignature Off
Options +FollowSymLinks
RewriteCond %{REQUEST_METHOD} ^(delete|head|trace|track) [NC]
RewriteRule ^(.*)$ - [F,L]

2017/07/06

Wordpress: bbp

[bbp-forum-index] – 显示版面索引/归档
[bbp-single-forum id=$forum_id] – 显示单个论坛主题
主题
[bbp-topic-index] – 显示主题索引/归档
[bbp-topic-form] – 显示新主题表单
[bbp-single-topic id=$topic_id] – 显示单个主题
主题标签
[bbp-topic-tags] – 显示所有主题标签的标签云
[bbp-single-topic-tag] – 显示指定标签内的主题
回复
[bbp-reply-form] – 显示主题回复表单
查看
[bbp-single-view] – 显示指定查看条件的主题
账户
[bbp-login] – 显示登录页面
[bbp-register] – 显示注册页面
[bbp-lost-pass] – 显示密码找回页面

2017/06/21

Git command line memo

VirtualBox: Can't support 64bits OS

Try using VirtualBox to setup a 64bits Linux server, but there's an error said it can't support 64bits OS but 32bits. In VirtualBox system settings, only 32bits OSs are availabled.

Solution: Enable the virtualization technology in motherboard BIOS.

Example: hp notebook
Before boot OS > Key[Esc] > BIOS setup > Advanced > check virtualization.

VirtualBox quick key

Default [host key] is Right Ctrl.

Display
Full screen on/off: [host key] + F
Scale screen on/off: [host key] + C

Menu
Call menu: [host key] + home

2017/06/16

IE: js only working in debug mode

I happened to an issue that js function is working in Chrome, Firefox and IE's debug mode. ONLY IN DEBUG MODE.

In stackoverflow, most answer are "Don't use 'console.log'". Because console object exists in scope only in debug mode after IE9.
Or use codes likes below to avoid console's problem.
if(!('console' in window)){
    window.console ={};
    window.console.log=function(string){
        return string;
    };
}

But it's not working on my issue, and try to catch the error is non-help at all.
window.onerror = function(msg, url, line) {
    alert('Error message: '+msg+'\nURL: '+url+'\nLine Number: '+line);
    return true;
}

Maybe it is cached that set to true somewhere, so I tried to set it to false.
$.ajax({
    type: "GET",
    url: "/" + filename,
    dataType: "xml",
    cache: false,
    success: function(xml){ /* code */ }
});

Success. Issue closed.

2017/06/13

Setting NLS_LANG Oracle in Non-English Environment

Develop in No-English Environment, setting the NLS_LANG environment variable for Oracle databases.

1. Determine the NLS_LANG
SELECT * FROM V$NLS_PARAMETERS
The NLS_LANG will be in format [NLS_LANGUAGE]_[NLS_TERRITORY].[NLS_CHARACTERSET]

2. For Windows
Control Panel > System: Advanced tab: Environment Variables
New in System variable section. Variable Name: NLS_LANG.

3. For UNIX
SETENV NLS_LANG [NLS_LANG]
If data is 7-bit or 8-bit ASCII it will be NLS_LANG: [NLS_LANGUAGE]_[NLS_TERRITORY].WE8ISO8859P1

4. Reboot machine.

[NLS_LANGUAGE]_[NLS_TERRITORY].[NLS_CHARACTERSET]:
American_America.UTF8
Japanese_Japan.JA16SJISTILDE

2017/06/12

Create and download file by JavaScript

Code:
<script>
function download(fileName, content){
    var file = document.createElement('a');
    file.download = fileName;
    file.href = 'data:application/octet-stream,'+encodeURIComponent(content);
    file.click();
}
</script>
Html:
<button onclick="download('test.txt','test text.');"/>

2017/06/02

VBA: Unhide all sheets in Excel

Code:
Sub UnhideAllSheets()
    Dim ws as Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        ws.Visible = xlSheetVisible
    Next ws
End Sub

2017/05/25

Forbid right click call menu and copy

By html:
<body oncontextmenu='return false;' oncopy='return false;'>
oncontextmenu='return false;' // Return false to forbid right click menu.
oncopy='return false;' // Return false to forbid copy context.

By JavaScript:
document.addEventListener('contextmenu', event => event.preventDefault());

2017/03/31

Show hidden files in WinSCP

Quick key: Ctrl+Alt+H
Preferences -> Panels -> Show hidden files

Then . file can be viewed. Some file like .htaccess will visible.

2017/03/29

Wordpress struction構造

|-- 404.php (404エラーページ)
|-- archive-custom_type.php (カスタム投稿一覧ページ)
|-- archive.php (ブログ一覧ページ)
|-- comments.php (コメント)
|-- editor-style.css (エディター用)
|-- favicon.ico (ファビコン)
|-- favicon.png(ファビコン)
|-- footer.php (フッター)
|-- functions.php (テーマ機能)
|-- header.php (ヘッダー)
|-- index.php (表紙)
|-- library (CSS/JS関連ファイルをまとめたフォルダ)
|   |-- css
|   |   |-- admin.css
|   |   |-- editor-style.css
|   |   |-- ie.css
|   |   |-- login.css
|   |   |-- style.css
|-- page-custom.php (カスタム固定ページ)
|-- page.php (固定ページ)
|-- post-formats (投稿フォーマット関連ファイルをまとめたフォルダ)
|-- screenshot.png (スクリーンショット)
|-- search.php (検索)
|-- sidebar.php (サイドバー)
|-- single-custom_type.php (カスタム投稿シングルページ)
|-- single.php (投稿シングルページ)
|-- style.css (スタイルシート)
|-- taxonomy-custom_cat.php (カスタム投稿カテゴリーページ)

2017/03/24

Get top 100 rows in Oracle/SQL Sever/MySQL

In Oracle:
SELECT * FROM (
    SELECT *
    FROM table
) WHERE ROWNUM < 101
In MySQL:
SELECT *
FROM
    table
LIMIT 100
In SQL Sever/ MS Access:
SELECT TOP 100
    *
FROM
    table

2017/03/21

Useful command line in window

Open cmd window by keyboard: Win+R, then input cmd and enter

System set: msconfig
Open Control Panel: Control Panel

Go to folder: CD pathToFolder
List all folders and files: DIR
List environment variables: SET [name=[value]]

New create a folder: mkdir folderName
Remove empty folder: rmdir folderName
Remove not empty folder: rmdir /s folderName

Open an application: start [appName]
For example: start firefox

Reboot: shutdown -r [seconds]
Shut down: shutdown -s [seconds]
Log off: shutdown -l [seconds]
Shutdown menu: shutdown -i
Abort shutdown command: shutdown -a
Hibernate(sleep): shutdown -h

IP: ipconfig /?

break: Ctrl+C

2017/03/19

Check environment variables by command line

Windows syntax:
SET [variable name=[variable value]]

List all: SET
Output help: SET /?
Output variable start with "P": SET P
Output variable by name: SET Home

2017/03/13

Quick ways to open/execute .jar file

Open and view the source
Change the .jar to .zip, click yes to the warning message, then you can open it as a zip file.
Execute by command line: java -jar fileName.jar
Need runtime environment

Create a bat file. New a txt file and paste code:
@echo OFF
cd jarFilePath
java -jar fileName.jar
Then change .txt to .bat, double-click it.

2017/03/08

Upload files by drag&drop

html part:
<div style="display: none;">
    <form action="upload.php" method="post" enctype="multipart/form-data" id="form">
        <input type="file" name="file" id="file">
    </form>
</div>
<div id="dropArea" style="height:25px">drop image here</div>
JS:
$("#dropArea").on("drop dragover", function(e) {
    var fm = document.getElementById('form');
    var fd = new FormData(fm);
    imageUpload(fd);
});

function imageUpload(fd) {
    $.ajax({
        async: true,
        type: 'post',
        url: 'upload.php',
        data: fd,
        contentType: false,
        processData: false,
        timeout: 120000,
        success: function(data) {
        },
        error: function(R, S, E){}
    });
}

VBA: Create folder if not existed

Code:
' check if folder exist
If Dir("folder path", vbDirectory) = "" Then
' if not exist, create
MkDir "folder path"
End If

2017/03/04

Google提供的机器人验证

Google所提供的机器人验证服务。

导入后,可实现图片验证等。
https://www.google.com/recaptcha/intro/index.html

题外话:图片验证或许可能是Google的人工智能的一部分。

2017/03/03

Gmail邮箱邮件限制

每天最多发送500封邮件。
每封邮件最多可有500名收件人。
邮件内容超过102kb时会被剪切。网页浏览时可以看到“查看全部内容”的链接,但app下目前还没有。

解决方案
建立一个Google group,用发送邮件到group邮件地址替代发送到每个用户。这样可以发送给更多的用户。

iPhone Gmail App's 102kb e-mail size limit

Open an email in Gmail app with your iPhone, if the email size is over 102kb, you will find the mail is been clipped.

If you use web gmail, you can find a link named "View entire message".

By the way, you can have attachments be sent by email under 25M.

To avoid this issue:
Only send relevant information, use links to additional information.
Minimize your code, delete useless css style.
Preview before send.

2017/03/02

結合テスト

目的
1、外部/内部インタフェースの完全性。結合・構造自体に問題がない。
2、機能の妥当性
3、データの内容
4、性能
対象物の内部構造に焦点。

※結合テストは設計・構造の妥当性を確認する為に、段階的に結合し確認することで問題を明確化
※対象は結合する対象によって変化
※一般的にはインタフェース、機能、データ、性能に着目
※開発中の為日々の変化に対応する必要あり

テスト方法
1、機能単位にプログラムを結合して対象とする「ブラックボックス・テスト」
2、サブシステム単位に機能をまとめでテスト、動作確認テスト

テストする際注意点
  • 連携
  • データの限界値
  • バッチの性能(PL/SQL join)
  • 負荷テスト
  • データ:本番と同じ動作環境で

2017/02/25

Share blogger's blogs/pages to Tumblr/Line/Linkedin

Blogger already has some share buttons like "google+", "twitter"... and maybe you want to share to Tumblr or Line.

To add Tumblr or Line share button, you need to edit blogger's template.

In template | edit html
Search "<b:includable id='shareButtons' var='post'>"

Then add the code inside this b:includable
Tumblr
<a class="tumblr-share-button" href="https://www.tumblr.com/share"></a>
Add the script before </body>
<script id="tumblr-js" async src="https://assets.tumblr.com/share-button.js"></script>
show as:

Line
<a expr:href='&quot;http://line.naver.jp/R/msg/text/?&quot; + data:post.title + &quot;%0D%0A&quot; + data:post.url + &quot;&quot;'> <img alt='LINEで送る' height='20px' src='https://media.line.me/img/button/ja/20x20.png' width='20px'/></a>
show as: LINEで送る

Linkedin
<script data-counter='right' type='IN/Share'>var data-url = &#39;<data:post.sharePostUrl/>&#39;;</script>
Add the script before </body>
<script src='//platform.linkedin.com/in.js' type='text/javascript'> lang: en_US</script>

2017/02/24

MySQL event scheduler

Attention: event_scheduler is supported after 5.1

Check if event_scheduler is on, execute:
SHOW VARIABLES LIKE 'event_scheduler';
To set event_scheduler on:
SET GLOBAL event_scheduler = ON;
or SET @@global.event_scheduler = ON;
or SET GLOBAL event_scheduler = 1;
or SET @@global.event_scheduler = 1;
To turn off is
SET GLOBAL event_scheduler = OFF;
or SET @@global.event_scheduler = OFF;
or SET GLOBAL event_scheduler = 0;
or SET @@global.event_scheduler = 0;

To create event:

CREATE EVENT [IF NOT EXISTS] event_name
  ON SCHEDULE schedule
  [ON COMPLETION [NOT] PRESERVE]
  [ENABLE | DISABLE]
  [COMMENT 'comment']
  DO sql_statement;
param
schedule:
  AT TIMESTAMP [+ INTERVAL INTERVAL]
                              | EVERY INTERVAL [STARTS TIMESTAMP] [ENDS TIMESTAMP]
INTERVAL:
  quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
                   WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
                   DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

2017/02/21

Customize your blogger: ads and page type

Customize your ads' position.
<!-- show Ad if you set ads to show in your blogger -->
<b:if cond='data:post.includeAd'>
<div class='inline-ad'>
<data:adCode/>
</div>
</b:if>

<!-- show only when it is static page or item(post page) -->
<b:if cond='data:blog.pageType in {&quot;static_page&quot;,&quot;item&quot;}'>
<!-- your code -->
</b:if>

<!-- show only when it is index page -->
<b:if cond='data:blog.pageType == &quot;index&quot;'>
<!-- your code -->
</b:if>

<!-- show only when device is mobile -->
<b:if cond='data:blog.isMobile'>
<!-- your code -->
</b:if>

2017/02/15

Drag & drop file code sample

Make a div for dropping.
$("#id").on("drop dragover", function(e) {
 var fm = document.getElementById('form');
 var fd = new FormData(fm);
 e.preventDefault();
 if (e.type === "drop") {
  var files = e.originalEvent.dataTransfer.files;
  console.log(files);
  if (files.length > 0) {
   fd.append("file", files[0]);
   // do something
  }
 }
 return false;
});
html part:
<form action="upload.php" enctype="multipart/form-data" id="form" method="post">
  <input name="mode" type="hidden" value="upload" />
  <input id="formFile" name="file" type="file" />
</form>

2017/02/09

Create array in array

1:
var myArray = [[]];
2:
var myArray1 = new Array();
myArray.push(new Array());
myArray[i]= myArray1;
3:
var myArray1 = new Array({name: "name", value: "value"});
myArray.push({name: "name", value: "value"});

Set back function with toolbar

Set:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Action:
onBackPressed();

2017/02/07

Insert two rows into db with one sql

MySQl
insert into table(columns...)values(value1...),(value2...),(value3...)
add more rows by ,(value...)
Oracle
insert all
into table(columns...)values(value1...)
into table(columns...)values(value2...)
select 1 from dual

2017/01/26

PHP upload file to server

<form method="post" enctype="multipart/from-data">
<input type="file" name="upload_file" >
</form>
Attr:
$_FILES['upload_file']
$_FILES['upload_file']['name']
$_FILES['upload_file']['tmp_name']
$_FILES['upload_file']['type']
$_FILES['upload_file']['size']
Check is file uploaded success:
if(!is_uploaded_file($_FILES['upload_file']['tmp_name'])) {
    unlink($_FILES['upload_file']['tmp_name']); // error
} else {
    // continue do something.
}
Check if file too big:
$maxsize = 10240;
if($_FILES['upload_file']['size'] > $maxsize) {
    unlink($_FILES['upload_file']['tmp_name']); // error
} else {
    // continue do something.
}
Check type:
if($_FILES['upload_file']['type'] != "image/gif") 
Move file:
move_uploaded_file($_FILES['upload_file']['tmp_name'], "path/" . $_FILES['upload_file']['name']);
Full sample(upload by one button):

2017/01/25

Integrating Google Sign-In error: status code 12501

When I try to integrating Google Sign-in activity into my app, happened to a error:
statusCode=unknown status code: 12501, resolution=null
It's caused by the wrong Server Client ID which saved in @values/strings.xml.
<string name="server_client_id">xxx-xxx.com</string>
It's web client id,not the android client id.

2017/01/19

Read file by php which forbidden by .htaccess

Folder "file" is forbidden to access by .htaccess file as below:
 Options -Indexes 
 # Controls who can get stuff from this server. 
 Order Deny,Allow 
 Deny from all 
 #Allow from localhost

Try to get content from /file/1.html which is forbidden to access directly through php.
Code:
echo "Read 1.html file in folder 'file':";
$file_handle = fopen($_SERVER['DOCUMENT_ROOT'] . "/file/1.html", "r"); 
//$file_handle = fopen("http://www.randinblogger.blogspot.com/", "r");
while (!feof($file_handle)) {
 $line = fgets($file_handle);
 echo $line;
}
fclose($file_handle);

2017/01/16

Android showAsAction: always doesn't work

If you use Android Support, it will no work as below.

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:id="@+id/action_1"
 android:icon="@drawable/ic_action_1"
 android:showAsAction="ifRoom"
 android:title="@string/menu_1"></item>
</menu>

Solution:

Add xmlns:app="http://schemas.android.com/apk/res-auto", and use app:showAsAction instead of android:showAsAction

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" >
 <item android:id="@+id/action_1"
  android:icon="@drawable/ic_action_1"
  app:showAsAction="ifRoom"
  android:title="@string/menu_undo"></item>
</menu>

2017/01/13

Dynamic SQL in Oracle

Had a case which need to use daynamic SQL and execute immediate statement. Share and memo a solution.

Customer's Needs:
There're two tables, A and B.
1. Update some columns in table B
2. The name of columns which will be updated are saved in table A(colname)
3. The columns' new value are saved in table A(colvalue)
4. Before get data from table A, we don't know which column will be updated.

Method:
1. Get data from table A and put in an cursor.
2. Create a dynamic SQL
3. Execute dynamic SQL

Code:

2017/01/11

Chrome page refresh: normal/hard/hard with cache cleared up

Quick keys
Normal: Ctrl+R
Hard: Ctrl+Shift+R

Hold left click to refresh button or right click refresh button to call out menu, then left click the option.

Detection: if device is iPad/iPhone or Android or PC

Use navigator to get information of device.

Code:
<script>
var _device = navigator.userAgent;
var isMobile = _device.indexOf("Mobile") > 0;
var isAndroid = _device.indexOf("Android") > 0;
var isPad = _device.indexOf("iPad") > 0;
var isiPhone = _device.indexOf("iPhone") > 0;
if(isMobile && !isPad){
  // device is mobile
  if(isiPhone){
    // device is iPhone
  } else if(isAndroid){
    // device is Android
  }
} else if(isPad){
  // device is iPad
} else {
  // device is PC
}
</script>

2017/01/05

Tab select sample without redirect


Html:
<div class="tabs">
<ul>
<li><a id="tab_1" onclick="showTabContent(this.id);">Tab 1</a></li>
<li><a id="tab_2" onclick="showTabContent(this.id);">Tab 2</a></li>
<li><a id="tab_3" onclick="showTabContent(this.id);">Tab 3</a></li>
</ul>
</div>
<div class="tabContent" id="tabContent1">Content 1</div>
<div class="tabContent" id="tabContent2" style="display:none;">Content 2</div>

2017/01/04

Fix rigidbody2D.velocity not suported in Unity 5.*

Use
GetComponent<Rigidbody2D>()
instead of
rigidbody2D.velocity

Example:
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x,0);