Skip to content

Instantly share code, notes, and snippets.

View chaoswey's full-sized avatar

chaoswey chaoswey

  • Taichung, Taiwan
View GitHub Profile
@chaoswey
chaoswey / IP-in-Network-mask.php
Last active July 22, 2019 01:47
網路遮罩
function ip_in_range($ip, $range)
{
if (strpos($range, '/') == false) {
return ($ip == $range);
}
list($range, $netmask) = explode('/', $range, 2);
$range_decimal = ip2long($range);
$ip_decimal = ip2long($ip);
$wildcard_decimal = pow(2, (32 - $netmask)) - 1;
$netmask_decimal = ~$wildcard_decimal;
@chaoswey
chaoswey / getContrastColor.php
Last active July 22, 2019 01:48
php 判斷 hex color 然後回傳 白色 or 黑色
/**
* @param $hexColor
* @return string
*/
function getContrastColor($hexColor)
{
$R1 = hexdec(substr($hexColor, 1, 2));
$G1 = hexdec(substr($hexColor, 3, 2));
$B1 = hexdec(substr($hexColor, 5, 2));
@chaoswey
chaoswey / password regular expression
Created December 26, 2018 01:53
密碼常用的正則表示式
至少八個字符,至少一個字母和一個數字:
"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$"
至少八個字符,至少一個字母,一個數字和一個特殊字符:
"^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$"
至少八個字符,至少一個大寫字母,一個小寫字母和一個數字:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$"
至少八個字符,至少一個大寫字母,一個小寫字母,一個數字和一個特殊字符:
@chaoswey
chaoswey / js-geocode.js
Last active July 22, 2019 01:48
jquery 查詢經緯度
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=[key]&sensor=false"></script>
<script>
$(function () {
var geocoder = new google.maps.Geocoder;
$('#trans').on('click', function () {
var address = $('input[name=address]').val();
geocoder.geocode({'address': address}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var api = results[0].geometry.location;
@chaoswey
chaoswey / phpAllFileAndFolderInFolder.php
Last active July 22, 2019 01:49
php All File And Folder In Folder
<?php
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->isDir()){
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}