Skip to content

Instantly share code, notes, and snippets.

@ole
ole / RelativeSizeLayout.swift
Last active December 30, 2024 16:48
A SwiftUI layout and modifier for working with relative sizes ("50 % of your container"). https://oleb.net/2023/swiftui-relative-size/
import SwiftUI
extension View {
/// Proposes a percentage of its received proposed size to `self`.
///
/// This modifier multiplies the proposed size it receives from its parent
/// with the given factors for width and height.
///
/// If the parent proposes `nil` or `.infinity` to us in any dimension,
/// we’ll forward these values to our child view unchanged.
@wendreof
wendreof / build.gradle
Created September 25, 2021 16:42
7-How-to-Safely-Build-Assigned-Flutter-App-with-GitHub-Actions
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
@importRyan
importRyan / whenHovered.md
Last active March 2, 2025 12:00
Reliable SwiftUI mouse hover

Reliable mouseEnter/Exit for SwiftUI

Kapture 2021-03-01 at 14 43 39

On Mac, SwiftUI's .onHover closure is not always called on mouse exit, particularly with high cursor velocity. A grid of targets or with finer target shapes will often have multiple targets falsely active after the mouse has moved on.

It is easy to run back to AppKit's safety. Below is a SwiftUI-like modifier for reliable mouse-tracking. You can easily adapt it for other mouse tracking needs.

import SwiftUI
@almonk
almonk / SnappyWindow.swift
Last active March 13, 2025 10:07
SnappyWindow – A NSWindow that acts like the PIP Video Window from Safari
//
// SnappyWindow.swift
// A NSWindow that snaps to corners
//
// Created by Alasdair Monk on 03/02/2021.
//
import Foundation
import Cocoa
@flutter-clutter
flutter-clutter / overlay_with_hole.dart
Created June 27, 2020 12:08
Flutter overlay with a hole
import 'package:flutter/material.dart';
class OverlayWithHole extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Flutterclutter: Holes")),
body: _getExperimentOne()
);
}
@jsharp83
jsharp83 / CameraManager.swift
Last active February 21, 2025 02:21
Basic camera code using AVCaptureSession in iOS
import Foundation
import AVFoundation
@objc
protocol CameraCaptureDelegate: class {
func captureVideoOutput(sampleBuffer: CMSampleBuffer)
@objc optional func captureAudioOutput(sampleBuffer: CMSampleBuffer)
}
class CameraManager: NSObject {
@larsaugustin
larsaugustin / reRender.swift
Created January 26, 2020 13:02
Get an array of pixels from an NSImage and use this array to render the image. Handy for performing per-pixel operations on an image
import Cocoa
// Representation of a pixel
struct Pixel {
var a: UInt8
var r: UInt8
var g: UInt8
var b: UInt8
}
@knightbenax
knightbenax / quick_fix_padding_bottom_app_bar.java
Created September 10, 2018 08:22
Quick fix for padding clipping menu items in BottomAppBar
/**
* Setting the padding on the BottomAppBar instead clips out the menuview for some
* reasons. Feel it's a bug.
*
* So instead would just get the ActionMenuView which houses the menu and apply the
* padding to that instead.
*
* Reuben 1. Google 0.
* **/
for(int i = 0; i < bottomAppBar.getChildCount(); ++i) {
@shalyf
shalyf / CVPixelBuffer(vImage).swift
Last active January 6, 2024 20:46
CVPixelBuffer通过vImage转换成CGImage
import Accelerate.vImage
func getImageBuffer(from pixelBuffer: CVPixelBuffer) -> vImage_Buffer? {
var buffer = vImage_Buffer()
let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.first.rawValue)
var cgFormat = vImage_CGImageFormat(bitsPerComponent: 8,
bitsPerPixel: 32,
colorSpace: nil,
bitmapInfo: bitmapInfo,
version: 0,
@gaearon
gaearon / index.html
Last active April 1, 2025 01:48
Add React in One Minute
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Add React in One Minute</title>
</head>
<body>
<h2>Add React in One Minute</h2>
<p>This page demonstrates using React with no build tooling.</p>