Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
/* | |
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace | |
so it's better encapsulated. Now you can have multiple random number generators | |
and they won't stomp all over eachother's state. | |
If you want to use this as a substitute for Math.random(), use the random() | |
method like so: | |
var m = new MersenneTwister(); |
// Lists of countries with ISO 3166 codes, presented in various formats. | |
// Last Updated: July 30, 2020 | |
// If you're using PHP, I suggest checking out: | |
// https://github.com/thephpleague/iso3166 | |
// or Laravel: https://github.com/squirephp/squire | |
// | |
// JS developers can check out: | |
// https://www.npmjs.com/package/iso3166-2-db | |
// |
Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
$biggest =100; | |
$all_numbers = range(0,$biggest); | |
$threes = array_fill_keys(range(3, $biggest, 3), 'Fizz'); | |
$fives = array_fill_keys(range(5, $biggest, 5), 'Buzz'); | |
$fifteens = array_fill_keys(range(15, $biggest, 15), 'FizzBuzz'); | |
$all_numbers = array_replace($all_numbers, $threes, $fives, $fifteens); | |
var_dump($all_numbers); |
// http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric/1830844#1830844 | |
function isNumber(n) { return !isNaN(parseFloat(n)) && isFinite(n); } | |
// Check if character is a fraction, e.g. ¼ | |
function isFractionalChar(n) { | |
c = n.charCodeAt(); | |
return (c >= 188 && c <= 190) || (c >= 8531 && c <= 8542); | |
} | |
// return the first fractional character in a string |
server { | |
listen 80; | |
listen [::]:80; | |
server_name domain.com; | |
autoindex off; | |
index index.php index.html; | |
root /srv/www/domain.com/public; |
# stop script on error signal | |
set -e | |
# remove old deployment folders | |
if [ -d "/home/forge/deploy" ]; then | |
rm -R /home/forge/deploy | |
fi | |
if [ -d "/home/forge/backup" ]; then | |
rm -R /home/forge/backup | |
fi |
/** | |
* Mass (bulk) insert or update on duplicate for Laravel 4/5 | |
* | |
* insertOrUpdate([ | |
* ['id'=>1,'value'=>10], | |
* ['id'=>2,'value'=>60] | |
* ]); | |
* | |
* | |
* @param array $rows |
If you're not familiar: What is fail2ban? fail2ban is an awesome linux service/monitor that scans log files (e.g. auth.log for SSH) for potentially malicious behavior. Once fail2ban is tripped it will ban users for a specified duration by adding rules to Iptables. If you're unfamiliar with fail2ban Chris Fidao has a wonderful (& free!) series about security including setting up fail2ban here.
Recently Laravel released a new feature in 5.1 to throttle authentication attempts by simply adding a trait to your authentication controller. The Laravel throttle trait uses the inputted username, and IP address to throttle attempts. I love seeing this added to a framework out of the box, but what about some of our other apps not built on Laravel? Like a WordPress login? Or even an open API etc.? Ultimately,