Skip to content

Instantly share code, notes, and snippets.

View codejockie's full-sized avatar

John C. Kennedy codejockie

View GitHub Profile
@codejockie
codejockie / DownloadProgressLiveData.kt
Created March 23, 2024 16:25 — forked from typebrook/DownloadProgressLiveData.kt
Observe Download manager progress using LiveData and Coroutine #android #kotlin #livedata
data class DownloadItem(
val bytesDownloadedSoFar: Long = -1,
val totalSizeBytes: Long = -1,
val status: Int,
val uri: String
)
class DownloadProgressLiveData(private val activity: Activity) :
LiveData<List<DownloadItem>>(),
CoroutineScope {
// REFERENCE UNICODE TABLES:
// http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml
// http://www.tamasoft.co.jp/en/general-info/unicode.html
//
// TEST EDITOR:
// http://www.gethifi.com/tools/regex
//
// UNICODE RANGE: DESCRIPTION
//
// 3000-303F: punctuation
@codejockie
codejockie / README.md
Created March 6, 2024 18:19 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store

@codejockie
codejockie / CSharpExtensions.cs
Last active January 30, 2024 12:45
Array Tabulator
public static class MyExtensions
{
public static void TimeAgo(this DateTime date)
{
// 1000 millisecs = 1 sec
// 60 secs = 1 min
// 60 mins = 1 hr
// 24 hrs = 1 day
var diff = DateTime.Now - date;
var millis = diff.TotalMilliseconds;
@codejockie
codejockie / Bitwise.cs
Created January 26, 2024 20:26
Use cases of bitwise operators
const byte SECURITY_CHECK_FLAG = 0b00000001;
const byte TWO_FACTOR_AUTH_FLAG = 0b00000010;
const byte JUST_A_FLAG = 0b00000100;
// Uses of Bitwise operators
void Main()
{
// 1. Storing multiple boolean flags
byte flags = 0;
// Enabling flags
@codejockie
codejockie / Program.cs
Created January 19, 2024 13:41
Using ResourceDescription to embed resource information
// https://github.com/dotnet/roslyn/issues/7791#issuecomment-394133511
var resourceDescription = new Microsoft.CodeAnalysis.ResourceDescription(
resourceFullName,
() => ProcessFile(resourceFilePath),
isPublic: true);
private static MemoryStream ProcessFile(string inFile)
{
var readers = new List<ReaderInfo>();
var resources = ReadResources(inFile);
@codejockie
codejockie / Debouncer.cs
Created January 8, 2024 15:11
A simple debouncer
using System;
using System.Threading;
public class Debouncer : IDisposable
{
private Thread thread;
private volatile Action action;
private volatile int delay = 0;
private volatile int frequency;
@codejockie
codejockie / TimeAgo.cs
Created December 29, 2023 20:58
A method to generate time elapsed since a given DateTime
void TimeAgo(DateTime date)
{
// 1000 millisecs = 1 sec
// 60 secs = 1 min
// 60 mins = 1 hr
// 24 hrs = 1 day
var diff = DateTime.Now - date;
var millis = diff.TotalMilliseconds;
var millisInDay = 86400 * 1000;
var daysInMillis = millis / millisInDay;
@codejockie
codejockie / Adapter.cs
Created December 13, 2023 21:15
Design Patterns
var hole = new RoundHole(5);
var rPeg = new RoundPeg(5);
hole.Fits(rPeg).Dump(); // True
var sm_sqpeg = new SquarePeg(5);
var lg_sqpeg = new SquarePeg(10);
//hole.Fits(sm_sqpeg); // Error: won't compile (incompatible types)
var sm_sqpeg_adapter = new SquarePegAdapter(sm_sqpeg);
var lg_sqpeg_adapter = new SquarePegAdapter(lg_sqpeg);