Skip to content

Instantly share code, notes, and snippets.

View barthap's full-sized avatar
Unavailable. Not responding to issues.

Bartłomiej Klocek barthap

Unavailable. Not responding to issues.
View GitHub Profile
@barthap
barthap / barbellPlatesCalculator.ts
Last active January 6, 2023 19:03
Calculates which plates to put on barbell to get desired weight
// example calculator functions
const barbellTotal = (plateWeights: Weight[]) => barbellWeight + 2 * plateWeights.reduce((a, b) => a + b, 0);
const singleDumbbellTotal = (plateWeights: Weight[]) => dumbbellWeight + 2 * plateWeights.reduce((a, b) => a + b, 0);
const doubleDumbbellTotal = (plateWeights: Weight[]) => 2 * singleDumbbellTotal(plateWeights);
const availableWeights: PlatesInventory = new Map([
// [weight, total number of plates available]
// NOTE: put number of plates -> two for each pair
[20, 2],
[12.5, 2],
@barthap
barthap / isPies.tsx
Created December 29, 2022 10:14
Typescript-refactored famous Polish Railways PKP isPies implementation
// jQuery
declare let $: any;
enum DogOptions {
DOG = 17,
ASSISTANT_DOG = 18,
GUIDE_DOG = 19,
};
/**
@barthap
barthap / vec_mem_ops.rs
Last active November 25, 2022 17:35
Rust: Vec<T> extension to move data out of it without copying.
pub trait MemOps {
fn move_and_clear(&mut self) -> Self;
}
impl<T> MemOps for Vec<T> {
/// Moves all the elememst of `self` into a new [`Vec`] instance,
/// leaving `self` empty. **No copying is performed.**
/// The memory capacity of `self` stays unchanged.
///
/// # Example
@barthap
barthap / MediaHandler.swift
Created November 16, 2022 07:24
Expo SDK 47 ImagePicker media handler modified to support Swift async-await syntax
// Copyright 2022-present 650 Industries. All rights reserved.
import ExpoModulesCore
import MobileCoreServices
import Photos
import PhotosUI
internal struct MediaHandler {
internal weak var fileSystem: EXFileSystemInterface?
internal let options: ImagePickerOptions
@barthap
barthap / react-native+0.68.2.patch
Created July 18, 2022 16:39
RN 0.68 patch to have iOS 15 detents in <Modal> component
diff --git a/node_modules/react-native/Libraries/Modal/Modal.js b/node_modules/react-native/Libraries/Modal/Modal.js
index 9140a56..1a26c51 100644
--- a/node_modules/react-native/Libraries/Modal/Modal.js
+++ b/node_modules/react-native/Libraries/Modal/Modal.js
@@ -246,6 +246,7 @@ class Modal extends React.Component<Props> {
return (
<RCTModalHostView
+ modalSheetSize={this.props.modalSheetSize}
animationType={animationType}
@barthap
barthap / README.md
Created July 5, 2022 21:57
Pretty git diff for minified JSON

How to see pretty git diff for minified JSON files

Problem: You are about to commit a change in minified, one-liner JSON file and want to see the diff.

Requirements:

  • Node.js - if you're not a JS guy, you'll need to write the pretty_json file (see below) in language of your choice
  • (Optional) colordiff - or any other tool to colorize your diffs

Here's my unix/mac solution:

@barthap
barthap / docker-rm-dangling-imgs.sh
Created December 4, 2021 09:50
Remove dangling Docker images. Useful when you often use `docker compose pull` and your disk gets clogged with old images.
#!/bin/bash
set -euo pipefail
echo "These images are gonna be removed:"
docker images -f "dangling=true"
echo
read -p "Do you want to continue? [yN]" -n 1 -r
@barthap
barthap / strip-optional.ts
Created November 27, 2021 13:15
Strip optional and undefined-type fields in typescript
type NonNullableKeys<T extends object> = {
[K in keyof T]: T[K] extends NonNullable<T[K]> ? K : never;
}[keyof T];
type NonOptionalKeys<T extends object> = {
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
}[keyof T];
type OnlyDefinedFields<T extends object> = Pick<T, NonNullableKeys<T>>;
type A = {
a: string;
@barthap
barthap / BridgeUtils.kt
Created October 28, 2021 16:44
Kotlin utils for React Native WritableMap/WritableArray
package com.barthap.rn.mlkit.ocr
import android.graphics.Point
import android.graphics.Rect
import com.facebook.react.bridge.WritableArray
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.WritableNativeArray
import com.facebook.react.bridge.WritableNativeMap
import java.lang.IllegalArgumentException
@barthap
barthap / (iosCustomSchemes)app.json
Last active June 9, 2023 22:58
An Expo config plugin for including multiple custom URI schemes into Info.plist (CFBundleSchemes)
// Usage example
{
"expo": {
"scheme": "primary scheme", // supported out of the box, but only single scheme
...
"plugins": [
...
["./withIosCustomScheme", { customScheme: "extraScheme1" }],
["./withIosCustomScheme", { customScheme: "extraScheme2" }]
]