Skip to content

Instantly share code, notes, and snippets.

View chunkyguy's full-sized avatar

Sidharth Juyal chunkyguy

View GitHub Profile
@chunkyguy
chunkyguy / RxArraySource.h
Created February 21, 2020 17:59
Rx with ObjectiveC using NSInvocation
#import "RxObservable.h"
@interface RxArraySource : RxObservable
+ (instancetype)createWithElements: (NSArray *)array;
- (void)subscribe:(NSInvocation *)invocation;
@end
@chunkyguy
chunkyguy / State+Binding.swift
Created December 27, 2022 20:40
Poor man's State and Binding without SwiftUI
@dynamicMemberLookup
class Variable<T> {
var value: T {
get { sub.value }
set { sub.value = newValue }
}
var stream: AnyPublisher<T, Never> {
return sub.eraseToAnyPublisher()
}
@chunkyguy
chunkyguy / AudioManagerController.h
Last active October 21, 2023 21:06
How to cross fade between AVAudioPlayers
/*
* Hedgewars-iOS, a Hedgewars port for iOS devices
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@chunkyguy
chunkyguy / index.html
Created August 20, 2023 09:01
Basic TicTacToe in javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Tic Tac Toe</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
@chunkyguy
chunkyguy / ContainerViewController.swift
Created December 14, 2022 19:42
UIViewController transitions
import UIKit
class ContainerViewController: UIViewController {
private var childVwCtrl: UIViewController
var contentViewController: UIViewController {
get { childVwCtrl }
set { set(contentViewController: newValue, animationDuration: nil) }
}
@chunkyguy
chunkyguy / MoveMeView.swift
Created December 12, 2022 22:17
MoveMe with layoutSubviews
import UIKit
struct Colors {
static var normal = UIColor.blue
static var selected = UIColor.red
}
extension CGPoint {
static func add(_ left: CGPoint, _ right: CGPoint) -> CGPoint {
return CGPoint(x: left.x + right.x, y: left.y + right.y)
//
// AsyncLoading.cpp
//
// Created by Sid on 11/10/14.
// Copyright (c) 2014 whackylabs. All rights reserved.
//
// Context: http://www.reddit.com/r/gamedev/comments/2ivsp6/async_loading_and_syncing_threads_with_your/
/** Output:
@chunkyguy
chunkyguy / UIColorPickerViewControllerDemo.swift
Created December 23, 2020 16:02
Use UIColorPickerViewController to pick color from the selected image
class ViewController: UIViewController {
private let imagePicker = UIImagePickerController()
private let colorPicker = UIColorPickerViewController()
private let imageView = UIImageView(image: nil)
private let colorView = UIView()
private let isSetUp = false
override func viewDidLayoutSubviews() {
if !isSetUp {
@chunkyguy
chunkyguy / clang-format
Created August 23, 2020 13:40
objective-c clang format
---
BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
@chunkyguy
chunkyguy / main.swift
Created November 26, 2019 21:20
A minimal iOS 13 app with no storyboard or xib
import UIKit
// MARK: - ViewController
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
}
}