Skip to content

Instantly share code, notes, and snippets.

View kreshikhin's full-sized avatar
🏠
Working from home

Denis Kreshikhin kreshikhin

🏠
Working from home
View GitHub Profile
// warning! bad code style!
var z = a + b + c + d;
// correct way
var z = (function(){
return a + (function(){
return b + (function(){
return c + (function(){
return (function(){
;function Product(data, parent){
var self = this;
$.extend(self, new Model());
self.id = ko.observable("#id");
// model properties
self.title = ko.observable("#title");
self.article = ko.observable("#article");
self.brand = ko.observable("#brand");
;function Model(){
this.selected = ko.observable(false);
this.excluded = ko.observable(false);
this.changed = ko.observable(false);
this.detectChanges = ko.observable(true);
this.deactivated = ko.observable(false);
};
Model.prototype.select = function(){ this.selected(true); };
Model.prototype.unselect = function(){ this.selected(false); };
require 'zbase32'
require 'translit'
class Product
include MongoMapper::Document
@@semaphore = Mutex.new
key :url, String # ???
key :origin_url, String
$(document).ready(function(){
$('header.collection').affix();
function Page(){
var self = this;
$.extend(self, new Model());
self.fileCount = 0;
self.fileCounter = 0;
// Promise to be filled with future value
var futureValue = new Promise();
// .then() will return a new promise
var anotherFutureValue = futureValue.then();
// Promise state handlers ( must be a function ).
// The returned value of the fulfilled / failed handler will be the value of the promise.
futureValue.then({
validate :old_password_should_be_valid
validate :new_password_should_be_valid
validate :password_confirmation_should_be_valid
before_save :calculate_digest
def old_password_should_be_valid
return if self.password.nil? or not self.persisted?
if User.digest(self.old_password) != self.password_digest
errors.add(:old_password, "Текущий пароль неверен")
@kreshikhin
kreshikhin / abstract-functor.hpp
Created February 2, 2014 19:01
functor with pimpl
class AbstractFunctorImpl{public: virtual void Execute() = 0; };
template<class Object, class Method>
class FunctorImpl: public AbstractFunctorImpl{
Object obj;
Method meth;
public:
FunctorImpl(Object& obj, Method meth) : obj(obj), meth(meth) {}
void Execute(){ (obj.*meth)(); }
for (var i = 1; i <=3; ++i) {
var build_clojure_with_new_variable = function(new_variable){
return function(){
console.log(new_variable);
};
};
var clojure = build_clojure_with_new_variable(i);
setTimeout(clojure, 0);
};
var sem = make(chan int, MaxOutstanding)
func handle(r *Request) {
<-sem // Wait for active queue to drain.
process(r) // May take a long time.
sem <- 1 // Done; enable next request to run.
}
func init() {
for i := 0; i < MaxOutstanding; i++ {