Skip to content

Instantly share code, notes, and snippets.

View cerkit's full-sized avatar

cerkit cerkit

View GitHub Profile
@cerkit
cerkit / BasicAuth1.cs
Last active August 29, 2015 14:06
BasicAuthenticationForXMLHttpRequests
// If the request was unauthorized, add the WWW-Authenticate header
// to the response.
private static void OnApplicationEndRequest(object sender, EventArgs e)
{
var response = HttpContext.Current.Response;
// see if the request sent an X-Requested-With header (Non-Browser request -
// used by jQuery and Angular implementations to prevent the browser from
// presenting the default Login dialog)
var request = HttpContext.Current.Request;
@cerkit
cerkit / app-config.js
Created September 23, 2014 16:45
AngularJS Client App for basic authentication - Config
/**
* $http interceptor.
* On 401 response - it stores the request and broadcasts 'event:auth-loginRequired'.
*/
angular.module('app').config(function ($httpProvider) {
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
var interceptor = ['$rootScope', '$q', function (scope, $q) {
function success(response) {
@cerkit
cerkit / loginDialog.html
Created September 23, 2014 16:56
Login Dialog for Basic Authentication Sample - Bootstrap and AngularJS
<div class="modal h1">
<div class="h2 container alert-info modal-body" data-backdrop="static">
Login<br /><br />
<div class="alert-danger">{{error}}</div>
<ng-form class="form-horizontal">
Username:
<input class="form-control" ng-model="username" />
Password:
<input class="form-control" type="password" ng-model="password" />
<br />
@cerkit
cerkit / loginDialog-directive.js
Created September 23, 2014 16:59
Basic Authentication with AngularJS - Login Dialog directive definition
angular.module('app').directive('loginDialog', function () {
return {
templateUrl: 'app/templates/loginDialog.html',
restrict: 'E',
replace: true,
controller: 'CredentialsController',
link: function (scope, element, attributes, controller) {
scope.$on('event:auth-loginRequired', function () {
console.log("got login event");
element.modal('show');
@cerkit
cerkit / index.html
Created September 23, 2014 17:08
AngularJS client app for basic authentication - Index.html page
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>Sample Angular Client for Basic Authentication</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
@cerkit
cerkit / CredentialsController.js
Created September 23, 2014 17:11
AngularJS Client for Basic authentication - Credentials Controller
function CredentialsController($scope, $http, $cookieStore, Base64) {
$scope.login = function (userName, password) {
var encodedUserNameAndPassword = Base64.encode(userName + ':' + password);
$http.defaults.headers.common['Authorization'] = 'Basic ' + encodedUserNameAndPassword;
$cookieStore.put('basicCredentials', encodedUserNameAndPassword);
$http.get(baseUrl + '/Values')
.success(function() {
$scope.$broadcast('event:auth-loginConfirmed');
$scope.password = '';
})
@cerkit
cerkit / SampleController.js
Created September 23, 2014 17:12
AngularJS Client for Basic Authentication - SampleController
var baseUrl = 'http://localhost:49587/api';
angular.module('app').controller('SampleController', function ($scope, $http, $cookieStore, Base64) {
$scope.refreshData = function () {
//Used to display the data
if ($cookieStore.get('basicCredentials'))
{
$http.defaults.headers.common['Authorization'] = 'Basic ' + $cookieStore.get('basicCredentials');
}
@cerkit
cerkit / HTML Entities
Last active August 29, 2015 14:21
HTML Entities for parsing HTML within an XML parser (Like .NET System.Xml.XmlDocument)
<!DOCTYPE root [
<!ENTITY Aacute "&#193;">
<!ENTITY aacute "&#225;">
<!ENTITY Abreve "&#258;">
<!ENTITY abreve "&#259;">
<!ENTITY ac "&#8766;">
<!ENTITY acd "&#8767;">
<!ENTITY Acirc "&#194;">
<!ENTITY acirc "&#226;">
<!ENTITY acute "&#180;">
<!DOCTYPE html>
<html>
<head>
<title>Settings page for Pebble</title>
<meta charset="utf-8" />
<link href="../Content/bootstrap.min.css" rel="stylesheet" />
<link href="../Content/Site.css" rel="stylesheet" />
<script src="../Scripts/bootstrap.min.js"></script>
</head>
<body>
@cerkit
cerkit / FizzBuzz.cs
Last active December 2, 2015 17:48
Proof that I can write code :)
for (int i = 1; i <= 100; i++)
{
if ((i % 3 == 0) && (i % 5 == 0))
{
Debug.WriteLine("FizzBuzz");
}
else if (i % 3 == 0)
{
Debug.WriteLine("Fizz");
}