Skip to content

Instantly share code, notes, and snippets.

View Mardiniii's full-sized avatar

Sebastian Zapata Mardini Mardiniii

View GitHub Profile
@Mardiniii
Mardiniii / concurrent_sudoku_solve.go
Last active April 15, 2018 16:50
Code snippet for medium post
// Solve algorithm
func Solve(grid [N][N]int) (bool, [N][N]int) {
ch := make(chan [N][N]int)
pending, row, col := pendingPositions(grid)
if !pending {
fmt.Println("Solve calls:", count)
return false, grid
}
@Mardiniii
Mardiniii / concurrent_sudoku_recursiveSolution.go
Last active April 15, 2018 16:51
Code snippet for medium post
func recursiveSolution(grid [N][N]int, ch chan [N][N]int) {
pending, row, col := pendingPositions(grid)
if !pending && CheckBoard(grid) {
ch <- grid
close(ch)
return
}
for i := 1; i <= 9; i++ {
Gist for Atom Sync-Settings plugin
@Mardiniii
Mardiniii / channels_solution.go
Created April 17, 2018 20:48
Fix race data races and race conditions with mutex and channels in Go
package main
import (
"fmt"
"sync"
)
// ChannelsSolution uses a buffered channel with capacity of one
// in order to avoid data races from the go routines trying to increase
// the counter
@Mardiniii
Mardiniii / searchFormHandler.js
Last active April 30, 2018 05:39
Code snippet for medium post
$(document).ready(function() {
function parseResponse(resultsContainer, data) {
console.log(data);
const resultsAmount = data.pages.length
$(resultsContainer).html('');
if (resultsAmount > 0) {
$.each(data.pages, function(index, page) {
appendToResults(resultsContainer, page)
setResultsTitle(resultsAmount + " results found it for: " + data.input, 'green')
@Mardiniii
Mardiniii / data_replication_problem.rb
Last active May 24, 2018 18:56
1st approach to solve data replication problem using Ruby.
require 'minitest/autorun'
# Problem
# https://softwareengineering.stackexchange.com/questions/153806/conflict-resolution-for-two-way-sync
# interface DB {
# String Get(String)
# void Set(String, String)
# []String Keys()
#
@Mardiniii
Mardiniii / srp.rb
Created May 28, 2018 20:38
Single Responsability Principle: A class should have one and only one reason to change, meaning that a class should have only one job.
# Violates SRP
class Invoice
def initialize(items, client)
@items = items
@client = client
@total = 0
end
def generate
@Mardiniii
Mardiniii / lsp.rb
Created May 28, 2018 20:44
Liskov Sustitution Principle: Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.
# Violates LSP
class Company
def hire_people
expand_the_team
end
def open_new_location
create_a_new_office
end
@Mardiniii
Mardiniii / isp.rb
Last active May 30, 2018 18:05
Interface segregation principle: A client should never be forced to implement an interface that it doesn't use or clients shouldn't be forced to depend on methods they do not use.
# Violates ISP
class Airplane
def load_luggage
end
def load_fuel
end
def take_off
end
@Mardiniii
Mardiniii / dip.rb
Last active May 30, 2018 18:17
Dependency Injection Principle: Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.
# Violates DIP
class InvoiceNotifier
def initialize(invoice)
@invoice = invoice
end
def mail_notification
InvoiceMailer.new.send(@invoice)
end