Skip to content

Instantly share code, notes, and snippets.

@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 July 9, 2024 19:51
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 May 2, 2024 03:05
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 June 19, 2024 07:33
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 May 23, 2024 11:08
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>
@Gevrai
Gevrai / BatteryMonitoring.swift
Created April 13, 2018 19:23
Very simple Singleton that sends a Notification whenever the state or level of the battery changed.
public class BatteryMonitoring {
public static let BatteryDidChangeNotification = Notification.Name(rawValue: "BatteryStateNotifier.BatteryDidChangeNotification")
public static let shared = BatteryMonitoring()
private init() {}
public private(set) var state : WKInterfaceDeviceBatteryState = .unknown
// State will be an int between 0 and 100 if state is not .unknown, else -1
public private(set) var level : Int = -1