Skip to content

Instantly share code, notes, and snippets.

View tikijian's full-sized avatar

Tim Tikijian tikijian

View GitHub Profile
@tikijian
tikijian / gist:04cd76840900a63c1a055d06114a87c1
Created January 30, 2019 09:54
sails.js destroy blueprint override
// Это копия стандартного sails blueprint destroy action
// за исключением того, что по дефолту вызывается .meta(fetch: true)
// для того, чтобы вызывались afterDestroy колбеки моделей.
// переопределение возможно за счет пакета https://github.com/sgress454/sails-hook-custom-blueprints
// подробней в моем issue https://github.com/balderdashy/sails/issues/4476
// Если issue пофиксят в мою пользу, то это переопределение можно будет убрать
var _ = require('@sailshq/lodash');
module.exports = function destroyOneRecord (req, res) {
var parseBlueprintOptions = req.options.parseBlueprintOptions || req._sails.config.blueprints.parseBlueprintOptions;
@tikijian
tikijian / coffee.js.coffee
Created August 24, 2014 18:03
frontend example
window.updateKitCount = (etalon_kit) ->
# update kit total_count, if number of chosen photos > than kit
current_count = parseInt($('#js-kit-counter .count').text())
total_count = parseInt($('#js-kit-counter .all').text())
if current_count > total_count
$('#js-kit-counter .all').text(total_count + etalon_kit)
window.initSortablePhotos = (el = '#sortable') ->
# sortable photos
$(el).sortable(
@tikijian
tikijian / common_controller.rb
Created August 24, 2014 17:53
common controller from markee.ru
class Frontend::CommonController < ApplicationController
before_action :set_ig_user, except: [:auth, :login, :logout]
before_action :create_cart
# Set custom layout
layout 'frontend'
def index
@catalog_items = CatalogueItem.published.to_a
@tikijian
tikijian / part_advertisment.rb
Created August 24, 2014 17:45
PartAdvertisment model
class PartAdvertisment < ActiveRecord::Base
# fields, for sorting in view (name => order_by field)
SORTING_FIELDS = {
'Город' => 'cities.title',
'Модель' => 'transport_models.title',
' ' => ' ', # gap
'Цена' => 'price'
}
# Advertisment-related behaviour. see lib/behaviours/advertisable.rb
@tikijian
tikijian / gist:e9a8af8d6dd5907b4dcb
Created June 22, 2014 10:13
TransportAdvertisment
class TransportAdvertisment < ActiveRecord::Base
# fields, for sorting in view (name => order_by field)
SORTING_FIELDS = {
'Город' => 'cities.title',
'Пробег' => 'mileage',
'Объем' => 'capacity',
'Цена' => 'price'
}
PRICE = 100
@tikijian
tikijian / const_missing.rb
Last active December 31, 2015 16:59
Code snippet for dynamic model definition within a specific module.
# class Post < ActiveRecord::Base
# #code
# end
#
# class Backend::Post < Post # we don't want to define it in each model file.
# end
module Backend
def self.const_missing(klass)
klass = klass.to_s
@tikijian
tikijian / php_sample.php
Created December 5, 2012 08:01
php sample
<?php
//событие подмены нужной цены для покупки услуг
AddEventHandler("catalog", "OnGetOptimalPrice", 'OnGetOptimalPriceHandler');
function OnGetOptimalPriceHandler($productID)
{
//получаем id инфоблока покупаемого товара. Если это услуга, то подменяем цену.
$db_iblock = CIBlockElement::GetList(array(), array("ID" => $productID), false, false, array("IBLOCK_ID"));
$iblock = $db_iblock->Fetch();