Skip to content

Instantly share code, notes, and snippets.

View joeltrew's full-sized avatar

Joel Trew joeltrew

View GitHub Profile
@joeltrew
joeltrew / 0_reuse_code.js
Created January 28, 2014 17:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@joeltrew
joeltrew / Subtle text shadow.css
Created January 28, 2014 17:29 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.
text-shadow: 1px 4px 2px rgba(0, 0, 0, 0.16);
@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
@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 / 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
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});
}
}
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]] {

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:

@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(
@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):