Skip to content

Instantly share code, notes, and snippets.

View PatrickJS's full-sized avatar

PatrickJS PatrickJS

View GitHub Profile
@PatrickJS
PatrickJS / BaseController.rb
Created September 2, 2013 19:31
CORS for Rails API
class Api::V1::BaseController < ActionController::Base
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
# For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
@PatrickJS
PatrickJS / spotlight.sh
Created September 17, 2013 04:01
Hide the Spotlight Menu Icon in OSX
sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search && killall SystemUIServer
@PatrickJS
PatrickJS / hosts
Created September 17, 2013 06:06 — forked from amitaibu/hosts
# /etc/ hosts
# For local developement
127.0.0.1 app.local
127.0.0.1 api.app.local
@PatrickJS
PatrickJS / angular-track-by-index.html
Created September 25, 2013 18:06
remove $$hashkey from Angular ng-repeat
<ul>
<li ng-repeat="thing in things track by $id($index)">
.....
</li>
</ul>
or
<script>
JSON.stringify(value, function (key, val) {
@PatrickJS
PatrickJS / angular-onbeforeunload.js
Last active December 23, 2015 23:29
Confirm dialog pop up if they try and (or accidently click away from) the page
'use strict';
angular.module('angular-onbeforeunload', [])
.factory('onBeforeUnload', ['$window',
function($window) {
var leavingPageText = "You'll lose your changes if you leave";
var leavingPageText2 = "Are you sure you want to leave this page?";
function init(top, bottom) {
leavingPageText = top || leavingPageText;
leavingPageText2 = bottom || leavingPageText2;
@PatrickJS
PatrickJS / angular-$off.js
Created September 26, 2013 07:27
$off in angular
var offCallMeFn = $scope.$on("$locationChangeStart", callMe);
//this will deregister that listener
offCallMeFn();
@PatrickJS
PatrickJS / index.html
Created October 7, 2013 04:03
"Can someone make a gist of the idiomatic way in Angular to navigate between two pages (A and B) where both A and B have a model to fetch?" --Yehuda Katz https://twitter.com/wycats/status/387043646354100224
<!DOCTYPE html>
<html>
<head>
<meta name="fragment" content="!" />
<meta charset="utf-8">
<title>Angular Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="styles.css">
</head>
<body ng-app="App">
@PatrickJS
PatrickJS / angular-module-pattern.js
Last active December 25, 2015 09:29
Angular Module Pattern
!function(app) {
'use strict';
app.factory('Tracking', function($rootScope, $log) {
var _tracking = {};
_tracking.success = function(event, args) {
args = getArgs(arguments);
return function() {
$log.info(event+':success', args);
@PatrickJS
PatrickJS / angular-service-factory-provider.js
Created October 18, 2013 09:08
Angular.js: service vs provider vs factory
var myApp = angular.module('myApp', [])
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, Service!"
};
});
//factory style, more involved but more sophisticated