Skip to content

Instantly share code, notes, and snippets.

View jeka-kiselyov's full-sized avatar

Jeka Kiselyov jeka-kiselyov

View GitHub Profile
@jeka-kiselyov
jeka-kiselyov / epsilon.c
Last active August 29, 2015 13:56
Math: Comparing with epsilon – relative error
/// Always forget it
/// Source: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
relativeError = fabs((result - expectedResult) / expectedResult);
// If result is 99.5, and expectedResult is 100, then the relative error is 0.005.
// Sometimes we don’t have an ‘expected’ result, we just have two numbers that we want to compare to see if they are almost equal. // We might write a function like this:
// Non-optimal AlmostEqual function - not recommended.
@jeka-kiselyov
jeka-kiselyov / cart.js
Last active August 24, 2016 08:47
JavaScript: Cart.js
// cart.js
//
// Copyright 2014 Jeka Kiselyov
// Released under the MIT license, http://opensource.org/licenses/MIT
//
// Usage:
// Cart.add(sku, name, 9.99, qty);
// Cart.remove(sku);
// if (Cart.has(sku)) { ...
// var price = Cart.priceTotal();
@jeka-kiselyov
jeka-kiselyov / display_russian_and_ukrainian_dates.tpl
Last active August 29, 2015 13:56
0F : Templates : Display Date in Different Languages
Test date format:<br>
En: {234234|date_format:'%B %e, %Y'}<br>
Rus: {234234|date_format:'%e %m %Y':'':'rus'}<br>
Urk: {234234|date_format:'%e %m %Y':'':'ukr'}<br>
First parameter - php.net/strftime (%m is changed to 'января':'декабря' for Russian and 'ciчня':'грудня' for Ukrainian)
Second parameter - default date (if argument == '')
Third - 'auto', 'rus', 'ukr'
Works with 0F modified date_format Smarty plugin. It's below in this gist: modifier.date_format.php