Skip to content

Instantly share code, notes, and snippets.

View jsuchal's full-sized avatar

Jano Suchal jsuchal

View GitHub Profile
@jsuchal
jsuchal / slovka-solver.rb
Created February 6, 2022 23:14
Slovka Solver
require 'active_support/all'
def pattern(word, candidate)
[0,1,2,3,4].map do |i|
if word[i] == candidate[i]
'X'
elsif word[i] != candidate[i] && candidate.include?(word[i])
'x'
else
'.'
require 'rubygems'
require 'bundler/setup'
require 'koala'
require 'date'
access_token = 'xxx' # fill in from https://developers.facebook.com/tools/explorer
Koala.configure do |config|
participants = {
'@ppidanic' => {shares: 0, likes: 0, statuses: 1},
'@honzajavorek' => {shares: 2, likes: 2, statuses: 2},
'@tylersiprova' => {shares: 7, likes: 10, statuses: 5},
'@jakub_lesko' => {shares: 0, likes: 0, statuses: 1},
'@ondrek' => {shares: 0, likes: 0, statuses: 1},
'@Puigcerber' => {shares: 4, likes: 7, statuses: 5},
'@OndroNR' => {shares: 0, likes: 0, statuses: 1},
'@martin_strycek' => {shares: 0, likes: 0, statuses: 2},
'@PredragToptal' => {shares: 0, likes: 0, statuses: 2},
class Point < Struct.new(:x, :y)
end
# completely different file/project
class Point
def to_string
"#{x}, #{y}"
end
end
class PaymentGatewayCallbackService
# New custom exception
TransactionFailed = Class.new(StandardError)
def callback(order_id, gateway_transaction_attributes)
order = Order.find(order_id)
transaction = order.order_transactions.create(callback: gateway_transaction_attributes)
# raise the exception when things went wrong
transaction.successful? or raise TransactionFailed
order.paid!
Painting = Struct.new(:name, :year)
def first(list, sorter = nil)
list = list.sort(&sorter) if sorter
list.first
end
def rest(list, sorter = nil)
list = list.sort(&sorter) if sorter
_, *rest = list
def solve(a)
i = 0
last_error = 0
begin
i += 1
errors1 = [
2182449 - (a[0][0] + a[0][1] + a[0][2]),
893841 - (a[1][0] + a[1][1] + a[1][2]),
1307065 - (a[2][0] + a[2][1] + a[2][2])
#!/bin/bash
VERSION="1.1.1"
PORT="9333"
PWD=`pwd`
mkdir -p ~/elasticsearch/
cd ~/elasticsearch/
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${VERSION}.zip
class Topic < ActiveRecord::Base
has_many :comments
has_one :last_comment, class_name: 'Comment'
end
class Comment < ActiveRecord::Base
belongs_to :topic
after_create :set_last_comment