Skip to content

Instantly share code, notes, and snippets.

View hippietrail's full-sized avatar

Andrew Dunbar hippietrail

  • Phong Nha
  • 05:12 (UTC +07:00)
View GitHub Profile
@inidamleader
inidamleader / AutoSizeText.kt
Last active May 8, 2024 10:53
Composable function that automatically adjusts the text size to fit within given constraints with optimal performance by using a binary search algorithm
// LAST UPDATE: 10 April 2024 v4.3:
// - Correction of updated density value in AutoSizeText function
package com.inidamleader.ovtracker.util.compose
import android.util.Log
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.InternalFoundationTextApi
@dovahkiin98
dovahkiin98 / AutoSizeText.kt
Created October 4, 2021 09:03
AutoSize text implementation in Jetpack Compose
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.InternalFoundationTextApi
import androidx.compose.foundation.text.TextDelegate
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@WilliamD47
WilliamD47 / save.swift
Created August 30, 2021 20:54
Save NSImage to file macOS SwiftUI
func savePNG(image: NSImage, path:String) {
let imageRep = NSBitmapImageRep(data: image.tiffRepresentation!)
let pngData = imageRep?.representation(using: .png, properties: [:])
do {
try pngData!.write(to: URL(fileURLWithPath: path))
} catch {
print(error)
}
@Eng-Fouad
Eng-Fouad / SampleMingw.kt
Created July 9, 2019 22:38
Kotlin Native Win32 GUI Sample
package sample
import kotlinx.cinterop.*
import platform.windows.*
@ExperimentalUnsignedTypes
fun WndProc(hwnd: HWND?, msg: UINT, wParam: WPARAM, lParam: LPARAM) : LRESULT
{
// This switch block differentiates between the message type that could have been received. If you want to
// handle a specific type of message in your application, just define it in this block.
@hippietrail
hippietrail / ht-search-related-tags.user.js
Last active October 11, 2015 04:57
Add a "Related Tags" module to the sidebar for Search results
@elmer-garduno
elmer-garduno / stripgutenberg.pl
Created July 25, 2012 15:51 — forked from hippietrail/stripgutenberg.pl
Strip headers/footers from Project Gutenberg texts
#!/usr/bin/perl
# stripgutenberg.pl < in.txt > out.txt
#
# designed for piping
# Written by Andrew Dunbar (hippietrail), released into the public domain, Dec 2010
# Added some other patterns to the beginning and header states
use strict;
@keeguon
keeguon / countries.json
Created April 5, 2012 11:11
A list of countries in JSON
[
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'AndorrA', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},
@mathiasbynens
mathiasbynens / unsafeWindow.user.js
Created August 13, 2011 13:21
`unsafeWindow` polyfill (for use in user scripts)
// ==UserScript==
// @name Emulate `unsafeWindow` in browsers that don’t support it.
// ==/UserScript==
// http://mths.be/unsafewindow
window.unsafeWindow || (
unsafeWindow = (function() {
var el = document.createElement('p');
el.setAttribute('onclick', 'return window;');
return el.onclick();
@TooTallNate
TooTallNate / .gitignore
Created July 9, 2011 04:05
low-level objc runtime apis
*
!*.m
!Makefile
@nichtich
nichtich / wiktionarylookup.html
Created November 12, 2010 19:10
Look up a word in Wiktionary via MediaWiki API and show the Wiktionary page
<html>
<head>
<script type="text/javascript" src="./jquery-1.4.3.min.js"></script>
<script type="text/javascript">
var baseURL = 'http://en.wiktionary.org';
function showPage(page,text) {
var sourceurl = baseURL + '/wiki/' + page;
$('#pagetitle').text(page);
$('#wikiInfo').html(text);
$('#sourceurl').attr('href',sourceurl);