Skip to content

Instantly share code, notes, and snippets.

View RinatMullayanov's full-sized avatar

Rinat Mullayanov RinatMullayanov

View GitHub Profile
@RinatMullayanov
RinatMullayanov / provider_factory_service_Angular_source_code.js
Last active August 29, 2015 14:19
https://github.com/angular/angular.js/blob/v1.3.15/src/auto/injector.js#L651 Provider is primary. Factory is wrapper over provider. Service is wrapper over factory.
////////////////////////////////////
// $provider
////////////////////////////////////
function supportObject(delegate) {
return function(key, value) {
if (isObject(key)) {
forEach(key, reverseParams(delegate));
} else {
return delegate(key, value);
@RinatMullayanov
RinatMullayanov / bem-naming.css
Last active August 29, 2015 14:19
BEM naming in CSS and HTML
.some-block {} /*block*/
.some-block__element {} /*element*/
.some-block_size_large {} /*modificator of block*/
.some-block__element_size_large {} /*modificator of element*/
/*
Block may contains another blocks and elements.
Element may contains another blocks and elements.
*/
@nolanlawson
nolanlawson / protips.js
Last active February 4, 2024 18:06
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
var Circle = function() {};
Circle.prototype = {
area: function() {
return Math.PI * this.radius * this.radius;
},
grow: function() {
this.radius++;
},
shrink: function() {
this.radius--;
@patrickarlt
patrickarlt / build.sh
Last active March 25, 2020 04:42
ES 7 async/await demo!
babel github-es6.js -o github.js --optional runtime --experimental
@RinatMullayanov
RinatMullayanov / modern_inheritance.js
Created August 28, 2014 08:32
Sample modern prototype inheritance in Javacript
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
function Product(name, price) {
this.name = name;
this.price = price;
if (price < 0)
throw RangeError('Cannot create product ' +
name + ' with a negative price');
return this;
}
@staltz
staltz / introrx.md
Last active May 7, 2024 09:38
The introduction to Reactive Programming you've been missing
@RinatMullayanov
RinatMullayanov / sample_inheritance.js
Last active August 29, 2015 14:01
Наследование(inheritance) на основе метода предложенного Дугласом Крокфордом
// http://javascript.crockford.com/prototypal.html
// базовый вариант наследования предложенный Дугласом Крокфордом
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
// ECMASсript 3
// продвинутый вариант того что предложил Дуглас Крокфорд
@phungnc
phungnc / provider, factory, service source code in Angular.js
Created December 6, 2013 08:15
the difference between service, factory, provider in angular.js
// Below is the source code pick from angular.js
// Read source code help us more clearer
// the difference between service, factory, provider
function provider(name, provider_) {
if (isFunction(provider_) || isArray(provider_)) {
provider_ = providerInjector.instantiate(provider_);
}
if (!provider_.$get) {
throw Error('Provider ' + name + ' must define $get factory method.');
}
@satyrius
satyrius / exercise-36.go
Created October 23, 2013 06:18
A Tour of Go. Exercise: Slices. Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers. When you run the program, it will display your picture, interpreting the integers as grayscale (well, bluescale) values. The choice of image is up to you. Interesting functions include x^y, (x+y)/2…
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
res := make([][]uint8, dy)
for y := range res {
res[y] = make([]uint8, dx)
for x := range res[y] {
res[y][x] = uint8((x + y) /2)