Skip to content

Instantly share code, notes, and snippets.

@fomichigo
fomichigo / ko-util-tyr.js
Created March 19, 2016 06:51 — forked from kyeotic/ko-util-tyr.js
Knockout Utility Functions
http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
ko.bindingHandlers.inlineSelect = {
init: function(element, valueAccessor, allBindingsAccessor){
var span = $(element);
var select = $('<select></select>', {'style' : 'display: none'});
span.after(select);
ko.applyBindingsToNode(select.get(0), { value: valueAccessor(), options: allBindingsAccessor().inlineOptions });
@fomichigo
fomichigo / ko.binding-handlers.js
Created March 19, 2016 06:35 — forked from romeshniriella/ko.binding-handlers.js
Binding handlers used in my App. Extracted from everywhere. Some of the original sources unknown.
ko.bindingHandlers.money = {
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var value = valueAccessor();
var allBindings = allBindingsAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value) || 0;
var output = output = accounting.formatMoney(valueUnwrapped, OKLO.CurrencySign);
if ($(element).is("input") === true) {
@fomichigo
fomichigo / CustomBindingHandler.js
Created February 13, 2016 09:00 — forked from RainerAtSpirit/CustomBindingHandler.js
KnockoutJS, RequireJS and the revealing module pattern
define (['knockout', 'jquery', 'prettyDate', 'metrojs'], function ( ko, $ ) {
"use strict";
// See https://github.com/SteveSanderson/knockout/wiki/Bindings---class
ko.bindingHandlers['class'] = {
'update' : function ( element, valueAccessor ) {
if ( element['__ko__previousClassValue__'] ) {
ko.utils.toggleDomNodeCssClass (element, element['__ko__previousClassValue__'], false);
}
var value = ko.utils.unwrapObservable (valueAccessor ());
@fomichigo
fomichigo / contact.html
Created December 14, 2015 16:09 — forked from ajtroxell/contact.html
Build a simple PHP, jQuery, and AJAX Powered Contact Form, from: http://ajtroxell.com/build-a-simple-php-jquery-and-ajax-powered-contact-form/
<form id="contact" name="contact" method="post">
<fieldset>
<label for="name" id="name">Name<span class="required">*</span></label>
<input type="text" name="name" id="name" size="30" value="" required/>
<label for="email" id="email">Email<span class="required">*</span></label>
<input type="text" name="email" id="email" size="30" value="" required/>
<label for="phone" id="phone">Phone</label>
<input type="text" name="phone" id="phone" size="30" value="" />
@fomichigo
fomichigo / l.php
Created October 30, 2015 08:38 — forked from adriengibrat/l.php
Extreme minification of shortest possible PSR-0 compliant autoloader, 5 lines !
<?php
//set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__); // optional
spl_autoload_register(function ($class) {
$file = preg_replace('#\\\|_(?!.+\\\)#','/', $class) . '.php';
if (stream_resolve_include_path($file))
require $file;
});
@fomichigo
fomichigo / interkassa.php
Created October 30, 2015 08:33 — forked from jerronimo/interkassa.php
Symfony Interkassa Integration Primer
<?php
namespace Mlm\PaymentBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Mlm\PaymentBundle\Entity\Order;
use Symfony\Component\HttpFoundation\JsonResponse;
@fomichigo
fomichigo / russian_transliteration.php
Last active June 14, 2017 11:04 — forked from vindia/russian_transliteration.php
Russian (cyrillic) transliteration function
<?php
function transliterate($string) {
$roman = array("Sch","sch",'Yo','Zh','Kh','Ts','Ch','Sh','Yu','ya','yo','zh','kh','ts','ch','sh','yu','ya','A','B','V','G','D','E','Z','I','Y','K','L','M','N','O','P','R','S','T','U','F','','Y','','E','a','b','v','g','d','e','z','i','y','k','l','m','n','o','p','r','s','t','u','f','','y','','e');
$cyrillic = array("Щ","щ",'Ё','Ж','Х','Ц','Ч','Ш','Ю','я','ё','ж','х','ц','ч','ш','ю','я','А','Б','В','Г','Д','Е','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Ь','Ы','Ъ','Э','а','б','в','г','д','е','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','ь','ы','ъ','э');
return str_replace($cyrillic, $roman, $string);
}
var_dump(transliterate('андрей шевченко')); # andrey shevchenko
?>
@fomichigo
fomichigo / .gitignore
Last active August 29, 2015 14:24 — forked from redoPop/.gitignore
# This is a template .gitignore file for git-managed WordPress projects.
#
# Fact: you don't want WordPress core files, or your server-specific
# configuration files etc., in your project's repository. You just don't.
#
# Solution: stick this file up your repository root (which it assumes is
# also the WordPress root directory) and add exceptions for any plugins,
# themes, and other directories that should be under version control.
#
# See the comments below for more info on how to add exceptions for your
<?php
// Add the code below to your theme's functions.php file to add a confirm password field on the register form under My Accounts.
add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3);
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
global $woocommerce;
extract( $_POST );
if ( strcmp( $password, $password2 ) !== 0 ) {
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'woocommerce' ) );
}
<?php
/**
* Check if there are onsale products.
*
* @access public
* @param -
* @return boolean
*/
function woo_have_onsale_products() {