Skip to content

Instantly share code, notes, and snippets.

@maarten00
maarten00 / pmt.js
Created Mar 19, 2015
Excel PMT in PHP and JavaScript
View pmt.js
/**
* Copy of Excel's PMT function.
* Credit: http://stackoverflow.com/questions/2094967/excel-pmt-function-in-js
*
* @param rate_per_period The interest rate for the loan.
* @param number_of_payments The total number of payments for the loan in months.
* @param present_value The present value, or the total amount that a series of future payments is worth now;
* Also known as the principal.
* @param future_value The future value, or a cash balance you want to attain after the last payment is made.
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
@maarten00
maarten00 / functions.php
Last active Jun 1, 2016
Gravity forms referrer url fix
View functions.php
function populate_posts($form){
foreach($form['fields'] as &$field){
if($field['defaultValue'] != '{referer}')
continue;
//Check referrer field, if exists and HTTP referrer not set, try to fill it manually
if($field['defaultValue'] == '{referer}' && ! isset($_SERVER['HTTP_REFERER']))
{
@maarten00
maarten00 / gist:ca92bdd99fc78cdf24dc
Created Nov 5, 2014
Regex: Find all @if, @else, @elseif or @endif that are not preceded and postceded by a space
View gist:ca92bdd99fc78cdf24dc
(?<!\s)(@if\(.*\)|@elseif\(.*\)|@else|@endif)(?!\s)
@maarten00
maarten00 / prettyprice.js
Last active Sep 24, 2019
Prettyprice Javascript
View prettyprice.js
export const prettyPrice = price => {
price = parseFloat(price);
price = formatMoney(price);
price = addDecimalSeperators(price);
price = price.replace(",00", ",-");
return price;
};
const formatMoney = (price, length, decimalDelimiter, sectionDelimiter) => {
let c, d, t, s, i, j;
@maarten00
maarten00 / prettyprice.php
Last active Aug 29, 2015
Pretty Price formatter
View prettyprice.php
/**
* Helper function to format price
* Replaces dots with commas, replaces trailing zeroes with ,-
* If there is only 1 trailing zero, adds another
* Adds ,- for rounded prices
* @param $price
* @return mixed|string
*/
public static function prettyPrice($price)
{
@maarten00
maarten00 / exception.blade.php
Last active Aug 29, 2015
Laravel Exception Mailer
View exception.blade.php
<h1>Exception in {{ App::environment() }}-environment!</h1>
<strong>Code</strong>: {{ $exception->getCode() }}<br>
<strong>Exception message</strong>: {{ $exception->getMessage() }}<br>
<strong>Exception file</strong>: {{ $exception->getFile() }}<br>
<strong>Exception line</strong>: {{ $exception->getLine() }}<br>
<hr/>
<strong>INPUT vars:</strong><br>