Skip to content

Instantly share code, notes, and snippets.

View Plotist's full-sized avatar
:shipit:

Oleg Vodolazsky Plotist

:shipit:
View GitHub Profile
@Plotist
Plotist / json.rb
Created May 18, 2021 20:54
Forces automatic date parsing for JSON inside specific module (SomeapiService)
# lib/someapi_service/json.rb
module SomeapiService
class << ::ActiveSupport::JSON
# Exposes ActiveSupport::JSON decoding regardless of global ActiveSupport.parse_json_times.
# See https://api.rubyonrails.org/classes/ActiveSupport/JSON.html for more info.
#
# @note Only available in the context of SomeapiService module
def open_decode(json)
Time.use_zone('UTC') do
@Plotist
Plotist / params_sanitizer.rb
Last active May 18, 2021 20:55
Ensures that provided timezones are respected while converting UTC/Unrecognized timezones into zone set by Time.zone
module Api::ParamsSanitizer
def sanitize_param_timezones
params.merge!(traverse_params(params.to_unsafe_h))
end
def traverse_params(params)
params.map { |k, v| traverser(k, v) }.to_h
end
@Plotist
Plotist / wacom-conf
Last active July 23, 2022 01:56
Wacom Intuos Pro L configuration script for Krita
#!/bin/zsh
# This should work out of the box on debian based systems. See last comment for sysvinit specific adjustments
# required libs:
# - xsetwacom
# - xinput
# Attach tools to specific monitor (use port name e.g. "VGA1" for non NVIDIA drivers)
@Plotist
Plotist / cyclic_rotation.rb
Last active December 26, 2020 21:21
<codility> CyclicRotation
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(a, k)
# write your code in Ruby 2.2
result = []
n = a.length
raise ArgumentError.new(
"Invalid argument type"
) if !a.is_a?(Array) || !k.is_a?(Integer)
@Plotist
Plotist / frog_jump.rb
Last active December 26, 2020 21:20
<codility> Frog Jump
def solution(x, y, d)
raise ArgumentError.new(
"Invalid argument type"
) if !x.is_a?(Integer) || !y.is_a?(Integer)
raise ArgumentError.new(
"y should be less or equal to 1 000 000 000"
) if y > 1000000000
raise ArgumentError.new(
"x should be less then y and greater then 0"
) if x > y || x < 1
@Plotist
Plotist / edit_distance.rb
Last active December 17, 2020 02:59
Edit distance calculation [ Ruby ]
module Analyzer
class EditDistance
attr_accessor :word1, :word2, :matrix
def initialize(word1, word2)
@word1 = word1
@word2 = word2
@w1l = @word1.length
@w2l = @word2.length
@matrix = Array.new(@w1l+1){Array.new(@word2.length+1){|i| 0}}
@Plotist
Plotist / edit_distance.cpp
Last active December 17, 2020 03:00
Edit distance calculation [ C++ ]
#include <iostream>
#include "edit_distance.h"
using namespace std;
// public
EditDistance::EditDistance(char *string1, char *string2){
s1 = string1;
s2 = string2;
rows = strlen(s1)+1;
@Plotist
Plotist / binary_gap.rb
Last active December 26, 2020 21:19
<codility> Binary gap
def solution(n)
# n - integer to calculate binary gap on, constrained
raise ArgumentError.new(
"Expected n to be an integer 'n' where 1 < n < 2,147,483,647"
) if !n || !n.is_a?(Integer) || n < 1 || n > 2147483647
max_length = 0
occurance_count = 0
n.to_s(2).split('').each do |bit|
@Plotist
Plotist / natural_rec_multiplication.rb
Last active December 17, 2020 02:51
Natural numbers recursive multiplication
def mult(a,b)
return 0 if a == 0 || b == 0
if a == 1
b
else
b+mult(a-1,b)
end
end
@Plotist
Plotist / NestedScrollExample.jsx
Last active April 28, 2020 17:22
Nested (parallax) scrolling in Web with React HOC
import React from "react";
import "./withNestedScrolling";
// On scrolling down comment-list-navigation will dissapear with slideOutUp animation
// On scrolling up comment-list-navigation will reappear with slideInDown animatio
const CommentsList = props => {
const { nestedScrollTargetHeight, scrollTargetRef, nestedScrollTargetRef } = props;
return (