Skip to content

Instantly share code, notes, and snippets.

@mckomo
mckomo / counter.rb
Created July 21, 2014 16:50
Ruby counter
class Counter
def initialize
@counter = "0"
end
def hit
@counter.replace( increment_string( @counter ) ); @counter.dup
end
@mckomo
mckomo / pretty_json.rb
Last active August 29, 2015 14:07
Liquid filter suited for Jekyll that generates pretty JSON output.
module Jekyll
module PrettyJsonFilter
def pretty_json(input)
begin
JSON.pretty_generate(input)
rescue JSON::GeneratorError => e
"Error: #{e}."
end
end
@mckomo
mckomo / missing_integer.rb
Created December 27, 2014 13:02
Codility – MissingInteger
def solution(a)
n = a.length
r = (1 .. n).to_a
diff = r - a
if diff.empty?
return n+1
end
@mckomo
mckomo / roulette.cpp
Created February 16, 2015 14:27
Roulette progression strategy simulator
#include <random>
#include <iostream>
#define START_CREDITS 1000
#define PROGRESSION_RATION 2
#define MINIMAL_BET 0.5
bool is_odd(int result)
{
return result % 2 == 1;
@mckomo
mckomo / curry.js
Last active July 5, 2016 19:12
JS implementation of curry function with some ES6 sugar.
function curry(fn) {
const arity = fn.length;
const curring = function() {
var args = asArray(arguments);
if (args.length >= arity) {
return fn(... args);
const list = ['m', 'c', 'k', 'o', 'm', 'o']
const reverse = (list) => {
if (list.length == 0) return [];
let first = list.splice(0, 1);
return reverse(list).concat(first);
}
const eventStub = value => ({
stopPropagation: () => {},
preventDefault: () => {},
persist: () => {},
target: {
value,
checked: value,
},
...value,
});
Test Suite 'All tests' started at 2017-08-20 15:59:02.890
Test Suite 'AirMonitorBotPackageTests.xctest' started at 2017-08-20 15:59:02.890
Test Suite 'WebhookControllerTests' started at 2017-08-20 15:59:02.890
Test Case '-[AppTests.WebhookControllerTests test_get_without_verification_params]' started.
/Users/mckomo/Projects/AirMonitor/AirMonitorBot/Tests/AppTests/WebhookControllerTests.swift:15: error: -[AppTests.WebhookControllerTests test_get_without_verification_params] : failed - expected to equal <badRequest>, got <ok>
Test Case '-[AppTests.WebhookControllerTests test_get_without_verification_params]' failed (0.073 seconds).
Test Suite 'WebhookControllerTests' failed at 2017-08-20 15:59:02.963.
Executed 1 test, with 1 failure (0 unexpected) in 0.073 (0.073) seconds
Test Suite 'AirMonitorBotPackageTests.xctest' failed at 2017-08-20 15:59:02.963.
@mckomo
mckomo / extract_string.rb
Last active June 5, 2018 10:34
Kata extract_strings.rb
def extract_strings(object)
# TODO
end
errors = {
options: {
frequency_limits: [
{
time_unit: [
'must be one of: day, week, month'