Skip to content

Instantly share code, notes, and snippets.

View Killavus's full-sized avatar

Marcin Grzywaczewski Killavus

  • Wrocław, Poland
View GitHub Profile
@Killavus
Killavus / ugly_code.coffee
Last active August 29, 2015 14:04
Example of badly written code - loading photos and making it grayed after click
$(document).ready ->
photoHTML = (photo) =>
"<li><a id='photo_#{photo.id}' href='#{photo.url}'><img src='#{photo.url}' alt='#{photo.alt}' /></a></li>"
$.ajax
url: '/photos'
type: 'GET'
contentType: 'application/json'
onSuccess: (response) =>
for photo in response.photos
@Killavus
Killavus / photo.coffee
Last active August 29, 2015 14:04
Photo domain object
class Photos.Photo
constructor: (@id, @url, @alt) ->
grayscaledURL: =>
@url + ".grayscaled.jpg"
@fromJSON: (json) ->
new Photos.Photo(json.id, json.url, json.alt)
@Killavus
Killavus / backend.coffee
Created July 17, 2014 20:08
Example of Backend class for photos displaying problem
class Photos.Backend
fetchPhotos: =>
request = $.ajax(
url: '/photos'
type: 'GET'
contentType: 'application/json'
)
.then (response) =>
photos = []
for photo in response.photos
@Killavus
Killavus / gui.coffee
Last active August 29, 2015 14:04
Example of the Gui class
class Photos.Gui
constructor: (@dom) ->
photoRow: (photo) =>
$("<li><a id='photo_#{photo.id}' href='#{photo.url}'><img src='#{photo.url}' alt='#{photo.alt}' /></a></li>")
addPhoto: (photo) =>
photoNode = @photoRow(photo).appendTo(@dom)
@linkClickHandlerToPhoto(photoNode, photo)
@Killavus
Killavus / app.coffee
Created July 17, 2014 21:01
Example app for photos displaying
class Photos.App
constructor: ->
@gui = new Photos.Gui($("#photos-list"))
@backend = new Photos.Backend()
start: =>
@backend.fetchPhotos()
.done(
(photos) =>
for photo in photos
@Killavus
Killavus / initialize_photos_app.coffee
Last active August 29, 2015 14:04
Example initialiser
$(document).ready =>
# put logic about starting your app here.
app = new Photos.App()
app.start()
1 runs average:
{
"Vue": 537.9427049774677,
"Backbone": 568.1099000212271,
"Knockout": 466.13354500732385,
"Ember": 1112.9281549947336,
"Angular": 788.7256610556506,
"React": 787.7407459600363,
"Om": 552.746056986507,
"Om v": 537.1314780204557,
1 runs average:
{
"Vue": 760.9619999420829,
"Backbone": 690.1490000891499,
"Knockout": 558.2629999844357,
"Ember": 1981.3939999730792,
"Angular": 816.4939999987837,
"React": 1021.7939999711234,
"Om": 812.5769999751355,
"Om v": 880.1849999581464,
ui: (isLoaded) ->
{
true: @mappingsList
false: @spinner
}[isLoaded]()
for searchCriteriaIndex in Config.SearchCriteria
((_searchCriteriaIndex) -> that._roomOptionTestCase(_url, _searchCriteriaIndex))(searchCriteriaIndex)