「jQuery」json形式の文字列をオブジェクトへ変換する方法まとめ

json文字列:
var str = ‘{“paName1”:”value1”,”paName2”:”value2”}’;

方法1
var obj = eval (“(” + str + “)”);

方法2
var obj = JSON.parse(str);

方法3
var obj = jquery.parseJSON(str);

[Java]IP文字列を整数に変換するコード

Javaコード:
public int iptoIntFunc(String ip){
if(null == ip || “”.equals(ip.trim()) || !checkIP(ip)) return 0;
String[] ipStrs = ip.split(“\\.”);
int result = 0;
for(int i = 0;i < 4;i ++){ Integer ipSubInteger = Integer.parseInt(ipStrs[i]); if(ipSubInteger > 255) {
result = 0;
break;
}
result += (ipSubInteger << (24 – i * 8));
}
return result;
}

/*正規表現でipチェック*/
private boolean checkIP(String ip){
return ip.matches(“\\d{1,3}(\\.\\d{1,3}){3}”);
}

「Android」重複した要素をリストから排除するコード

方法1
public static void removeDuplement(List emLst) {
for ( int i = 0 ; i < emLst.size() – 1 ; i ++ ) {
for ( int j = emLst.size() – 1 ; j > i; j — ) {
if (emLst.get(j).equals(emLst.get(i))) {
emLst.remove(j);
}
}
}
System.out.println(emLst);
}

方法2
public static void removeDupElement(List emLst) {
HashSet h = new HashSet(emLst);
emLst.clear();
emLst.addAll(h);
System.out.println(emLst);
}

方法3
public static void removeDupElementWithOrder(List emLst) {
Set set = new HashSet();
List newLst = new ArrayList();
for (Iterator iter = emLst.iterator(); iter.hasNext();) {
Object element = iter.next();
if (set.add(element))
newLst.add(element);
}
emLst.clear();
emLst.addAll(newLst);
System.out.println( ” remove duplicate ” + emlst);
}

CentOS7.3.1611でポートを解放する

ポートを解放
firewall-cmd –zone=public –add-port=80/tcp –permanent
firewall-cmd –add-port=22/tcp –zone=public –permanent

ファイアウォールを再起動
systemctl restart firewalld

利用しているポートを確認
lsof -i tcp:80

ポートの一覧を表示
netstat -ntlp

CentOS7にnginx1.13.4をインストールする手順

1.nginxパッケージのダウンロード
#wget http://nginx.org/download/nginx-1.13.4.tar.gz

2.解凍
#tar xzvf nginx-1.13.4.tar.gz

3.コンパイルインストール
#./configure –prefix=/usr/local/nginx-1.13.4 && make && make install

4.設定ファイルをバックアップ
#cd /usr/local/nginx-1.13.4 && cp nginx.conf nginx.conf.bak

5.nginxの操作
起動
/usr/local/nginx-1.13.4/sbin/nginx -c /usr/local/nginx-1.13.4/conf/nginx.conf &リロード
/usr/local/nginx-1.13.4/sbin/nginx -s reload
停止
/usr/local/nginx-1.13.4/sbin/nginx -s stop

MySQLにユーザー作成、権限設定のメモ

操作手順
#create user ‘testuser’@’%’ identified by ‘12345’;
#grant all privileges on *.* to ‘testuser’;
#commit;
#flush privileges;

CentOS7でMySQL完全アンインストールする

操作手順
#yum remove mysql mysql-server mysql-devel mysql-libs compat-mysql51 mysql-community-client mysql-community-libs mysql-community-server mysql-community-common mysql-community-release.noarch
#rm -rf /var/lib/mysql
#rm /etc/my.cnf
#rm -rf /var/lib/mysql/
#rm -rf /usr/lib64/mysql
#rm -rf /usr/lib/mysql
#rm -rf /usr/share/mysql
#rm –rf /usr/my.cnf
#rm -rf /root/.mysql_sercret
#chkconfig –del mysqld

#yum list installed mysql*

「PHP」アップロードされた画像の拡張子(jpg、png、gif)を判定する

phpコード:
function isImageFunc($fileName)
{
$file = fopen($fileName, “rb”);
$kdf = fread($file, 2);

fclose($file);
$strInfo = @unpack(“C2chars”, $kdf);
$typeCode = intval($strInfo[‘chars1’].$strInfo[‘chars2’]);
$fileType = ”;

if($typeCode == 255216 /*jpg*/ || $typeCode == 7173 /*gif*/ || $typeCode == 13780 /*png*/ || $typeCode == 8273 /*webp*/)
{
return $typeCode;
}
else
{
// echo ‘”jpg/jpeg/gif/png/webp画像をアップロードしてください’;
return false;
}
}

jqueryで最初ラジオボタンの値を取得

$(“input[type=radio][checked]”).eq(0).val()

CentOS7.3にphp-mcrypt5.4.16をインストールする

# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm

# sudo rpm -ivh epel-release-7-10.noarch.rpm
Preparing… ################################# [100%]
Updating / installing…
1:epel-release-7-10 warning: /etc/yum.repos.d/epel-testing.repo created as /etc/yum.repos.d/epel-testing.repo.rpmnew
warning: /etc/yum.repos.d/epel.repo created as /etc/yum.repos.d/epel.repo.rpmnew
################################# [100%]

 

# sudo yum install –enablerepo=epel php-mcrypt
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* epel: ftp.riken.jp
* remi-safe: mirrors.mediatemple.net
Resolving Dependencies
–> Running transaction check
—> Package php-mcrypt.x86_64 0:5.4.16-7.el7 will be installed
–> Processing Dependency: libmcrypt.so.4()(64bit) for package: php-mcrypt-5.4.16-7.el7.x86_64
–> Running transaction check
—> Package libmcrypt.x86_64 0:2.5.8-13.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
php-mcrypt x86_64 5.4.16-7.el7 epel 20 k
Installing for dependencies:
libmcrypt x86_64 2.5.8-13.el7 epel 99 k

Transaction Summary
================================================================================
Install 1 Package (+1 Dependent package)

Total download size: 119 k
Installed size: 331 k
Is this ok [y/d/N]: y
Downloading packages:
(1/2): libmcrypt-2.5.8-13.el7.x86_64.rpm | 99 kB 00:00
(2/2): php-mcrypt-5.4.16-7.el7.x86_64.rpm | 20 kB 00:00
——————————————————————————–
Total 432 kB/s | 119 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : libmcrypt-2.5.8-13.el7.x86_64 1/2
Installing : php-mcrypt-5.4.16-7.el7.x86_64 2/2
Verifying : libmcrypt-2.5.8-13.el7.x86_64 1/2
Verifying : php-mcrypt-5.4.16-7.el7.x86_64 2/2

Installed:
php-mcrypt.x86_64 0:5.4.16-7.el7

Dependency Installed:
libmcrypt.x86_64 0:2.5.8-13.el7