Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Crafting

Calinoiu Alexandru Nicolae alexandru-calinoiu

💭
Crafting
View GitHub Profile
View agilePool.json
{
"name": "AgilePool",
"description": "Testing pool from Agile Freaks",
"ticker": "AFPL",
"homepage": "https://www.agilefreaks.com"
}
@alexandru-calinoiu
alexandru-calinoiu / knights_tour.rb
Created Nov 4, 2018
Solve knights tour both recursively and iteratevely
View knights_tour.rb
# 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
View thread_safe_queue.rb
require 'thread'
q = Queue.new
eq = Enumerator.new(-> { q.size }) do |y|
loop do
y << q.pop
end
end
doubler = Thread.new do
View e2e.ts
/**
* 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';
View function_strong_params.rb
#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' } }
View resilience.rb
class Client
class NotificationsResponse
attr_reader :content, :error
def self.build(&block)
error = false
content = begin
yield
rescue Errno::ECONNREFUSED => exception
error = exception
View boot_enqueue.rb
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
View movie.graphql
query {
movie(id: 1) {
title
shortname
release_year
extras(first: 25) {
images {
hero {
16_9
View combine.rb
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 Jan 7, 2017
A very naive graph implementation in ruby
View graph.rb
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