Skip to content

Instantly share code, notes, and snippets.

View cerkit's full-sized avatar

cerkit cerkit

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / vb_using_an_enum.vb
Last active August 29, 2015 14:05
Using an Enum
Dim lightState as trafficLightEnum
lightState = trafficLightEnum.Yellow
If lightState = trafficLightEnum.Red Then
Vehicle.Stop()
Else If lightState = trafficLightEnum.Green Then
Vehicle.Go()
Else If lightState = trafficLightEnum.Yellow Then
Vehicle.FloorIt()
End If
@cerkit
cerkit / enum_example.vb
Created August 15, 2014 13:33
VB.NET Enum Example
Public Enum trafficLightEnum
Red
Yellow
Green
End Enum
@cerkit
cerkit / boolean_property_eval.vb
Created August 15, 2014 13:23
Set boolean property using evaluation of boolean expression
C1GridView1.Columns.ColumnByName("Age Allocated").Visible = Mid(C1, 40, 1) = "Y"
@cerkit
cerkit / boolean_property_old_way.vb
Created August 15, 2014 13:20
Set boolean property with If, Then, Else (old way)
If Mid(C1, 40, 1) = "Y" Then
C1GridView1.Columns.ColumnByName("Age Allocated").Visible = True
Else
C1GridView1.Columns.ColumnByName("Age Allocated").Visible = False
End If
@cerkit
cerkit / append_on_condition_using_iif.vb
Created August 15, 2014 13:16
Append on condition using IIf
C1 &= IIf(chkRailCar.Checked, "Y", "N")