Skip to content

Instantly share code, notes, and snippets.

View thekarel's full-sized avatar

Charles Szilagyi thekarel

View GitHub Profile
<span class="gallery-date">{{(gallery.date | date:'mediumDate') || "Various"}}</span>
// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
@thekarel
thekarel / angular-http-auth.js
Created October 9, 2013 15:59
Adding auth headers (username, password) to AngularJS $http methods -- From http://blog.tomaka17.com/2012/12/random-tricks-when-using-angularjs/
// Base64 is not native, get a library or base64 outside of your script.
$http.defaults.headers.common['Authorization'] = 'Basic ' + Base64.encode($scope.login.login + ':' + $scope.login.password);
sc create newservice binpath= <pat_to_the_executable>
function foo(a, b)
{
a = typeof a !== 'undefined' ? a : 42;
b = typeof b !== 'undefined' ? b : 'default_b';
}
@thekarel
thekarel / app.js
Created October 18, 2013 13:16
AngularJS: Multiple controllers and 1 ng-view on the same page, plus embedded directives
/**
* Create the app
*/
var appOne = angular.module('appOne', ['ngRoute']);
/**
* Configure routing - so controllerTwo runs
*/
appOne.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:
set NEWVAR=SOMETHING
you are just setting it in the current process space. According to this page you can use the setx command:
setx NEWVAR SOMETHING
setx is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit
@thekarel
thekarel / app.js
Created October 19, 2013 23:37
Create scope variable from the original HTML of a directive in AngularJS
var myApp = angular.module('myApp', []);
myApp.directive('collapsible', function () {
/**
* We need this since by the time we get to link,
* the original HTML is already gone, replaced by template.
*/
var originalHTML = {};
return {
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.1/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="MyCtrl">
{{serviceOutput}}
<br/><br/>
scope.$on('$locationChangeStart', function (event, newLoc, oldLoc){
console.log('changing to: ' + newLoc);
});
scope.$on('$locationChangeSuccess', function (event, newLoc, oldLoc){
console.log('changed to: ' + newLoc);
});