Skip to content

Instantly share code, notes, and snippets.

View jimmyhoran's full-sized avatar
🛠️
Working on my own thing

Jimmy Horan jimmyhoran

🛠️
Working on my own thing
View GitHub Profile
func setTitle(title:String, subtitle:String) -> UIView {
let titleLabel = UILabel(frame: CGRect(x:0, y:-5, width:0, height:0))
titleLabel.backgroundColor = UIColor.clear
titleLabel.textColor = UIColor.gray
titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
titleLabel.text = title
titleLabel.sizeToFit()
@jimmyhoran
jimmyhoran / subl
Created November 14, 2017 09:49 — forked from yoeun/subl
subl command on linux
#!/bin/sh
# save to /usr/local/bin/subl
nohup /path/to/Sublime\ Text\ 2/sublime_text $1 >/dev/null 2>&1 &
@jimmyhoran
jimmyhoran / authInterceptor.js
Created December 31, 2017 06:26 — forked from bettysteger/authInterceptor.js
Set specific http headers on every http request from cookies (angular)
'use strict';
/**
* Authentication with token and email for every server request. (Sets HTTP headers)
*
* This interceptor shows the error from the server (i18n key).
* Also sets global error variable if the request fails and redirects the user to '/' when he is not authorized.
* @see http://engineering.talis.com/articles/client-side-error-logging/
*/
app.factory('authInterceptor', function ($rootScope, $q, $cookies, $location, $timeout) {
@jimmyhoran
jimmyhoran / auth.markdown
Created December 31, 2017 06:26 — forked from mlynch/auth.markdown
AngularJS Authentication and CORS

Single Page Apps are ruling the world and AngularJS is leading the charge. But many of the lessons we learned in the Web 2.0 era no longer apply, and few are as drastically different as authentication.

CORS

CORS is an oft-misunderstood feature of new browsers that is configured by a remote server. CORS stands for Cross-Origin-Resource-Sharing, and was designed to make it possible to access services outside of the current origin (or domain) of the current page.

Like many browser features, CORS works because we all agree that it works. So all major browsers like Chrome, Firefox, and IE support and enforce it. By using these browsers, you benefit from the security of CORS.

That means certain browsers do not enforce it, so it is not relevant there. One large example is a native Web View for things like Cordova and Phonegap. However, these tools often have configuration options for whitelisting domains so you can add some security that way.

@jimmyhoran
jimmyhoran / UINavigationBar+Height.swift
Created February 18, 2018 07:36 — forked from siberianisaev/UINavigationBar+Height.swift
Change height of UINavigationBar
import Foundation
private var AssociatedObjectHandle: UInt8 = 0
extension UINavigationBar {
var height: CGFloat {
get {
if let h = objc_getAssociatedObject(self, &AssociatedObjectHandle) as? CGFloat {
import UIKit
class AlignedImageButton: UIButton {
// Convenience initializer must delegate across not up
// So we override init and call super.init to facilitate that
override init(frame: CGRect) {
super.init(frame: frame)
}
#!/bin/sh
# first, go to the root of the git repo
cd `git rev-parse --show-toplevel`
# write out a tree with only the stuff in staging
INDEXTREE=`git write-tree`
# now write out a tree with everything
git add -A
import Foundation
internal class ClosureSleeve {
let closure: () -> Void
init(for object: AnyObject, _ closure: @escaping () -> Void) {
self.closure = closure
objc_setAssociatedObject(
object,
import Foundation
extension Date {
static func isoString(from date: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone(abbreviation: "GMT")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
return dateFormatter.string(from: date).appending("Z")
body {
font-size: 100%;
}
body,
caption,
th,
td,
input,
textarea,