Skip to content

Instantly share code, notes, and snippets.

View ischenkodv's full-sized avatar

Dmitri Ischenko ischenkodv

  • Ukraine, Kryvyi Rih
View GitHub Profile
@ischenkodv
ischenkodv / AsyncQueue.js
Created February 28, 2015 20:17
Asynchronous queue implementation. Functions could be added to queue and executed one by one immediately, or with intervals or in the next frame (using requestAnimationFrame).
;(function(window) {
'use strict';
/**
* AsyncQueue allows you to create a queue of function to be executed via
* setTimout that guaranteed to run in order. This can enable to run
* process-intensive operations without locking up UI.
*
* @constructor
@ischenkodv
ischenkodv / joomla_json.php
Created November 30, 2014 00:35
Return JSON data from action of Joomla controller.
/**
* JSON response from controller's action.
*/
public function run( )
{
JFactory::getDocument()->setMimeEncoding( 'application/json' );
JResponse::setHeader('Content-Disposition','attachment;filename="progress-report-results.json"');
$data = array(
'foo' => 'bar'
@ischenkodv
ischenkodv / ie_conditionals.html
Created February 11, 2014 21:11
Adding class names depending on Internet Explorer version.
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html class="ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8" lang="en"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9" lang="en"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<body></body>
</html>
@ischenkodv
ischenkodv / gist:7006705
Created October 16, 2013 12:09
Usage of SymbolPath as a google maps marker icon.
// Usage of SymbolPath as a marker icon
var marker = new google.maps.Marker({
position: new google.maps.LatLng(-122.5,47.5),
icon: {
path: google.maps.SymbolPath.CIRCLE,
fillOpacity: 0.5,
fillColor: 'ff0000',
strokeOpacity: 1.0,
strokeColor: 'fff000',
strokeWeight: 3.0,
@ischenkodv
ischenkodv / gist:6091581
Created July 26, 2013 19:27
CSS rotate element 5 degrees in IE
/* 5 degree */
filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.99, M12=-0.08, M21=0.08, M22=0.99, SizingMethod="auto expand");
/*
m11 = sin (5 * pi / 180)
m12 = cos (5 * pi / 180)
m21 = cos (5 * pi/ 180)
m22 = sin (5 * pi / 180)
*/
@ischenkodv
ischenkodv / Detecs CSS transform
Last active December 20, 2015 06:08
A function that detects CSS transform availability in browsers.
function getSupportedTransform() {
var prefixes = 'transform WebkitTransform MozTransform OTransform msTransform'.split(' ');
for(var i = 0; i < prefixes.length; i++) {
if(document.createElement('div').style[prefixes[i]] !== undefined) {
return prefixes[i];
}
}
return false;
}
@ischenkodv
ischenkodv / shuffle.js
Last active December 16, 2015 18:08
Knuth shuffle
// Implementation of Knuth shuffle: http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
// More implementations: http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript
var shuffle = function(a) {
for (var i = a.length; --i > 0;) {
// Get random number between first and current index.
var r = Math.floor(Math.random() * (i + 1));
// Swap random with current index values.
var d = a[r];
a[r] = a[i];
a[i] = d;
@ischenkodv
ischenkodv / chain.js
Last active December 14, 2015 22:19
Underscore.js chaining
// Compose function
var cleanArray = _.compose(_.compact, _.uniq, _.flatten);
result = cleanArray(lottery);
// Chainable way
result = _.chain(lottery)
.flatten()
.uniq()
.compact()
.value()
@ischenkodv
ischenkodv / bcrypt.php
Created January 27, 2013 14:02
Usage of Zend\Crypt to generate and verify password hash.
// Create hash
$bcrypt = new Bcrypt();
$bcrypt->setSalt('abcdefghijklmnopqrstufwxyz');
$password = 'dima';
$hash = $bcrypt->create($password);
// Verify password
if ($bcrypt->verify($password, $hash)) {
echo "And there was much rejoicing";
} else {
@ischenkodv
ischenkodv / jquery_checkbox_checked.js
Created November 10, 2012 23:42
Find if input is checked
var isChecked = $('input[type="checkbox"]').is(':checked')