Skip to content

Instantly share code, notes, and snippets.

@kurko
kurko / model_test.js
Last active December 23, 2015 19:09
Testing Ember models in a Rails app with QUnit
//= require admin/application
module("Model/Campaign");
test("simple test now", function() {
expect(1);
var store = Admin.__container__.lookup("store:main"),
campaign = store.createRecord('campaign', {id: 1}),
ad1 = store.createRecord('ad', {name: 'ad 1'}),
ad2 = store.createRecord('ad', {name: 'ad 2'}),
ad3 = store.createRecord('ad', {name: 'ad 3'});
@kurko
kurko / gist:6662513
Last active December 23, 2015 16:29
OO solutions for imperative problems

OO solutions for imperative problems

[september, 22nd 2013]

On september 17th, 2013, Aaron Cruz wrote in the Objects on Rails mailing list:

I have a very imperative problem. Something needs to be done, then something else, then something else, constantly changing state from one step to the next.

Video Import example >

Admin.RefreshableModel = function() {
var refreshable = this;
this.timer = null;
/**
* Keeps reloading a given model from the server. To stop this process, just
* kill the `timer` variable.
*/
this.reload = function(model) {
@kurko
kurko / client.hbs
Last active December 22, 2015 02:59
Ember.js bug with nested models
<h1>{{name}}</h1>
Client's name shows up fine. But campaigns don't :(
<br />
{{content.campaigns}} => <DS.ManyArray:ember374>
<br />
App.Text = DS.Model.extend({
title: DS.attr("string")
});
@kurko
kurko / controller.js
Last active December 21, 2015 12:38
Generating content for ArrayController. Returns: Uncaught TypeError: Object function () { return App.Article.createRecord({title: "my article"}); } has no method 'addArrayObserver'
App.IndexController = Ember.ArrayController.extend({
software_index: function() {
// this will use .find() later
return Ember.A([App.Text.find()]);
}.property()
});
App.PostsIndexController = Ember.ArrayController.extend();
# when I tried to start postgres, I had an error telling me there were no postgres clusters created
# so I had to create one using the `pg_createcluster` command, like the following
pg_createcluster 9.1 main --start
#after creating the cluster, it will start the server because of `--start`
#so I had to change to postgresql user
sudo su - postgres
#to change it's pasword, doing `psql -d <database_name> -U <username>
psql -d postgres -U postgres
@kurko
kurko / gist:5118248
Created March 8, 2013 17:36
Example of OOP Javascript.
$(document).ready(function() {
if ($("[name='search']").length) {
$("[name='search']").each(function() {
var search = new Search.Input(this);
search.setBindings();
});
}
});
@kurko
kurko / gist:5117251
Last active December 14, 2015 16:48
Object-Oriented Programming for defining what the system is and what it does

In a software, what matters for the end users is what the system does, not what the system is. A DVD has no value for the user unless you put it into the machine.

Architecture represents what the system is, while what it does is represented by the messages between objects, which is captured via use cases. Architecture is the form, the shape of something, in this case, the objects and the mechanisms to support them.

A good definition of use case is described as the solution to a particular problem. In Jerry Weinberg's words, "problem is the definition between the current state and the desired state". It's safe to assume that state is what the system is, which can be modified by the interaction between objects.

Objects relate to the end user, its business and its components. Classes don't. Classes are a way to represent objects, the state, but they do very poorly when trying to represent what the system does. Once you hit runtime, objects morph into total obscure forms due to the endless inte

@kurko
kurko / gist:5049820
Created February 27, 2013 17:32
Kanji project using Neural Nets: some numbers
  • 2 images, 2 neural nets
  • Input: 20 neurons each neural net
  • Hidden: 2 layers, one of 20 and another of 10
  • 10.000 epochs for training for each neural net

For 3 layers (input plus 2 hidden), 20^20^10 would be the total of calculations per training epoch. The total would be (20^20^10) multiplied by 10000 (epochs) multiplied by 2 (number of neural nets).

This takes less than a second.