Skip to content

Instantly share code, notes, and snippets.

View petrokoriakin's full-sized avatar

Petro Koriakin petrokoriakin

  • Kyiv, Ukraine
View GitHub Profile
@petrokoriakin
petrokoriakin / comments_spec.js.coffee
Created February 10, 2012 14:29
code sample describing the process of the spec initialization
describe 'Comment model', ->
beforeEach ->
@xhr = sinon.useFakeXMLHttpRequest()
@requests = []
@xhr.onCreate = (xhr) =>
@requests.push xhr
interaxt.comments = new interaxt.models.Comments()
afterEach ->
@xhr.restore
describe 'when the user is a PUBLISHER', ->
@petrokoriakin
petrokoriakin / comments_spec.js.coffee
Created February 10, 2012 14:32
code sample describing the process of the spec initialization
describe 'Comment model', ->
beforeEach ->
interaxt.SHOW_HOST = 'testhost'
@xhr = sinon.useFakeXMLHttpRequest()
@requests = []
@xhr.onCreate = (xhr) =>
@requests.push xhr
afterEach ->
@xhr.restore
describe 'when the user is a PUBLISHER', ->
@petrokoriakin
petrokoriakin / jasmine_error.txt
Created February 10, 2012 14:33
It thorows following errors when executed
Error: Invalid element to decorate
at Error (unknown source)
at [object Object].decorate (http://localhost:3000/assets/closure/goog/ui/component.js:705:11)
at new <anonymous> (http://localhost:3000/assets/closure/comment.js:277:15)
at [object Object].create (http://localhost:3000/assets/closure/main.js:24:24)
at http://localhost:3000/assets/closure/ozz.js:141:5
at [object Object].<anonymous> (http://localhost:3000/assets/closure/ozz.js:577:7)
at [object Object].handleComplete_ (http://localhost:3000/assets/closure/goog/net/xhrmanager.js:362:46)
at [object Object].handleEvent_ (http://localhost:3000/assets/closure/goog/net/xhrmanager.js:289:19)
at [object Object].<anonymous> (native)
@petrokoriakin
petrokoriakin / gist:1795054
Created February 11, 2012 01:41
collection expectation
interaxt.container.createComment 'the commment'
@result = interaxt.app.showEvent.collection$Values(20).forEach(
(comment) =>
if comment.getBody == 'the commment'
return true
)
expect(interaxt.can).toHaveBeenCalled()
expect(@result).toBeTruthy
@petrokoriakin
petrokoriakin / gist:2036694
Created March 14, 2012 14:06
server response
{
"show_event": {
"host": "pyotr_k",
"role": 100,
"key": 531412,
"token": "T1==cGFydG5lcl9pZD01MzE0MTImc2RrX3ZlcnNpb249dGJydWJ5LXRicmItdjAuOTEuMjAxMS0wNy0wNSZzaWc9OWNjYzFlMWVmOGFiN2E2MTczMjM0ZDgyNmQzYzc0NDRlZTQxYzBjOTpyb2xlPW1vZGVyYXRvciZzZXNzaW9uX2lkPTJfTVg0MU16RTBNVEotTVRJM0xqQXVNQzR4ZmpJd01USXRNRE10TVRRZ01USTZNRGc2TkRNdU1UazJNek16S3pBd09qQXdmakF1TmpZME16UXdPVFF5TWpNNWZnJmNyZWF0ZV90aW1lPTEzMzE3MzM3NzMmbm9uY2U9MC4wNjYxODI4MzkzODYwMjQ4NyZjb25uZWN0aW9uX2RhdGE9JTdCJTIycm9sZSUyMiUzQTEwMCUyQyUyMnBpZCUyMiUzQSUyMnB5b3RyX2slMjIlN0Q=",
"session_id": "2_MX41MzE0MTJ-MTI3LjAuMC4xfjIwMTItMDMtMTQgMTI6MDg6NDMuMTk2MzMzKzAwOjAwfjAuNjY0MzQwOTQyMjM5fg",
"poster": {
"updated_at": 1331726923
}
@petrokoriakin
petrokoriakin / gist:2427949
Created April 20, 2012 11:36
code sample
class AvailabilityController < ApplicationController
before_filter :set_current_customer
before_filter :update_customer_status
def statuses
statuses_collection = @current_customer.collect_statuses
render :json => {
:partnerStatuses => statuses_collection,
}
end
@petrokoriakin
petrokoriakin / gist:2427971
Created April 20, 2012 11:45
code sample
class Identity < ActiveRecord::Base
belongs_to :user
has_one :settings
has_many :text_notifiers
has_many :mail_notifiers
has_many :favorites
has_many :saved_searches
has_many :utterances, :foreign_key => :author_id
has_many :claims do
def active
@petrokoriakin
petrokoriakin / gist:3099215
Created July 12, 2012 16:39
Passing current_user into the model
#Aplication Controller
before_filter :define_current_user
def define_current_user
User.current_user = current_user
end
#User.rb (model)
class User
class << self
@petrokoriakin
petrokoriakin / gist:4171702
Created November 29, 2012 20:30
Grape Congig
# config/initializers/grape.rb
module AppstackGrapeEndpointSetup
extend ActiveSupport::Concern
module ClassMethods
include Rails.application.routes.url_helpers
def default_url_options
{host: ::Rails.application.config.action_mailer.default_url_options[:host]}
end
@petrokoriakin
petrokoriakin / ukrainian_coins
Created October 8, 2013 09:19
Українські копійки - 1,2,5,10,25,50. 1 копійку можна розміняти 1 різним способом - {1} 2 - двома різними способами {1 + 1; 2} 5 - 4 {1 + 1 + 1 + 1 + 1; 1 + 1 + 1 + 2; 1 + 2 + 2; 5} …… Скількома різними способами можна розміняти гривню (100 копійок) ?
counter = 0
a = [0, 1, 2, 5, 10, 25, 50]
7.times do | i1 |
7.times do | i2 |
7.times do | i3 |
7.times do | i4 |
7.times do | i5 |
7.times do | i6 |
7.times do | i7 |
7.times do | i8 |