Skip to content

Instantly share code, notes, and snippets.

View MNBuyskih's full-sized avatar

Mihail Buyskih MNBuyskih

View GitHub Profile
@MNBuyskih
MNBuyskih / bootstrap-modal.html
Last active December 19, 2020 23:38
Bootstrap modal helper class
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="modal.js"></script>
</head>
@MNBuyskih
MNBuyskih / Date.getDaysInMonth.js
Created December 13, 2013 09:13
Method allow get totals days in month. Usage: var date = new Date(2013, 2, 14); alert(date.getDaysInMonth());
Date.prototype.getDaysInMonth = function () {
return (new Date(this.getFullYear(), this.getMonth() + 1, 0)).getDate();
};
@MNBuyskih
MNBuyskih / gist:eb2be76a3afbb0c81c66
Last active August 29, 2015 14:01
4chan all image expansion bookmarklet
javascript:var links=document.getElementsByClassName('fileThumb');for(var i in links){if(links.hasOwnProperty(i)){var images=links[i].getElementsByTagName('img');console.log(images.length);ImageExpansion.toggle(images.length===1?images[0]:images[1]);}}
$.fn.drag = function () {
var $this = $(this);
$this.data('move', false);
$this.mousedown(function (e) {
e.preventDefault();
$this.data('move', true);
$this.data('start', [e.offsetX, e.offsetY]);
});
$(document).mouseup(function (e) {
e.preventDefault();
@MNBuyskih
MNBuyskih / getPath.js
Created September 18, 2014 10:26
Get full path of element
$.fn.getPath = function () {
var $this = $(this), _parents = $this.parents(), parents = [], getIndex = function (node, className) {
var name = node.get(0).tagName.toLowerCase(), parent = node.parent(), siblings = parent.children(name + className);
if (siblings.length > 1) {
return ':nth-child(' + (siblings.index(node) + 1) + ')';
}
return '';
}, getClass = function (className) {
className = $.trim(className);
if (!className) return '';
@MNBuyskih
MNBuyskih / gist:f7780fc82de7dafdcd21
Created February 9, 2015 07:08
php to base 62 - from base 62
/**
* src - http://stackoverflow.com/questions/4964197/converting-a-number-base-10-to-base-62-a-za-z0-9
*/
class Base62 {
public static $table = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
public static function encode($num) {
$base = 62;
$table = self::$table;
@MNBuyskih
MNBuyskih / underscore.findKey.js
Last active August 29, 2015 14:21
UnderscoreJS find key in object by predicant
function findKey (obj, predicant) {
var key = null;
_.find(obj, function (v, k) {
if (predicant(v, k, obj)) {
key = k;
return true;
}
return false;
});
@MNBuyskih
MNBuyskih / isNumeric.js
Last active August 29, 2015 14:21
underscorejs _.isNumeric() function. Src is jQuery.isNumeric() function.
function isNumeric (obj) {
return !_.isArray(obj) && (obj - parseFloat(obj) + 1) >= 0;
}
function deepClone (obj, depth) {
var clone;
if (!obj || (typeof obj !== 'object')) {
clone = obj; // by value
} else if (_.isString(obj)) {
clone = String.prototype.slice.call(obj);
} else if (_.isDate(obj)) {
clone = new Date(obj.valueOf());
} else if (_.isFunction(obj.clone)) {
@MNBuyskih
MNBuyskih / string-md5.js
Last active August 29, 2015 14:22
node js quick md5 string
// crypto = require('crypto')
crypto.createHash('md5').update('string').digest('hex');