Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Always coding

Suyeol Jeon devxoul

👨‍💻
Always coding
View GitHub Profile
@devxoul
devxoul / ApolloMockedProviderDynamicVariables.tsx
Last active Feb 23, 2021
Use expect matcher in Apollo MockedProvider variables
View ApolloMockedProviderDynamicVariables.tsx
jest.mock('@wry/equality', () => ({
equal: (lhs: any, rhs: any) => {
const equals = require('expect/build/jasmineUtils').equals(lhs, rhs)
return equals || jest.requireActual('@wry/equality').equal(lhs, rhs)
}
}))
const mocks = [
{
@devxoul
devxoul / Spy.ts
Created Feb 12, 2021
Jest Spy type
View Spy.ts
type Spy<T extends {}, M extends jest.FunctionPropertyNames<Required<T>>> = Required<T>[M] extends (...args: any[]) => any
? jest.SpyInstance<ReturnType<Required<T>[M]>, jest.ArgsType<Required<T>[M]>>
: never;
@devxoul
devxoul / nonnull_connection.py
Created Dec 18, 2020
Graphene NonNullConnection
View nonnull_connection.py
class NonNullConnection(graphene.relay.Connection):
class Meta:
abstract = True
@classmethod
def __init_subclass_with_meta__(cls, node=None, **options):
if node is not None and not isinstance(node, graphene.NonNull):
node = graphene.NonNull(node)
super(NonNullConnection, cls).__init_subclass_with_meta__(
View UIBezierPath+CatmullRomInterpolate.swift
extension UIBezierPath {
/// https://github.com/jnfisher/ios-curve-interpolation/blob/master/Curve%20Interpolation/UIBezierPath%2BInterpolation.m
func catmullRomInterpolate(with points: [CGPoint], alpha: CGFloat = 0.3) {
guard points.count >= 4 else { return self.hermiteInterpolate(with: points, alpha: alpha) }
let startIndex = 1
let endIndex = points.count - 2
for currentIndex in 1..<endIndex {
let prevIndex = currentIndex - 1
View AutoAssembly.swift
import Foundation
public enum Swinject {
public final class Container {
}
}
protocol Assembly {
func assemble(to container: Swinject.Container)
}
View firebase_carthage_frameworks.py
import io
import requests
import subprocess
import zipfile
FIREBASE_VERSION = '6.29.0'
def main():
json_urls = [
"https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json",
@devxoul
devxoul / git-reorder
Last active Feb 26, 2021
$ git reorder HEAD~3
View git-reorder
# https://gist.github.com/devxoul/00b5b4fac4243075656dc79912e256d6
git rebase --exec 'git commit --amend -C HEAD --date="$(date -R)" && sleep 1.05' $1
View NSStatusBarStub.swift
final class NSStatusBarStub: NSStatusBar {
override func statusItem(withLength length: CGFloat) -> NSStatusItem {
let alloc = NSStatusItem.perform(NSSelectorFromString("alloc"))!.takeRetainedValue() as! NSStatusItem
let selector = NSSelectorFromString("_initInStatusBar:withLength:withPriority:hidden:")
let imp = alloc.method(for: selector)
typealias ObjcInitBlock = @convention(c) (NSStatusItem, Selector, NSStatusBar, CGFloat, Int, Bool) -> NSStatusItem
let initializer = unsafeBitCast(imp, to: ObjcInitBlock.self)
let statusItem = initializer(alloc, selector, self, length, 1, true) // it won't work the last parameter("hidden") is set to `false`
@devxoul
devxoul / TypedContainer.swift
Last active May 6, 2020
Conceptual strong-typed DI container
View TypedContainer.swift
protocol ContainerProtocol {
associatedtype Service
associatedtype Nested: ContainerProtocol
var service: Service { get }
var nestedContainer: () -> Nested { get }
}
struct TypedContainer<Service, Nested: ContainerProtocol>: ContainerProtocol {
let service: Service
@devxoul
devxoul / distinctUntilChanged.swift
Last active Apr 16, 2020
RxSwift Observable<(T, T)>.distinctUntilChanged() returns wrong result
View distinctUntilChanged.swift
let source = Observable<(Int, Int)>.from([
(0, 1),
(2, 3),
(4, 5),
])
// Doesn't work as expected
// A -> (0, 1)
source
.distinctUntilChanged(==)