Skip to content

Instantly share code, notes, and snippets.

View ggoraa's full-sized avatar
💭
🛞 Making something revolutionary

Voltangle ggoraa

💭
🛞 Making something revolutionary
View GitHub Profile

A metatable can be defined like

local t = setmetatable({}, {
  __tostring = function() return 'custom tostring behavior!' end
})

Here are the metamethods that you can define, and their behavior

Operators

//
// Router.swift
// Routing
//
//
import SwiftUI
enum Views: CaseIterable {
case main
@c-villain
c-villain / Frame.swift
Created December 30, 2021 21:13
Must-have SwiftUI frame extensions
extension View {
// MARK: Vertical Center
func vCenter() -> some View {
self
.frame(maxHeight: .infinity, alignment: .center)
}
// MARK: Vertical Top
func vTop() -> some View {
@LeviSnoot
LeviSnoot / discord-timestamps.md
Last active June 14, 2024 21:27
Discord Timestamp Syntax

Discord Timestamps

Discord timestamps can be useful for specifying a date/time across multiple users time zones. They work with the Unix Timestamp format and can be posted by regular users as well as bots and applications.

The Epoch Unix Time Stamp Converter is a good way to quickly generate a timestamp. For the examples below I will be using the Time Stamp of 1543392060, which represents November 28th, 2018 at 09:01:00 hours for my local time zone (GMT+0100 Central European Standard Time).

Formatting

Style Input Output (12-hour clock) Output (24-hour clock)
Default <t:1543392060> November 28, 2018 9:01 AM 28 November 2018 09:01
@BrentMifsud
BrentMifsud / Image+Data.swift
Last active March 14, 2024 16:19
SwiftUI Image from data
import Foundation
import SwiftUI
#if canImport(UIKit)
import UIKit
#elseif canImport(AppKit)
import AppKit
#endif
extension Image {
/// Initializes a SwiftUI `Image` from data.
@WorldDownTown
WorldDownTown / ContrastRatio.swift
Last active December 28, 2023 06:01
Get contrast ratio between two UIColors
// https://www.w3.org/TR/WCAG20/
// Contrast ratio
// Relative luminance
import UIKit
extension UIColor {
convenience init(hex: UInt, alpha: CGFloat = 1) {
self.init(red: CGFloat((hex & 0xff0000) >> 16) / 255,
green: CGFloat((hex & 0x00ff00) >> 8) / 255,
@seanf
seanf / process.kt
Created August 23, 2017 02:12
Execute process from Kotlin
import java.lang.ProcessBuilder.Redirect
import java.util.concurrent.TimeUnit
fun String.runCommand(workingDir: File? = null) {
val process = ProcessBuilder(*split(" ").toTypedArray())
.directory(workingDir)
.redirectOutput(Redirect.INHERIT)
.redirectError(Redirect.INHERIT)
.start()
if (!process.waitFor(10, TimeUnit.SECONDS)) {
@lzhoucs
lzhoucs / idea-reset-evaluation.sh
Last active February 28, 2023 19:19
reset intellij idea 14 evaluation
#!/bin/bash
echo "removing evaluation key"
rm ~/.IntelliJIdea15/config/eval/idea15.evaluation.key
# for mac go to: /Users/username/Library/Preferences/IntelliJIdea2016.3/eval/idea163.evaluation.key
echo "resetting evalsprt in options.xml"
sed -i '/evlsprt/d' ~/.IntelliJIdea15/config/options/options.xml
# for mac go to: /Users/lzhoucs/Library/Preferences/IntelliJIdea2016.3/options/options.xml
@fabiomsr
fabiomsr / ByteArray.kt
Last active April 24, 2024 08:41
ByteArray and String extension to add hexadecimal methods in Kotlin
private val HEX_CHARS = "0123456789ABCDEF".toCharArray()
fun ByteArray.toHex() : String{
val result = StringBuffer()
forEach {
val octet = it.toInt()
val firstIndex = (octet and 0xF0).ushr(4)
val secondIndex = octet and 0x0F
result.append(HEX_CHARS[firstIndex])
@jpillora
jpillora / INSTALL.md
Last active October 25, 2023 05:03
Headless Transmission on Mac OS X
  1. Go to https://developer.apple.com/downloads/index.action and search for "Command line tools" and choose the one for your Mac OSX

  2. Go to http://brew.sh/ and enter the one-liner into the Terminal, you now have brew installed (a better Mac ports)

  3. Install transmission-daemon with

    brew install transmission
    
  4. Copy the startup config for launchctl with

    ln -sfv /usr/local/opt/transmission/*.plist ~/Library/LaunchAgents