Skip to content

Instantly share code, notes, and snippets.

@sashaegorov
sashaegorov / multipleinheritance.py
Created April 27, 2023 19:32 — forked from litzomatic/multipleinheritance.py
Understanding super and multiple inheritance in Python.
View multipleinheritance.py
class Bar(object):
def __init__(self, bar='bar', *args, **kwargs):
self.bar = bar
super(Bar, self).__init__(*args, **kwargs)
class Foo(object):
def __init__(self, foo='foo', *args, **kwargs):
self.foo = foo
super(Foo, self).__init__(*args, **kwargs)
@sashaegorov
sashaegorov / prime.rb
Created January 11, 2019 10:05
Prime numbers with Ruby endless range
View prime.rb
factors = -> (n) { (1..n).select{|x| n % x === 0} }
prime = ->(n){ (factors === n) === [1,n] }
(1..).lazy.select(&prime).take(10).to_a
@sashaegorov
sashaegorov / es60_tags_search.js
Created January 22, 2018 11:55
ElasticSearch setup for searching tags
View es60_tags_search.js
// DELETE my-index
// PUT my-index
{
"settings": {
"analysis": {
"analyzer": {
"auto_completion_analyzer": {
"type": "custom",
"filter": [
@sashaegorov
sashaegorov / sleep.js
Created December 25, 2017 19:26
Await and Sleep
View sleep.js
function sleep (time, arg) {
console.log(`Sleep started for ${arg}...`);
return new Promise((resolve) => {
setTimeout(() => {
resolve(arg);
}, time);
});
}
await sleep(1000, this.report.pagination.pageNumber)
@sashaegorov
sashaegorov / ar_arel_wrapper.rb
Created February 22, 2017 10:34 — forked from tokland/ar_arel_wrapper.rb
Simple wrapper over arel
View ar_arel_wrapper.rb
require 'active_record'
require 'arel'
# Ruby-like syntax in AR conditions using the underlying Arel layer (Rails >= 3.0).
#
# What you would usually write like this:
#
# User.where(["users.created_at > ? AND users.name LIKE ?", Date.yesterday, "Mary"])
#
# can now be written like this (note those parentheses required by the operators precedences):
@sashaegorov
sashaegorov / .eslintrc
Created September 18, 2016 16:42 — forked from elycruz/.eslintrc
.eslintrc as yaml file
View .eslintrc
# --------------------------------------------------------------------------------------------------------------------- #
# Conversion of http://eslint.org/docs/rules/ to an actual .eslintrc file:
# Copied: 04/01/2015
# Updated to yaml format: 05/15/2015
# Copied by: Ely De La Cruz <elycruz@elycruz.com>
# --------------------------------------------------------------------------------------------------------------------- #
# --------------------------------------------------------------------------------------------------------------------- #
# Environemnt Types:
# --------------------------------------------------------------------------------------------------------------------- #
@sashaegorov
sashaegorov / node-cluster-messaging.js
Created May 14, 2016 14:11 — forked from jpoehls/node-cluster-messaging.js
Simple message passing between cluster master and workers in Node.js
View node-cluster-messaging.js
var cluster = require('cluster');
if (cluster.isWorker) {
console.log('Worker ' + process.pid + ' has started.');
// Send message to master process.
process.send({msgFromWorker: 'This is from worker ' + process.pid + '.'})
// Receive messages from the master process.
@sashaegorov
sashaegorov / ruby_private_inheritance.rb
Created January 13, 2016 16:53
Ruby private inheritance
View ruby_private_inheritance.rb
class Parent
attr_accessor :a, :b
def initialize(a)
@a = a
end
private
def set_b
@b = 'b'
end
end
@sashaegorov
sashaegorov / cs-jq-plugin-template.coffee
Created October 30, 2015 10:02 — forked from rjz/cs-jq-plugin-template.coffee
Coffeescript jQuery Plugin Class Template
View cs-jq-plugin-template.coffee
# A class-based template for jQuery plugins in Coffeescript
#
# $('.target').myPlugin({ paramA: 'not-foo' });
# $('.target').myPlugin('myMethod', 'Hello, world');
#
# Check out Alan Hogan's original jQuery plugin template:
# https://github.com/alanhogan/Coffeescript-jQuery-Plugin-Template
#
(($, window) ->