Skip to content

Instantly share code, notes, and snippets.

View phgrey's full-sized avatar

Sergey Semenov phgrey

View GitHub Profile
# Simple and straight variant - only using if the task will never
# be extended (almost write-only-code)
def flat_me_rube(what)
if what.is_a?(Array)
what.map {|o| flat_me_rube o } # convert all non-array element of array to array too
.reduce &:concat # and then concat them all together
else
[what] # converting itself
end
end
@phgrey
phgrey / jsx-middleware.js
Created March 13, 2017 12:41
Express js middleware for babel conversions of assets
var babel = require('babel-core');
var path = require('path');
var fs = require('fs');
//mean file exists and was not modified until last visit
function check_files(target, cb){
fs.stat(target, (err1, target_stats) => {
//could not read target file - not our buiseness
if(err1 && err1.code !== 'ENOENT') return cb(null, false);
if(target_stats && !target_stats.isFile()) return cb(null, false);
@phgrey
phgrey / enql.js
Created March 13, 2017 12:54
simple domain language for storing conditions in text fields
var _ = require('underscore'),
operators = {
'in': function(field){
var values = [];
for(var i = 1; i< arguments.length; i++)
values.push(arguments[i]);
return function(row){
var test = Array.isArray(row[field]) ? row[field] : [row[field]];
return _.intersection(test, values).length > 0;
}

Keybase proof

I hereby claim:

  • I am phgrey on github.
  • I am phgrey (https://keybase.io/phgrey) on keybase.
  • I have a public key ASDJ5CrF4uq-J5cxy1fcBZzOpnkAe3NU__NiDA-qamf-jwo

To claim this, I am signing this object:

#! /usr/bin/node
/**
* HTTP server for some data transitions Endpoint: http://XXX/compute/<request_id>
* details - https://www.corva.ai/software-engineer-interview-question/
*/
const http = require('http'),
assert = require('assert');