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 / 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')
@ischenkodv
ischenkodv / caret.js
Created October 31, 2012 18:08
Move caret to the end of input or textarea
function moveCursorToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}
@ischenkodv
ischenkodv / random.js
Last active October 12, 2015 02:38
Generate random number using bitwise operator to round values.
/**
* Generate random integer from 0 to limit.
*/
function rnd(limit) {
return (Math.random()*limit)|0;
}
/**
* Generate random float value in range.
*/
@ischenkodv
ischenkodv / gist:979832
Created May 18, 2011 23:31
Example of 2 Mootools panels for blog post.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Открывающаяся панель на MooTools</title>
<script type="text/javascript" src="mootools.min.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
var mySlide = new Fx.Slide('section');