Author Archive

JS精度计算

Math.formatFloat = function(f, digit) { 
    var m = Math.pow(10, digit); 
    return parseInt(f * m, 10) / m; 
} 

var numA = 0.1; 
var numB = 0.2;
alert(Math.formatFloat(numA + numB, 1) === 0.3);

这个方法是什么意思呢?为了避免产生精度差异,我们要把需要计算的数字乘以 10 的 n 次幂,换算成计算机能够精确识别的整数,然后再除以 10 的 n 次幂,大部分编程语言都是这样处理精度差异的,我们就借用过来处理一下 JS 中的浮点数精度误差。


Postfix 限制发件人 smtpd_sender_restrictions

/etc/postfix/sender_access:
domain1.com OK
domain2.com OK
Run: postmap /etc/postfix/sender_access
/etc/postfix/main.cf
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access, reject
/etc/init.d/postfix reload

https://wiki.centos.org/HowTos/postfix_restrictions


ImageMagick Is On Fire — CVE-2016–3714

If you use ImageMagick or an affected library, we recommend you mitigate the known vulnerabilities by doing at least one of these two things (but preferably both!):

Verify that all image files begin with the expected “magic bytes” corresponding to the image file types you support before sending them to ImageMagick for processing. (see FAQ for more info)
Use a policy file to disable the vulnerable ImageMagick coders. The global policy for ImageMagick is usually found in “/etc/ImageMagick”. The below policy.xml example will disable the coders EPHEMERAL, URL, MVG, and MSL.
policy.xml (updated 5/5)


  
  
  
  
  
  
  
  
  


Custom Blade Directives in Laravel 5

Step 1: Register a custom Blade directive:

Custom Link';
         });
     }
    ...
Step 2: Use your custom Blade directive:



@shout('this is my custom blade directive!!')

@customLink

Outputs:

THIS IS MY CUSTOM BLADE DIRECTIVE!!
Custom Link


Custom Classes in Laravel 5

This answer is applicable to general custom classes within Laravel. For a more Blade-specific answer, see Custom Blade Directives in Laravel 5.

Step 1: Create your Helpers (or other custom class) file and give it a matching namespace. Write your class and method:


Step 2: Create an alias:

 [
     ...
        'Helper' => 'App\Helpers\Helper::class',
     ...
Step 3: Use it in your Blade template:


{!! Helper::shout('this is how to use autoloading correctly!!') !!}

Extra Credit: Use this class anywhere in your Laravel app:


Source: http://www.php-fig.org/psr/psr-4/

Why it works: https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ClassLoader.php

Where autoloading originates from: http://php.net/manual/en/language.oop5.autoload.php


Installing PHP 7 on OS X Yosemite

How to install it?

This tutorial is for OS X users, some procedures might apply for some linux versions too (apache configuration)

1. Get Homebrew

Homebrew is a package manager for OS X. Find install instructions HERE.
(continue reading…)


Debian完全卸载清理并重新安装MySQL服务器

sudo apt-get --purge remove mysql-server
sudo apt-get install mysql-server

sudo apt-get --purge remove mysql-server
sudo apt-get --purge remove mysql-client
sudo apt-get --purge remove mysql-common
apt-get autoremove
apt-get autoclean
rm /etc/mysql/ -R
rm /var/lib/mysql/ -R

postfix疯狂外发垃圾邮件之分析与解决,思路分析与解决办法

分析
一、查找main.cf配置文件
localhost# find / -name main.cf
/etc/postfix/main.cf (continue reading…)


Tomcat htaccess

Protecting a Resource with a MemoryRealm

To actually see how a MemoryRealm works, let’s create a realm that protects a sample web application named /onjava. At this point, if you have not already done so, take a look at my previous OnJava article, Deploying Web Applications to Tomcat. We will be using the /onjava web application from it. The steps involved in setting up a new MemoryRealm are described in the following list. (continue reading…)


iOS国际化

环境

系统环境: iOS7 – iOS9
(continue reading…)


Copyright © 1996-2010 Add Lives. All rights reserved.
iDream theme by Templates Next | Powered by WordPress