Skip to content

Instantly share code, notes, and snippets.

@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 / 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-convenience.js
Created June 29, 2016 16:48 — forked from lelandrichardson/ko-convenience.js
Knockout.js Custom Utility Bindings
(function (ko, handlers, unwrap, extend) {
"use strict";
extend(handlers, {
href: {
update: function (element, valueAccessor) {
handlers.attr.update(element, function () {
return { href: valueAccessor() };
});
}
},
@fomichigo
fomichigo / simple-json-reponse.php
Created August 7, 2016 09:36 — forked from james2doyle/simple-json-reponse.php
A simple JSON response function for PHP. Used in various PhileCMS plugins.
<?php
function json_response($message = null, $code = 200)
{
// clear the old headers
header_remove();
// set the actual code
http_response_code($code);
// set the header to make sure cache is forced
header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
// Q sample by Jeff Cogswell
/*===========
We want to call these three functions in sequence, one after the other:
First we want to call one, which initiates an ajax call. Once that ajax call
is complete, we want to call two. Once two's ajax call is complete, we want to call three.
BUT, we don't want to just call our three functions in sequence, as this quick
demo will show. Look at this sample function and think about what order
@fomichigo
fomichigo / gist:31829c4defc5006b84c13217b9e51e10
Created May 18, 2017 17:23 — forked from realmyst/gist:1262561
Склонение числительных в javascript
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
use:
declOfNum(count, ['найдена', 'найдено', 'найдены']);
@fomichigo
fomichigo / UUID.php
Created July 10, 2017 13:25
Pure PHP UUID generator
<?php
/**
* UUID class
*
* The following class generates VALID RFC 4122 COMPLIANT
* Universally Unique IDentifiers (UUID) version 3, 4 and 5.
*
* UUIDs generated validates using OSSP UUID Tool, and output
* for named-based UUIDs are exactly the same. This is a pure
* PHP implementation.

Array<T>

Legend:

  • ✏️ method changes this.
  • 🔒 method does not change this.

Array<T>.prototype.*:

  • concat(...items: Array: T[] 🔒 ES3
@fomichigo
fomichigo / simple-pagination.js
Created June 1, 2018 15:35 — forked from kottenator/simple-pagination.js
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@fomichigo
fomichigo / selenium-php-webdriver-cheatsheet.md
Created July 20, 2018 18:02 — forked from aczietlow/selenium-php-webdriver-cheatsheet.md
Cheat sheet for using php webdriver (facebook/webdriver).

Webdriver PHP API workthough

  • Open a browser

    # start an instance of firefox with selenium-webdriver
    
    $browser_type = 'firefox'
    $host = 'http://localhost:4444/wd/hub'
    

$capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => $browser_type);