Skip to content

Instantly share code, notes, and snippets.

View chunkyguy's full-sized avatar
🤗
LGTM

Sidharth Juyal chunkyguy

🤗
LGTM
View GitHub Profile
@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 / 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 / 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)
@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 / 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 / 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
}
}
@chunkyguy
chunkyguy / ServiceLocator.swift
Last active November 19, 2019 16:50
Service Locator Pattern with GameplayKit
private class ServiceWrapper<T>: GKComponent {
let service: T
init(service: T) {
self.service = service
super.init()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
import Foundation
import SceneKit
import GLKit
class World {
let scene = SCNScene()
func setUp() {
let worldNode = scene.rootNode
addLights(to: worldNode)