Skip to content

Instantly share code, notes, and snippets.

View tuscen's full-sized avatar
🐼

Aleksey Usatov tuscen

🐼
View GitHub Profile
def conjunctionSelect obj,arg,*args
res = []
for i in obj
res << i if ([arg]+args).inject do |acc,n|
n.call(i) && acc.call(i)
end
#res << i if ([arg]+args).all? {|n| n.call(i)}
end
res
end
let compose = (...fns) => x => fns.reverse().reduce((acc, f) => f(acc), x);
let map = f => functor => functor.map(f);
let log = function() {
console.log(this);
return this;
};
let Maybe = function(x) {
this.__value = x;
let compose = (...fns) => x => fns.reverse().reduce((acc, f) => f(acc), x);
let map = f => x => x.map(f);
let log = function() {
console.log(this);
return this;
};
let toUpperCase = x => x.toUpperCase();
@tuscen
tuscen / maybe.rb
Last active August 29, 2015 14:27
Ruby implementation of something that looks like maybe monad.
class Nothing
def >> fn
self
end
def value
nil
end
end
@tuscen
tuscen / hexlet.slack.log
Last active August 29, 2015 14:28 — forked from namreg/hexlet.slack.log
почему дефолты в БД зло, Continuos Delivery
kirill.mokevnin [8:19 PM]
тут в соседнем чате спросили почему дефолты в базе зло, но по скольку это касается не только руби, предлагаю обсудить
kirill.mokevnin [8:19 PM]
тут
kirill.mokevnin [8:20 PM]
Кто согласен не согласен?
ivanlemeshev [8:21 PM]
@tuscen
tuscen / hexlet.slack.log
Last active August 29, 2015 14:28 — forked from namreg/hexlet.slack.log
про функциональный подход и стейты.
sumyuga [7:57 PM] вот такой вопрос меня последние два дня волнует:
а пишут ли веб в функциональном стиле? читал что Lisp используют для веба и даже в продакшене он себя хорошо чувствует.
просто на мой взгляд это скорее эзотерика, хотя с приходом reactjs может многое изменится, кто что думает?
kirill.mokevnin [8:05 PM]
В функциональном стиле пишут функции, а не веб
когда в любом языке программирования вы используете функцию map, вы пишите этот кусочек программы в функциональном стиле
sumyuga [8:06 PM]
ну в общем вы меня поняли )) да, есть же clojure, совсем забыл ))
@tuscen
tuscen / The Technical Interview Cheat Sheet.md
Last active August 28, 2015 05:05 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@tuscen
tuscen / bijective.rb
Last active September 19, 2015 20:49 — forked from zumbojo/bijective.rb
Simple bijective function (base(n) encode/decode)
# Simple bijective function
# Basically encodes any integer into a base(n) string,
# where n is ALPHABET.length.
# Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047
ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
# make your own alphabet using:
# (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join
class Gray_code
def self.encode number
( number ^ ( number >> 1 ) ).to_s(2)
end
def self.decode number
bin = number[0]
(number.length-1).times do |i|
bin += ( number[i+1].to_i(2) ^ bin[i].to_i(2) ).to_s(2)
@tuscen
tuscen / curry.js
Last active October 16, 2015 07:23
Function.prototype.curry = function(...args) {
let fn = this;
let f = (...restArgs) => {
if (fn.length < args.length + restArgs.length) {
args = args.concat(restArgs);
return fn.apply(this, args.slice(0, fn.length));
} else {
args = args.concat(restArgs);
return f;