Skip to content

Instantly share code, notes, and snippets.

View joeltrew's full-sized avatar

Joel Trew joeltrew

View GitHub Profile
@joeltrew
joeltrew / AccessibilityScrollModifier.swift
Created May 17, 2022 11:48
AccessibilityScrollModifier lets you place content in a scrollview when dynamic text hits certain sizes or by default an Accessibility Category size
struct AccessibilityScrollModifier: ViewModifier {
@Environment(\.sizeCategory) private var sizeCategory
var axis: Axis.Set
var shouldScroll: (ContentSizeCategory) -> Bool
func body(content: Content) -> some View {
if shouldScroll(sizeCategory) {
@joeltrew
joeltrew / Combine+ResultHelpers.swift
Created January 26, 2021 15:28
Combine+ResultHelpers.swift
//
// Combine+Helpers.swift
//
import Foundation
import Combine
public extension Publisher {
func asResult<S, E: Error>() -> AnyPublisher<Result<S, E>, Never> where Self.Output == S, Self.Failure == E {
@joeltrew
joeltrew / SinkPublisher+Result.swift
Created November 17, 2020 15:02
Extension that adds a specialised sink method for handling a result enum, providing a failure and success closure avoids a layer of nesting
public extension Publisher where Failure == Never {
func sinkResult<U, E>(
receiveSuccess: @escaping ((U) -> Void),
receiveFailure: @escaping ((E) -> Void)
) -> AnyCancellable where Output == Result<U, E> {
let subscriber = Subscribers.Sink<Output, Failure>(
receiveCompletion: { _ in },
receiveValue: { result in
switch result {
case .success(let value):
@joeltrew
joeltrew / UIColor+Hex.swift
Created May 4, 2020 20:03
Hex String to UIColor, both static and dynamic string support
extension UIColor {
convenience init(hex: StaticString) {
let hex = String(hex.description)
guard let rgb = UIColor.rgbValue(from: hex) else {
preconditionFailure("Invalid hex color string provided")
}
self.init(

Keybase proof

I hereby claim:

  • I am joeltrew on github.
  • I am minispecs (https://keybase.io/minispecs) on keybase.
  • I have a public key ASDjr5A5QRd8qkOKdW1xQ1FkcFwuR2d9dVyQH9hSU3Jw4Qo

To claim this, I am signing this object:

var results = [NSDictionary]()
if let path = NSBundle.mainBundle().pathForResource("output", ofType: "json") {
do {
let jsonData = try NSData(contentsOfFile: path, options: NSDataReadingOptions.DataReadingMappedIfSafe)
do {
let jsonResult: NSDictionary = try NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
if let londonEvents = jsonResult["WALES"] as? [[String: AnyObject]] {
@joeltrew
joeltrew / application.controller.js
Created December 14, 2015 00:28
pass data with transition
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
actions: {
transition: function() {
this.transitionToRoute('newroute', {id: 1, model: 123});
}
}
@joeltrew
joeltrew / app-page-component.js
Created December 13, 2015 17:02
Ember component for display apps
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['apps-page'],
sortProperty: ['name'],
sortedApps: Ember.computed.sort('apps', 'sortProperty'),
actions: {
@joeltrew
joeltrew / application.controller.js
Last active November 26, 2015 17:23
rescursive component save
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
tree: {
value1: 234,
valueOptions: {
subOption1: 123,
subOption2: 133,
subOption3: 7432,
@joeltrew
joeltrew / javascript_resources.md
Created January 28, 2014 17:29 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage