Skip to content

Instantly share code, notes, and snippets.

View a-ignatov-parc's full-sized avatar

Anton Ignatov a-ignatov-parc

View GitHub Profile
function goToStep(env, step) {
var handler = function() {
// Launch animation
transition(env, step);
// Update first step
env.steps.first = step;
// Update buttons status
updateButtonsState(env);
var data = {
id: 1,
name: 'test',
posts: [{
id: 1,
text: 'test'
}]
},
model = new Backbone.Model(data),
posts = model.getAsCollection('posts')
// При объявлении метода сразу же вызывается функция которая создает массив с месяцами и
// одновремено возвращает другую функция которая будет доступна при обращении к методу и в которой
// через замыкание будет доступен массив с месяцами.
getDeclinatedMonths: (function() {
var months = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
return function(month) {
// Если переменная передана, то возвращаем значение массива иначе весь массив
return month != null ? months[month] : months;
}
if (isNext) {
stepPosition++;
} else {
stepPosition--;
}
if (stepPosition >= 0 || stepPosition <= slides) {
scrollbar.slider('option', 'value', stepPosition);
}
@a-ignatov-parc
a-ignatov-parc / gist:4159487
Created November 28, 2012 06:52
Настройки линтования для grunt.js
jshint: {
options: {
indent: 4,
expr: true,
boss: true,
undef: true,
curly: true,
forin: true,
unused: true,
newcap: true,
{
"ErrorCode": "",
"Success": true,
"Result": [{
"Id": "14a08298-16d6-11e2-9dbd-10246288709b",
"NameRu": "Ширина, м.",
"NameEn": "width",
"Data": [{
"NameEn": "width",
"NameRu": "Ширина, м.",
app.prototype.beforeInit = function(input) {
if (!this.global.google) {
this.global.gInit = this.bind(function() {
this.core.observatory.trigger('...');
delete this.global.gInit;
}, this)
}
}
// To make the benchmark results predictable, we replace Math.random
// with a 100% deterministic alternative.
Math.random = (function() {
var seed = 49734321;
return function() {
// Robert Jenkins' 32 bit integer hash function.
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
Result: {
List: [
{
Id: null,
ListFields: []
}, {
Id: null,
ListFields: []
}
],
@a-ignatov-parc
a-ignatov-parc / callback_with_custom_params.js
Created August 23, 2012 12:24
Рефакторинг адского ада
var method = 'get' + section[0].toUpperCase() + section.substring(1)
if (typeof(this[method]) === 'function') {
this[method](params, function() {
callback(a, b, c);
});
}