Skip to content

Instantly share code, notes, and snippets.

View eugeneglova's full-sized avatar

Eugene Glova eugeneglova

View GitHub Profile
@eugeneglova
eugeneglova / myPHPProgrammingSkillsTest.php
Created April 5, 2013 17:42
my version of oDesk PHP Programming Skills Test
<?php
// 1
$_POST['checkbox_2'] = true;
$_POST['checkbox_1'] = true;
$_POST['checkbox_3'] = true;
for ($_POST as $key => $val) {
if (preg_match('/checkbox_(\d+)/', $key, $matches)) {
<?php
// How to replace middle part of the word
// Array of words
$array = array('what', 'aaa', 'hellokity');
// Function to return replaced value
// Accept value as a string and
// replacer as a character to replace each char in middle part of the word
@eugeneglova
eugeneglova / proxy.php
Last active December 21, 2015 01:09
php curl proxy
<?php
/**
* proxy.php
*
* Responsible to get data from remote domain
*
* mod_rewrite configuration for .htaccess file
*
* RewriteEngine on
@eugeneglova
eugeneglova / encryption.js
Last active December 21, 2015 12:19
trying to make public and private key based on http://www.youtube.com/watch?v=3QnD2c4Xovk
function enc(exp, private) {
return Math.pow(exp, private) % 17;
}
function calc(pub1, private1, private2) {
var a, b;
a = enc(pub1, private1);
b = enc(pub1, private2);
return enc(b, private1) === enc(a, private2);
}
@eugeneglova
eugeneglova / html2canvas-proxy.php
Last active December 30, 2015 07:29
html2canvas php proxy
<?php
/**
* html2canvas proxy script
*
* Provides proxy service for html2canvas.js lib.
* Responsible for output javascript callback with image url
* to provide work around for the same origin limitation.
*
* Used to ensure that project images are included in the export PNGs,
/**
* isFiles
*
* Returns true if user tries to drag or drop files
*
* @param {jQuery Event} e
* @return {Boolean}
*/
isFiles: function(e) {
if ( ! is(e, 'object')) return false;
(function() {
"use strict";
var loaded_css_urls = [];
function getFontById(fonts, id) {
var found_font;
fonts.some(function(font) {
if (font.id === id) {
@eugeneglova
eugeneglova / index.js
Last active August 29, 2015 14:10
Check for correct brackets in string
function check(s) {
var i = 0, l;
s = s.replace(/[^\{\}\(\)\[\]]/g, "");
l = s.length;
if ( ! l) return true;
if (l % 2 !== 0) return false;
<?php
error_reporting(E_ALL & ~E_WARNING);
// cache time in seconds
$cache_time = 5 * 60; // 5 mins
$time = floor(time() / $cache_time) * $cache_time;
// Getting headers sent by the client.
$headers = apache_request_headers();
@eugeneglova
eugeneglova / index.js
Last active April 25, 2021 20:55
Fill array with missing values using recursion
// [1,3,8,9,17] -> [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
// Using recursion
var dates = [1,3,8,9,17];
function nextI (i) {return i+1;}
function getMissingElements(nextI, element, currentNextElement) {
var nextElement = nextI(element);
if (nextElement === currentNextElement) {
return [];
}
return [nextElement].concat(getMissingElements(nextI, nextElement, currentNextElement));