Skip to content

Instantly share code, notes, and snippets.

View radekkozak's full-sized avatar

Radek Kozak radekkozak

  • BONE
  • Poland
View GitHub Profile
@gmk57
gmk57 / Sending events to UI.kt
Last active February 13, 2024 15:17
Sending events to UI with Channel/Flow + custom collector (see my first comment for reasons behind it)
/**
* Starts collecting a flow when the lifecycle is started, and **cancels** the collection on stop.
* This is different from `lifecycleScope.launchWhenStarted { flow.collect{...} }`, in which case
* the coroutine is just suspended on stop.
*/
inline fun <reified T> Flow<T>.collectWhileStarted(
lifecycleOwner: LifecycleOwner,
noinline action: suspend (T) -> Unit
) {
object : DefaultLifecycleObserver {
@liamcain
liamcain / obsidian-pagebreaks.css
Created November 8, 2020 01:04
Obsidian Pagebreaks
/**
Create pagebreaks in exported Obsidian PDFs.
Example:
# Heading 1
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
@DaveThw
DaveThw / install_ruby.sh
Last active July 1, 2020 06:59 — forked from blacktm/install_ruby_rpi.sh
A Bash script to install Ruby, using rbenv/ruby-build, on Ubuntu/Debian and derivatives
#!/bin/bash
# ------------------------------------------------------------------------------------------------
# Installs Ruby using rbenv/ruby-build - can be used multiple times, to install different versions
#
# Download and run locally:
# wget git.io/inst_ruby -O install_ruby.sh && chmod a+x install_ruby.sh
# ./install_ruby.sh 2.6.6
#
# Run from the web:
set myBibFile to "/Users/zhope/Dropbox/Sundry/Library.bib"
if myBibFile exists then
set currentBibs to do shell script "/usr/local/bin/pandoc-citeproc --bib2json " & quoted form of myBibFile & " | /usr/local/bin/jq -r ' .[] | \"\\(.id)\"'"
set currentBibs to paragraphs of currentBibs
end if
set bibFile to POSIX file myBibFile
my write_to_file("", bibFile, true)
@derickfay
derickfay / sk2c single note templated.applescript
Created March 9, 2019 23:49
Export selected Skim notes to the clipboard using native Skim templates
(* EXPORT SELECTED NOTES TO THE CLIPBOARD
(no longer) requires hackademic URL handler from github user smargh
entirely rewritten to take advantage of Skim's built-in templating
2019-03-10 by derickfay
*)
property LF : (ASCII character 10)
@derickfay
derickfay / export skim notes to markdown on clipboard sorting by color.applescript
Last active June 21, 2019 17:19
export skim notes to markdown on clipboard sorting by color.applescript
(* EXPORT ALL SKIM NOTES TO THE CLIPBOARD
(no longer) requires hackademic URL handler from github user smargh
entirely rewritten to take advantage of Skim's built-in templating
2016-06-26 by derickfay
2019-02-09 updated to group notes by color
*)
property LF : (ASCII character 10)
tell application "Bookends"
set theIDs to «event ToySRUID» "Selection"
repeat with theID in paragraphs of theIDs
tell front library window
try
set myRefs to (publication items whose id is theID)
set myItem to first item of myRefs
set thePath to path of attachment items of myItem
tell application "Bookends"
tell front library window
set theIDs to get id of publication items of group item "Unlinked Attachments"
repeat with theID in theIDs
try
set myRefs to (publication items whose id is theID)
set myItem to first item of myRefs
set {theKey, thePath, theAuthor, theEditor, theTitle} to {citekey, path of attachment items, authors, editors, title} of myItem
if theAuthor = "" then set theAuthor to theEditor
set theRIS to format myItem using "RIS.fmt"
@zverhope
zverhope / be_orphaned_files.scpt
Last active December 16, 2022 08:24
Find orphaned files in Bookends, whether with hierarchical or flat folder structure, and then move to Orphans folder
set theFolder to (path to home folder as text) & "Library:Mobile Documents:iCloud~com~sonnysoftware~bot:Documents"
set BEList to {}
set orphanList to {}
set FinderList to {}
set pathList to {}
set od to AppleScript's text item delimiters
tell application "Finder"
-- create a list of the name of every file in the folder you've set
set FinderList to every file of folder theFolder as alias list
@JoseAlcerreca
JoseAlcerreca / Event.kt
Created April 26, 2018 10:25
An event wrapper for data that is exposed via a LiveData that represents an event.
/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
*/
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.