Skip to content

Instantly share code, notes, and snippets.

View aalekz's full-sized avatar

Alexander Simson aalekz

View GitHub Profile
@pd95
pd95 / Export-HEVC.swift
Created June 2, 2020 22:25
Swift Playground code showing how to convert a video from H264 (in my case) to HEVC/H265 using AVFoundation
import AVFoundation
// Get test video from bundle
let url = Bundle.main.url(forResource: "test", withExtension: "mp4")!
let anAsset = AVURLAsset(url: url)
// get properties of video track
let track = anAsset.tracks(withMediaType: AVMediaType.video).first!
let size = track.naturalSize.applying(track.preferredTransform)
let frameSize = CGSize(width: abs(size.width), height: abs(size.height))
import { useState, useEffect } from "react";
import { AsyncStorage } from "react-native";
function useAsyncStorage(key, initialValue) {
const [storedValue, setStoredValue] = useState(initialValue);
useEffect(() => {
AsyncStorage.getItem(key)
.then(value => {
if (value === null) return initialValue;
// Advanced SwiftUI Transitions
// https://swiftui-lab.com
// https://swiftui-lab.com/advanced-transitions
import SwiftUI
struct CrossEffectDemo: View {
let animationDuration: Double = 2
let images = ["photo1", "photo2", "photo3", "photo4"]
@State private var idx = 0
@chriseidhof
chriseidhof / RemoteValue.swift
Created June 28, 2019 10:27
Custom Lazy Loading
import Foundation
import SwiftUI
import Combine
import TinyNetworking
final class RemoteValue<A>: BindableObject {
let didChange = MyPublisher()
let endpoint: Endpoint<A>
var value: A? {
didSet {
@stinger
stinger / CombineFetcher.swift
Last active January 28, 2023 18:07
Combine - fetching data using URLSession publishers
import Foundation
import Combine
enum APIError: Error, LocalizedError {
case unknown, apiError(reason: String)
var errorDescription: String? {
switch self {
case .unknown:
return "Unknown error"
@groue
groue / JSONSynchronization.swift
Created September 13, 2017 14:33
GRDB JSONSynchronization
// To run this playground, select and build the GRDBOSX scheme.
//
// This sample code shows how to use GRDB to synchronize a database table
// with a JSON payload. We use as few SQL queries as possible:
//
// - Only one SELECT query.
// - One query per insert, delete, and update.
// - Useless UPDATE statements are avoided.
import Foundation
//
// MyMetalWaterfall.swift
// version 0.1.105 (updated for Swift 5)
//
// Demonstrates using a MetalKit compute shader to render a live waterfall RGB bitmap
// into a UIView
//
// This is a single file iOS app
//
// It includes AppDelegate for a minimal demonstration app
@GraxRabble
GraxRabble / sodium_demo.c
Last active October 28, 2018 03:33
This c file demostrates how to use each libsodium functions and lets you play with them to see their outputs.
/*
* GraxRabble
* 04 MAY 2014
* Note this was created for the 4.5 version of libSodium.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sodium.h" /* library header */
@hlung
hlung / How to connect PS3 controller to a Mac or PC.md
Last active July 22, 2024 21:41
How to connect PS3 controller to a Mac or PC

How to connect PS3 controller to a Mac or PC

This is how you connect PS3 controller to Mac OSX, PC, etc. when previously connected to a PS3. You will need a Mini USB cable. Overcome your laziness, get up of your chair, and go get one!

A big misconception is that keep holding PS button will reset the controller's pairing. It DOES NOT! From my testings, the controller keeps paring with the last machine it was CONNECTED VIA A USB CABLE.

Here are the steps:

@steipete
steipete / PSPDFTextView.m
Created November 28, 2013 11:15
Works around the issue where UITextView doesn't scroll to the new line until there's a character in there. Super horrible workaround.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
// Horrible HACK for bug in UITextView where it won't scroll to the new line after pressing enter in the text view.
// I feel dirty for having to write this. Buggy at least within iOS 7.0 - 7.1b1.
if (PSPDFIsUIKitFlatMode() && [text isEqualToString:@"\n"] && range.location == textView.text.length) {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^{
CGPoint contentOffset = textView.contentOffset;
CGFloat fontSize = textView.font.pointSize;
if (textView.contentSize.height - fontSize > textView.bounds.size.height) {
contentOffset.y += fontSize + 2.f; // add spacing