Skip to content

Instantly share code, notes, and snippets.

View otar's full-sized avatar

Otar Chekurishvili otar

View GitHub Profile
function array_nbr(row_idx, column_idx, rows, columns, level)
{
level = level || 1;
var nbr = [];
for (var y = Math.max(0, row_idx - level); y <= Math.min(row_idx + level, rows); y++)
{
for (var x = Math.max(0, column_idx - level); x <= Math.min(column_idx + level, columns); x++)
{
nbr.push([x, y]);
}
@otar
otar / loan_calculator.php
Created December 8, 2010 10:00
Calculates monthly or total payable amount of the loan
<?php
/**
* Calculates monthly or total payable amount of the loan.
*
* @param integer $amount Loaned amount, default is 1000
* @param integer $percent Percent in which amount should be calculated, default is 15
* @param integer $months Loan duration in months, default is 12 months (1 year)
* @param boolean $total If positive value is passed function returns total payable amount instead of monthly
* @return float Returns 2 decimal float number
@otar
otar / envirions.php
Created March 7, 2012 09:41
Detect current environment and define as a global constant.
<?php
/**
* Detect current environment and define as a global constant.
* @param array $environments Associative-Array where the keys are environment
* names and it's values the URI's that should be matched. Environment URI's can
* be string or an array of strings. If no environment URI is matched sets
* current environment as a first key element of an environments array.
* @param string $constant_name Name of the constant enfironment should be
* assigned to.
@otar
otar / jquery.confirmations.js
Created September 11, 2012 08:57
jQuery Confirmations
$(function()
{
$('a[rel="confirm"]').on('click', function(event)
{
var message = !$(this).data('confirm')
? 'Are you sure you want to do this?'
: $(this).data('confirm');
if (!confirm(message))
{
<?php
function request_path()
{
$request_uri = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
$script_name = explode('/', trim($_SERVER['SCRIPT_NAME'], '/'));
$parts = array_diff_assoc($request_uri, $script_name);
if (empty($parts))
{
return '/';
@otar
otar / jsonp.js
Last active August 29, 2015 14:05
Helper function for loading JSONP
var jsonp = function(url)
{
var script = window.document.createElement('script');
script.async = true;
script.src = url;
script.onerror = function()
{
alert('Can not access JSONP file.')
};
var done = false;
@otar
otar / setup_selenium.sh
Created October 23, 2015 10:40 — forked from curtismcmullan/setup_selenium.sh
Setup Selenium Server on Ubuntu 14.04
#!/bin/bash
# Following the guide found at this page
# http://programmingarehard.com/2014/03/17/behat-and-selenium-in-vagrant.html
echo "\r\nUpdating system ...\r\n"
sudo apt-get update
# Create folder to place selenium in
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">