Skip to content

Instantly share code, notes, and snippets.

View wcoder's full-sized avatar
🎯
Focusing

Yauheni Pakala wcoder

🎯
Focusing
View GitHub Profile
private void SetLeftDrawableWithBounds(Button button, int drawableResId, Size size, Android.Graphics.Color tintColor) {
var context = button.Context;
var drawable = DrawableCompat.Wrap(AppCompatDrawableManager.Get().GetDrawable(context, drawableResId)).Mutate();
drawable.SetBounds(0, 0, (int) context.ToPixels(size.Width), (int) context.ToPixels(size.Height));
if (tintColor != Android.Graphics.Color.Transparent) {
DrawableCompat.SetTint(drawable, tintColor);
}
button.SetCompoundDrawables(drawable, null, null, null);
@wcoder
wcoder / find-span-generic.cs
Last active July 14, 2021 15:24
Generic Xamarin.Android method to find Span in TextView for implementation custom LinkMovementMethod.OnTouchEvent
private T FindSpan<T>(TextView textView, ISpannable spannable, MotionEvent e)
where T : Java.Lang.Object
{
var x = (int)e.GetX() - textView.TotalPaddingLeft + textView.ScrollX;
var y = (int)e.GetY() - textView.TotalPaddingTop + textView.ScrollY;
var layout = textView.Layout;
int position = layout.GetOffsetForHorizontal(layout.GetLineForVertical(y), x);
var links = spannable.GetSpans(position, position, Java.Lang.Class.FromType(typeof(T)));
@wcoder
wcoder / xamarin-help.md
Last active July 14, 2021 19:37
Xamarin Q&A

Xamarin.Android

How to get Java class from C# type?

Java.Lang.Class has a special method for managed types:

Java | C# (Xamarin.Android)

@wcoder
wcoder / extend_string_format.cs
Created August 5, 2021 13:34
The example demonstrates the use of square brackets to extend the C # string.Format ()
using System;
public static class StringExtensions
{
public static string Format(this string str, params object[] parameters)
{
return string.Format(str, parameters);
}
@wcoder
wcoder / firestore.utils.ts
Last active July 31, 2022 14:18
Utility method to update more than 500 docs in Firestore using Batch. TypeScript.
import admin from 'firebase-admin';
/**
* Firestore does not accept more than 500 writes in a transaction or batch write.
*/
const MAX_TRANSACTION_WRITES = 499;
type WriteBigBatchOperationType = (batch: admin.firestore.WriteBatch) => void;
type WriteBigBatchCallbackType = (operation: WriteBigBatchOperationType) => void;
@wcoder
wcoder / ls_profiles.sh
Last active May 24, 2023 20:08
Show a list of all iOS provisioning profiles with decoded content
#!/bin/bash
PP="$HOME/Library/MobileDevice/Provisioning Profiles"
echo $PP
echo "All Provisioning Profiles:"
ls -al "$PP"
echo "Decoded Provisioning Profiles:"
@wcoder
wcoder / ya.js
Last active October 10, 2024 11:19 — forked from wildcard/ya.py
Download file from Yandex.Disk through share link for large file. Pure Node.js script
#!/usr/bin/env node
// How to
// wget http://gist.github.com/...
// chmod +x ya.js
// ./ya.js download_url path/to/directory
const https = require('https');
const { URL } = require('url');
const { spawn } = require('child_process');
@wcoder
wcoder / export-csv-to-json.js
Created October 16, 2023 18:56
Export CSV spreadsheets from Google docs and convert to JSON with formatting
#!/bin/bash
DOC_ID=''
SHEET_ID=0
TMP_FILE='temp.csv'
OUTPUT_FILE='result.json'
# export csv
curl -L "https://docs.google.com/spreadsheets/d/$DOC_ID/export?format=csv&gid=$SHEET_ID" -o $TMP_FILE