Skip to content

Instantly share code, notes, and snippets.

View id-ilych's full-sized avatar

Ilya Denisov id-ilych

View GitHub Profile
@id-ilych
id-ilych / karafka_puma_graceful_shutdown.rb
Last active July 6, 2023 13:51
Configure puma to gracefully shutdown karafka producer on stop
require 'puma/plugin'
module GracefulShutdown
# Configures puma to gracefully shutdown karafka producer
# Related documentation: https://karafka.io/docs/Producing-messages/#producer-shutdown
# Usage:
#
# (at the end of config/puma.rb)
#
# GracefulShutdown::SetupPuma.new.call(self)
@id-ilych
id-ilych / kafka_producer_client.rb
Created May 5, 2023 11:14
Dummy client to use in specs for apps using waterdrop gem to produce kafka messages
# Spec producer client used to buffer messages that we send out in specs
class KafkaProducerClient < WaterDrop::Producer::DummyClient
attr_accessor :messages
# Sync fake response for the message delivery to Kafka, since we do not dispatch anything
class SyncResponse
# @param _args Handler wait arguments (irrelevant as waiting is fake here)
def wait(*_args)
false
end
@id-ilych
id-ilych / geometry.js
Last active April 13, 2024 09:34
Functions to build a convex hull and minimum bounding box for a given set of points
const geometry = {};
// for all the functions below, assume screen coordinates: the x-axis is rightward, the y-axis is downward
// finds a point with the lowest vertical position (leftmost wins in case of a tie)
geometry.lowestPoint = (points) => points.reduce((lowest, point) => {
if (point[1] > lowest[1]) {
return point;
}
if (point[1] === lowest[1] && point[0] < lowest[0]) {
/* eslint-disable no-console */
const config = require('../graphql-schema-linter.config.js')
// Aaa prefix is used to put this rule on top of the list
// which is required for excludes to work properly
// This rule allows to add exclusions (defined in graphql-schema.config.js)
function AaaWithExcludes (context) {
const stack = []
@id-ilych
id-ilych / .jsx
Last active June 24, 2019 15:42
React Native "ref" playground
import * as React from 'react';
import { Button, Text, TextInput, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
// WebSocketFactory.d.ts
export function newWebSocket( url: String ): WebSocket;
// WebSocketFactory.js
exports.newWebSocket = function( url ) {
if (CC_JSB) {
return new WebSocket( url, [], "ssl_cert.pem" );
}
else {
return new WebSocket( url );
build_prompt () {
local lhs=$1
local rhs=$2
local save='\e[s' # Save cursor position
local rest='\e[u' # Restore cursor to save point
# Strip ANSI commands before counting length
# From: https://www.commandlinefu.com/commands/view/12043/remove-color-special-escape-ansi-codes-from-text-with-sed
rhs_stripped=$(sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" <<<"$rhs")
echo "\[${save}\e[${COLUMNS:-$(tput cols)}C\e[${#rhs_stripped}D${rhs}${rest}\]${lhs}"
}
@id-ilych
id-ilych / logcat.log
Created April 9, 2019 13:01
Cocos Creator 2.0.9 Android `wss://` issue
04-09 13:31:07.813: D/WebSocket.cpp(20710): WebSocket thread start, helper instance: 0xd19ad4e0
04-09 13:31:07.820: D/WebSocket.cpp(20710): scheme: ws, host: echo.websocket.org, port: 0, path:
04-09 13:31:07.926: D/WebSocket.cpp(20710): WebSocket (0xce292b00) Unhandled websocket event: 32
04-09 13:31:07.926: D/WebSocket.cpp(20710): WebSocket (0xce292b00) Unhandled websocket event: 29
04-09 13:31:08.166: D/WebSocket.cpp(20710): WebSocket (0xce292b00) Unhandled websocket event: 24
04-09 13:31:08.277: D/WebSocket.cpp(20710): WebSocket (0xce292b00) Unhandled websocket event: 2
04-09 13:31:08.277: D/WebSocket.cpp(20710): onConnectionOpened...: 0xce292b00, client protocols: , server selected protocol:
04-09 13:31:08.286: D/WebSocket.cpp(20710): Safely done, msg(2)!
04-09 13:31:08.287: D/WebSocket.cpp(20710): msg(2) append: 0 + 4 = 4
04-09 13:31:08.287: D/WebSocket.cpp(20710): msg(2) was totally sent!
@id-ilych
id-ilych / Fail.java
Created April 7, 2019 17:36
Contest dumb fail I've made :(
// what I carelessly wrote
BigInteger value = ciphertext[0];
BigInteger p, o;
if (value.equals(ciphertext[1])) { // << here's careless fail. Never should've done it
BigInteger[] factors = factorize(value);
p = factors[0];
o = factors[1];
} else {
p = gcd(value, ciphertext[1]);
o = value.divide(p);
#include <functional>
#include <optional>
#include <vector>
#include <iostream>
template<typename T>
using Receiver = std::function<void( T )>;
template<typename T, typename U>
using Transformer = std::function<U( T )>;