Skip to content

Instantly share code, notes, and snippets.

View RStankov's full-sized avatar
🤖
👨‍💻

Radoslav Stankov RStankov

🤖
👨‍💻
View GitHub Profile
class App.Newsfeed.Layout
constructor: (@container, @views = [], @columnWidth = 393, @columnMargin = 16) ->
@columns = []
render: ->
count = Math.max 1, Math.floor(@container.parent().width()/(@columnWidth + @columnMargin))
return if count is @columns.length
@container.empty()
app.factory 'Profile', ($resource) ->
$resource '/a/profile', {},
update:
method: 'PATCH'
headers: {'Content-Type': undefined}
transformRequest: (resource) ->
formData = new FormData()
for key,value of resource
if resource.hasOwnProperty(key) and key[0] isnt '$'
app.factory 'Resources', ($resource) ->
(pluralName, actions = {}) ->
actions['create'] ||= {method: 'POST'}
actions['update'] ||= {method: 'PATCH'}
Resources = $resource "/a/#{pluralName}/:id/:action", {id: '@id'}, actions
Resources.save = (object, success, failure) ->
failure ||= (object, errors) -> object.errors = errors
# WidgetContainer
# top
# left
# width
# height
# kind
# holdable (polymorphic relation)
# attributes (hstore)
class Widget < ActiveRecord::Base
@RStankov
RStankov / api_exception.rb
Created July 5, 2014 11:47
Api error exeption
module ApiException
class InvalidApiKey < StandardError
end
class InvalidApiVersion < StandardError
end
class InvalidAuthenticityToken < StandardError
end
app.factory 'Resources', ($resource) ->
(pluralName, actions = {}) ->
actions['create'] ||= {method: 'POST'}
actions['update'] ||= {method: 'PATCH'}
Resources = $resource "/a/#{pluralName}/:id/:action", {id: '@id'}, actions
Resources.save = (object, success, failure) ->
failure ||= (object, errors) -> object.errors = errors
#
# Render slim templates from asset pipeline with custom helpers
# Basically this is inlined slim_assets with minor modifications
#
# Research links:
#
# http://stackoverflow.com/questions/14946634/precompile-slim-templates-using-the-rails-asset-pipeline
# https://github.com/sstephenson/sprockets/issues/218
# https://github.com/mattvague/slim_assets/blob/add_app_helpers/lib/slim_assets/slim_sprockets_engine.rb
#
app.component 'FollowButtonsContainer'
events:
'click [data-follow]': 'toggleFollowing'
toggleFollowing: (e) ->
e.preventDefault()
unless AppConfig.isLoggedIn
App.redirectToLogin ".... if we need this"
module TitleValidator
module_function
def call(object)
object.errors.add :title, :blank if object.title.blank
object
end
end
module EventNotifier
extend self
delegate :register, :register_default, :execute, to: :instance
private
def instance
@instance ||= EventNotifier::Dispatcher.new
end