Skip to content

Instantly share code, notes, and snippets.

@alexbeletsky
alexbeletsky / gist:3607835
Created September 3, 2012 08:15
JavaScript namespace
namespace = (function (global) {
return function (namespace) {
var splitted = namespace.split(".");
return _.reduce(splitted, function(prev, next) {
if (!prev[next]) prev[next] = { };
return prev[next];
}, global);
};
})(this);
@alexbeletsky
alexbeletsky / game.js
Created September 21, 2012 20:22
Game of Life in 50 lines and 20 specs
// http://en.wikipedia.org/wiki/Conway's_Game_of_Life
var Game = {
init: function (options) {
this.grid = new Grid(options);
},
putCell: function (x, y, state) {
this.grid.putCell(x, y, state);
@alexbeletsky
alexbeletsky / sample.js
Created October 15, 2012 10:04
MondoDB benchmark of collection.find, searching by integer of string field.
// Trying out the performance difference between look up document by interger field
// or string one.
//
// The test shows that there is either almost no difference, or look up by string field
// works even a bit better.
//
// How can it be explained?
//
// Output sample:
// benchmarking started...
@alexbeletsky
alexbeletsky / Feedback.js
Created November 8, 2012 07:38
Baby steps to Backbone - step 2 - Validation
var Feedback = Backbone.Model.extend({
url: '/feedback',
defaults: {
'email': '',
'website': '',
'feedback': ''
},
@alexbeletsky
alexbeletsky / app.js
Created November 21, 2012 19:02
Catching up Backbone change event, only once
var BaseModel = Backbone.Model.extend({
defaults: {
region: 'kiev',
operation: 'sell',
type: 'appartment',
marketSegment: 'lux'
}
});
@alexbeletsky
alexbeletsky / code.js
Created November 24, 2012 14:31
fs.writeFile - interesting side effect
// missed second parameter - buffer of byte, callback function passed instead..
fs.writeFile('uploads/' + image.name, function(err) {
if (err) {
return next(err);
}
res.redirect('back');
});
@alexbeletsky
alexbeletsky / Feedback.js
Created December 18, 2012 19:07
Backbone.View done with TDD
var Feedback = Backbone.Model.extend({
url: '/feedback',
validate: function (attrs) {
var errors = [];
if (!attrs.email || attrs.email === '') {
errors.push({name: 'email', message: 'Please fill email field.'});
}
@alexbeletsky
alexbeletsky / vagrantfile
Created December 18, 2012 19:43
Vagrant file (for node.js development)
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.ssh.forward_agent = true
config.vm.forward_port 3000, 3000
# allow for symlinks in the app folder
config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/app", "1"]
config.vm.customize ["modifyvm", :id, "--memory", 512, "--cpus", 1]
config.vm.provision :chef_solo do |chef|
@alexbeletsky
alexbeletsky / gist:5256092
Created March 27, 2013 17:08
Oak rake error
C:\Development\Projects\experiments\oak\Blog>rake
"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" "Blog.sln" /verbosity:quiet /nologo
C:\Development\Projects\experiments\oak\Blog\Blog\Blog.csproj(144,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
C:\Development\Projects\experiments\oak\Blog\Blog\Blog.csproj(144,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
C:\Development\Projects\experiments\oak\Blog\Blog.UITests\Blog.UITests.fsproj(39,3): error MSB4019: The imported project "C:\Program Files (x86)\Microsoft F#\v4.0\Microsoft.FSharp.Targets" was not found. Confirm that the p
@alexbeletsky
alexbeletsky / start.api.json
Created June 25, 2013 07:20
Response from v3 Github API, shows that `created_at` has a wrong value.
[ { id: 7744300,
name: 'Buttons',
full_name: 'alexwolfe/Buttons',
owner:
{ login: 'alexwolfe',
id: 407237,
avatar_url: 'https://secure.gravatar.com/avatar/5248e75ab0de8f30d818956c657be0f9?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png',
gravatar_id: '5248e75ab0de8f30d818956c657be0f9',
url: 'https://api.github.com/users/alexwolfe',
html_url: 'https://github.com/alexwolfe',