Skip to content

Instantly share code, notes, and snippets.

View rohozhnikoff's full-sized avatar

Murad R. rohozhnikoff

  • Kyiv, Ukraine
View GitHub Profile
@rohozhnikoff
rohozhnikoff / gist:6834561
Last active December 24, 2015 17:19
simple helper to create jquery-plugins, based on class-instance (just for concept)
function cloneStructuresPrimitives(input) {
// need checks on primitivesTypes, return input
return JSON.parse(JSON.stringify(input));
}
export default function(name, WidgetClass) {
return $.fn[name] = function(opt){
if (this.length > 0) return
baseOpt = opt || {};
@rohozhnikoff
rohozhnikoff / gist:6834564
Created October 4, 2013 23:37
Переводим первую букву в верхний регистр (удобно для всяких динамически формируемых штук)
String.prototype.cap = function () {
return this.charAt(0).toUpperCase() + this.slice(1);
}
@rohozhnikoff
rohozhnikoff / gist:6834578
Created October 4, 2013 23:39
Начинаем день недели с понедельника
Date.prototype.getWeekday = function(){
var weekday = this.getDay() - 1;
if(weekday === -1) weekday = 6;
return weekday;
}
@rohozhnikoff
rohozhnikoff / gist:6835679
Created October 5, 2013 01:59
удобный метод для проброса всяких jquery колбеков
callback: function (method) {
var self = this;
return (typeof self[method] === "function")
? function(){
// добавляем оригинальный this последним аргументом
var args = _(arguments).toArray().value();
args.push(this);
return self[method].apply(self, args);
}
$('<script>', {src: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js'}).appendTo('head');
$(function(){
var arr = [];
$('*').each(function(i, el){
var classe = $(el).attr('class');
if(classe && classe.length) {
arr.push(classe.split(' '));
}
});
arr = _(arr).sortBy();
@rohozhnikoff
rohozhnikoff / gist:74a2a5ff04af6414e1c2
Created July 28, 2014 10:24
bootstrap grid standalone
//
// Grid system
// --------------------------------------------------
//## Define your custom responsive grid.
//** Number of columns in the grid.
@grid-columns: 12;
//** Padding between columns. Gets divided in half for the left and right.
@rohozhnikoff
rohozhnikoff / gist:e6f925a6b78c010f7bc1
Created August 29, 2014 22:39
keyCodes on browsers, name => code
{
"backspace": "8",
"tab": "9",
"enter": "13",
"shift": "16",
"ctrl": "17",
"alt": "18",
"pause/break": "19",
"caps lock": "20",
"escape": "27",
@rohozhnikoff
rohozhnikoff / gist:ee6a14727f0674b67b7b
Created August 29, 2014 22:40
keyCodes on browsers, code => name
{
"8": "backspace",
"9": "tab",
"13": "enter",
"16": "shift",
"17": "ctrl",
"18": "alt",
"19": "pause/break",
"20": "caps lock",
"27": "escape",
@rohozhnikoff
rohozhnikoff / equalHelper.coffee
Created September 3, 2014 13:40
block helper to check if arguments is equal
`import Em from 'ember'`
equal = (args..., options) ->
arr = for arg in args
value = @get(arg)
if typeof value isnt 'undefined' then value else arg
method = if _.isEqual.apply(_, arr) then 'fn' else 'inverse'
return options[method](@)
@rohozhnikoff
rohozhnikoff / gist:9c4c1090b2963ee0dc7f
Created September 3, 2014 13:41
simple helper to add 's' if length more then 1
`import Ember from 'ember'`
oneormany = (length, value) ->
return "There are no #{value}s" if length is 0
suffix = if length > 1 then 's' else ''
return "#{length} #{value}#{suffix}"
OneormanyHelper = Ember.Handlebars.helper 'oneormany', oneormany
`export { oneormany }`