Skip to content

Instantly share code, notes, and snippets.

View mlynch's full-sized avatar
🍂
Taking a break

Max Lynch mlynch

🍂
Taking a break
View GitHub Profile
@mlynch
mlynch / directive.markdown
Last active July 31, 2017 14:37
Making of an AngularJS Directive

A while back I made a quick AngularJS directive for Bootstrap 3 Tooltips. I wanted to be able to specify tooltips on any element like this:

<button title="Settings" data-placement="bottom" data-delay="500"
data-toggle="tooltip"><i class="icon ion-gear"></i></button>

But I wanted to be able to do it without having to call $([data-toggle="tooltip"]').tooltip() every time I loaded a new page with tooltips, which is what you'd have to do if you were using vanilla jQuery and Bootstrap without something like Angular.

I built a really simple directive that worked perfectly, and I realized this was a perfect example of creating a simple custom directive that makes your life so much easier.

@mlynch
mlynch / auth.markdown
Last active September 4, 2020 18:11
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.

@mlynch
mlynch / autofocus.js
Last active August 24, 2022 15:03
AngularJS Autofocus directive
/**
* the HTML5 autofocus property can be finicky when it comes to dynamically loaded
* templates and such with AngularJS. Use this simple directive to
* tame this beast once and for all.
*
* Usage:
* <input type="text" autofocus>
*
* License: MIT
*/
angular.module('maxlynch')
/**
* A simple ace-editor widget for adding a rich code editor
* in place of a textarea with full ngModel support.
*
* Usage:
*
* <ace-editor language="javascript" theme="monokai"></ace-editor>
*
@mlynch
mlynch / drawer.js
Last active August 29, 2015 14:08
Menu and Drawer toggle
angular.module('myApp', ['ionic'])
.directive('menuAndDrawerClose', ['$ionicViewService', function($ionicViewService) {
return {
restrict: 'AC',
require: '?^ionSideMenus,?^drawer',
link: function($scope, $element, $attr, ctrls) {
$element.bind('click', function(){
ctrls[0] && ctrls[0].close();
ctrls[1] && ctrls[1].close();
@mlynch
mlynch / gist:5a53aa2f6a997c386e02
Created November 18, 2014 05:55
v8flags issue
$ npm install -g gulp
/
> [email protected] install C:\Users\Max_2\AppData\Roaming\npm\node_modules\gulp\nod
e_modules\v8flags
> node fetch.js
-
C:\Users\Max_2\AppData\Roaming\npm\node_modules\gulp\node_modules\v8flags\fetch.
@mlynch
mlynch / app.plist
Last active January 27, 2019 21:38 — forked from mhartington/README.md
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
@mlynch
mlynch / ionRadio.js
Last active October 13, 2022 15:07
ionRadio fix for iOS 9 bugs
/**
* ionRadioFix - fixes a bug in iOS 9 UIWebView that breaks the tilde selector in CSS. To
* use this fix, include it after your Ionic bundle JS.
*
* Note: due to Angular directive override limitations, you'll need to change any reference
* to <ion-radio> to <ion-radio-fix> to apply this patched radio button.
*
* Also, make sure to add the new CSS from the second part of this gist.
*/
angular.module('ionic').directive('ionRadioFix', function() {
@mlynch
mlynch / info.plist
Last active August 6, 2023 07:31
Disable App Transport Security in iOS 9
<!--
This disables app transport security and allows non-HTTPS requests.
Note: it is not recommended to use non-HTTPS requests for sensitive data. A better
approach is to fix the non-secure resources. However, this patch will work in a pinch.
To apply the fix in your Ionic/Cordova app, edit the file located here:
platforms/ios/MyApp/MyApp-Info.plist
And add this XML right before the end of the file inside of the last </dict> entry:
@mlynch
mlynch / gist:20eedbf80f2ddbd8df45
Last active October 19, 2015 15:09
Ionic Workshop Links