Skip to content

Instantly share code, notes, and snippets.

View kysely's full-sized avatar
👓

Radek Kyselý kysely

👓
View GitHub Profile
@kysely
kysely / super.json
Created September 21, 2021 11:27
super.json
{
"profiles": {
"communication/send-sms": {
"version": "1.0.1",
"defaults": {
"SendMessage": {
"providerFailover": true
}
},
"priority": [
@kysely
kysely / watch-event-loop-delay.ts
Created January 8, 2021 11:42
Watches event loop delay and alerts when `alertPredicate` evaluates to true.
import { monitorEventLoopDelay } from 'perf_hooks';
/**
* Watches event loop delay and alerts when `alertPredicate` evaluates to true.
*
* Requires Node 11.10+
*
* WARNING: The process might be affected if it already has delayed event loop
* and `checkEveryMs` with `samplingResolutionInMs` are set too low.
*
@kysely
kysely / machine.js
Last active April 22, 2020 13:13
Generated by XState Viz: https://xstate.js.org/viz
function generateTransaction(
toProgressEvent = "",
toSuccessEvent = "",
failedAttemptEvent = "",
failedEvent = "MarketCancels"
) {
return {
initial: "Idle",
states: {
@kysely
kysely / ws.ts
Created January 31, 2020 15:28
WS.ts
import * as WebSocket from 'ws'
import { Component, ComponentOptions } from '../base'
import { setOurInterval, OurInterval, getRetryAfter } from '../utils'
import { ClientRequest, IncomingMessage } from 'http'
export interface WSIntegrationBaseOptions extends ComponentOptions {
socketUrl?: string
}
/**
@kysely
kysely / fib.hs
Created April 25, 2018 01:41
Fibonacci Sequence Generator
fib :: Int -> [] Integer
fib n = next [0, 1]
where
next l
| length l == n = l
| otherwise = next (l ++ [last(init l) + last l])
@kysely
kysely / MockAsyncIOTCPServer.py
Created January 10, 2018 19:23
Simple mock asyncio TCP server; useful for testing (keywords: pytest-aiotcp, pytest-tcp, tcpserver, asyncio, pytest)
#!/usr/bin/env python3
import asyncio
import logging
logging.basicConfig(level=logging.INFO)
def _DEFAULT_REPLY_CB(message):
return message
class MockTCPServer:
@kysely
kysely / touchOver.coffee
Last active April 10, 2018 04:27
Alternative to MouseOver event that works on touch devices in Framer prototypes
Layer::isTouchOver = ( touchPoint = {x: 0, y: 0} ) ->
touchX = touchPoint.x
touchY = touchPoint.y
if touchX < @screenFrame.x || touchX > (@screenFrame.x+@width) || touchY < @screenFrame.y || touchY > (@screenFrame.y+@height)
false
else
true
# Listen to ›Pan‹ event on some parent and
@kysely
kysely / includeJSLibrary.coffee
Last active May 15, 2017 15:45
Ensure the user always gets the JS dependency library for your module. Function will first look for the library locally; then falls to online loading (in case the user didn't download the dependency).
# ADD THE insertScript FUNCTION TO YOUR MODULE'S CODE
insertScript = (localScript, webScript, name = 'JavaScript Library') ->
try
lib = Utils.domLoadDataSync localScript
console.log "%c#{name} Successfully Included Locally", "background: #DDFFE3; color: #007814"
catch e
try
lib = Utils.domLoadDataSync webScript
console.log "%c#{name} Successfully Included from Web", "background: #DDFFE3; color: #007814"
catch e
@kysely
kysely / rgbToHex.coffee
Created February 28, 2017 20:43
Function that will find RGB color(s) in string and convert it (them) to HEX format (also accepts Color object)
# FUNCTIONS FOR YOUR PROTOTYPE —————————
getHex = (ch) ->
hexa = ch.toString(16)
return if hexa.length is 1 then "0#{hexa}" else hexa
rgb = ([r, g, b]) -> "##{getHex(r)}#{getHex(g)}#{getHex(b)}"
hexColor = ( rgbColor ) ->
findColorsRegex = /(rgba\(|rgb\()([\d\s,]+)(\))/g
separateValsRegex = /([\d]+)/g
@kysely
kysely / camelCase.coffee
Last active February 23, 2017 19:45
Convert dash-separated or underscore_separated string to camelCase
# String prototype extension
String::toCamel = () -> @replace( /([-_][a-z])/g, ($1) -> return $1.toUpperCase().replace(/[-_]/,'') )
console.log "font-size".toCamel() # Outputs "fontSize"