Skip to content

Instantly share code, notes, and snippets.

View alexandru-calinoiu's full-sized avatar
💭
Crafting

Calinoiu Alexandru Nicolae alexandru-calinoiu

💭
Crafting
View GitHub Profile
{
"name": "AgilePool",
"description": "Testing pool from Agile Freaks",
"ticker": "AFPL",
"homepage": "https://www.agilefreaks.com"
}
@alexandru-calinoiu
alexandru-calinoiu / knights_tour.rb
Created November 4, 2018 10:04
Solve knights tour both recursively and iteratevely
# A knight is placed on a square of the board, moving according to the rules of the chess he must visit each square exactly once
N = 8
sol = Array.new(N) { Array.new(N) { :not_visited } }
def print_solution(sol)
sol.each do |line|
line.each { |char| print "#{char} " }
puts
require 'thread'
q = Queue.new
eq = Enumerator.new(-> { q.size }) do |y|
loop do
y << q.pop
end
end
doubler = Thread.new do
/**
* e2e task
*
* You should have the server up and running before executing this task. e.g. run `au run`, otherwise the
* protractor calls will fail.
*/
import { build, CLIOptions } from 'aurelia-cli';
import * as del from 'del';
import * as eventStream from 'event-stream';
import * as gulp from 'gulp';
#inspired by http://blog.martinosis.com/blog/simple-functional-strong-params-in-ruby/
require 'pp'
filter_hash = -> keys, params {
keys.map { |key| [key, params[key]] }.to_h
}.curry
params = { name: 'Ion', age: 42, pwd: 'plain', contact: { address: 'Danil Ionescu' } }
class Client
class NotificationsResponse
attr_reader :content, :error
def self.build(&block)
error = false
content = begin
yield
rescue Errno::ECONNREFUSED => exception
error = exception
@alexandru-calinoiu
alexandru-calinoiu / boot_enqueue.rb
Created April 20, 2017 12:23
Async step adapter
class Enqueue
include Dry::Monads::Either::Mixin
include IngestService::Import['enqueue']
def call(step, input, *args)
enqueue.call(step.operation_name, input, args)
Right(input)
end
end
query {
movie(id: 1) {
title
shortname
release_year
extras(first: 25) {
images {
hero {
16_9
class VideoPresenter
def initialize(db_video, facebook_video)
@facebook_id = db_video[:id]
@age = facebook_video[:age]
end
end
db_videos = [{ id: 42, name: 'Ion' }, { id: 43, name: 'Gheo' }]
facebook_videos = [{ facebook_id: 43, age: 42 }, { facebook_id: 44, age: 43 }]
@alexandru-calinoiu
alexandru-calinoiu / graph.rb
Created January 7, 2017 16:37
A very naive graph implementation in ruby
require 'pp'
class Graph
def initialize(graph = {})
@hash = graph.freeze
end
def add_vertex(node)
Graph.new(@hash.merge(Hash[node, { edges: {}.freeze }]).freeze)
end