Skip to content

Instantly share code, notes, and snippets.

View zontag's full-sized avatar
🏠
Working from home

Tiago Zontag zontag

🏠
Working from home
  • Curitiba
View GitHub Profile
@emredesu
emredesu / ScrollRectAutoScroll.cs
Last active March 19, 2026 00:47 — forked from mandarinx/ScrollRectAutoScroll.cs
Re-written for the new input system. Also uses unscaledDeltaTime for use in pause menus, and doesn't do anything if the platform is a mobile platform with no gamepads connected.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityEngine.InputSystem;
[RequireComponent(typeof(ScrollRect))]
public class ScrollRectAutoScroll : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
public float scrollSpeed = 10f;
private bool mouseOver = false;
@spireggs
spireggs / ScrollRectAutoScroll.cs
Last active March 19, 2026 19:24 — forked from mandarinx/ScrollRectAutoScroll.cs
Unity3d ScrollRect Auto-Scroll, Dropdown Use: Places this component in the Template of Dropdown (with the ScrollRect component)
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
//comment the next line out if you aren't using Rewired
using Rewired;
[RequireComponent(typeof(ScrollRect))]
public class ScrollRectAutoScroll : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
@alexpaul
alexpaul / CoreData-Saving-Array.md
Last active June 16, 2023 12:23
Core Data saving an array.

Core Data (Saving an array)

While saving an array to Core Data is supported, one of the first questions you will want to ask, if this array should be a relationship to another entity instead? It the answer is no, then continue reading on....

1. Core Data Model (Graphical Interface)

Set the attribute, in this case, the type you want to save as an array to Core Data supported type Binary Data

Example
attribute is hobbies

@ji3g4kami
ji3g4kami / XCTestCase+JSON.swift
Created April 5, 2020 21:50
load JSON file with ease
import XCTest
extension XCTestCase {
enum TestError: Error {
case fileNotFound
}
func getData(fromJSON fileName: String) throws -> Data {
let bundle = Bundle(for: type(of: self))
guard let url = bundle.url(forResource: fileName, withExtension: "json") else {
@PaulWoodIII
PaulWoodIII / SelectedItems.swift
Created August 19, 2019 00:02
quick example of how to use selection in a SwiftUI list, an ObservableObject provides the content as well
//: [Previous](@previous)
import SwiftUI
import Combine
import PlaygroundSupport
class Context: ObservableObject {
@Published var selectedItems: Set<String>
@Published var items: Array<String>
@gokselkoksal
gokselkoksal / Channel.swift
Last active September 16, 2022 03:53
Channel implementation
public class Channel<Value> {
private class Subscription {
weak var object: AnyObject?
private let notifyBlock: (Value) -> Void
private let queue: DispatchQueue
var isValid: Bool {
return object != nil
@messeb
messeb / URLResponse+HTTP.swift
Created December 5, 2017 21:00
URLResponse as HTTPURLResponse and check if call has status code 2xx
extension URLResponse {
/// Returns casted `HTTPURLResponse`
var http: HTTPURLResponse? {
return self as? HTTPURLResponse
}
}
extension HTTPURLResponse {
/// Returns `true` if `statusCode` is in range 200...299.
/// Otherwise `false`.
@michaelevensen
michaelevensen / EmbedViewController.swift
Last active September 5, 2022 07:27
Embed a UIViewController in Container View programatically
// Instantiate
self.mapViewController = self.storyboard?.instantiateViewController(withIdentifier: "MapViewController") as? MapViewController
if let mapViewController = self.mapViewController {
// Add to Container View
self.mapViewContainerView.addSubview(mapViewController.view)
self.addChildViewController(mapViewController)
mapViewController.didMove(toParentViewController: self)
}
@tkersey
tkersey / UIView.swift
Created November 16, 2015 01:12
Calculate preferred height of UIView
extension UIView {
func calculatePreferredHeight(preferredWidth: CGFloat? = nil) -> CGFloat {
let width = preferredWidth ?? frame.width
let widthConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:[view(==\(width)@999)]", options: .allZeros, metrics: nil, views: ["view": self])
addConstraints(contraint)
let height = systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height
removeConstraints(constraint)
return height
}
}
@Mariovc
Mariovc / ImagePicker.java
Last active November 29, 2024 16:28
Utility for picking an image from Gallery/Camera with Android Intents
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;