Skip to content

Instantly share code, notes, and snippets.

View kkurni's full-sized avatar

Kurniawan Kurniawan kkurni

  • Microsoft
  • Redmond
View GitHub Profile
@kkurni
kkurni / kk-example-angularjs-cors
Last active September 25, 2018 18:13
CORS Demo with Angular JS
var AngularJSApp = angular.module("AngularJSApp", ["ngResource", "ngSanitize"])
.config(function ($routeProvider, $httpProvider) {
$routeProvider.
when('/', { controller: NavigationCtrl, templateUrl: 'navigation.html' }).
when('/feedback', { controller: FeedbackCtrl, templateUrl: 'feedback.html' }).
otherwise({ redirectTo: '/' });
$httpProvider.defaults.withCredentials = true;
delete $httpProvider.defaults.headers.common["X-Requested-With"];
@kkurni
kkurni / kk-angular-resource-1.1.2
Last active December 11, 2015 21:28
AngularJS Resouce (1.1.2) with custom header params. Example to use. Authenticate.signIn(null,null, function (data, headers) { console.log(headers('x-token')); }, function(data, status, headers, config) { console.log('fail'); }, { 'Authorization': 'Basic dGVzdGtrMTNAdGVzdC5jb206cGFzc3dvcmQhMQ==' } );
'use strict';
/**
* @ngdoc overview
* @name ngResource
* @description
*/
/**
* @ngdoc object
@kkurni
kkurni / TokenHandler.js
Last active December 11, 2015 21:28
Angular JS Factory for Token Handler which inject authorization header request. This must use in combination with my custom resource which modified based on 1.1.2 - https://gist.github.com/4662478
KK.factory('TokenHandler', ['$cookieStore', function ($cookieStore) {
var tokenHandler = {};
tokenHandler.setToken = function (newToken) {
$cookieStore.put("X-Authorization-Token", newToken);
console.log('set token ' + newToken);
};
tokenHandler.getToken = function () {
console.log('get cookie ' + $cookieStore.get("X-Authorization-Token"));
@kkurni
kkurni / InjectHtmlService.js
Created January 30, 2013 07:37
Inject HTML Service Example with Authorization
'use strict';
SEEK.factory('InjectHtmlService', ['mobileRoot', '$http', 'TokenHandler', function (mobileRoot, $http, tokenHandler) {
var resource = {};
resource.injectHtml = function (url, success, error) {
$(document).on('submit', 'form', function () {
//add site
submitPost(mobileRoot + $(this).attr('action'));
@kkurni
kkurni / httpLoadingInterceptor
Last active December 13, 2015 18:49
AngularJS Loading interceptor example
KK.factory('httploadingInterceptor',['$q','$rootScope', function ($q, $rootScope) {
return function (promise) {
$rootScope.loading = true;
return promise.then(function (response) {
// hide the spinner
$rootScope.loading = false;
return response;
@kkurni
kkurni / facedetection.R
Created October 2, 2013 05:11
R Script for face detection
library(reshape2)
library(foreach)
memory.limit(1000000)
# parameters
data.dir <- 'C:/Projects/KK/BigData/FacebookFaceDetection/data/'
patch_size <- 10
search_size <- 2
* {
padding: 0;
margin: 0;
}
body {
font-size: 14px;
font-family: Georgia, "Bitstream Charter", serif;
color: #333333;
text-align: center;
@kkurni
kkurni / angular.placeholder.js
Last active December 25, 2015 18:09
Angular Placeholder for IE8/9 Support which compatible with validation attribute (e.g required)
MyApp.directive('placeholder', function($timeout) {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attr, ctrl) {
//check whether it support placeholder and cache it
scope.supportsPlaceholders = scope.supportsPlaceholders || function() {
return "placeholder" in document.createElement("input");
};
@kkurni
kkurni / AntiXSSValidator.cs
Last active December 25, 2015 20:39
AntiXSS validator for public API. This will allow special characters but will block XSS attacks. allow < ; | () but block any attacks from these list https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SEEK.Employment.Profile.API.Validation;
public class AntiXssValidator : IAntiXssValidator
{
public static string[] XSSTagStringsForDoubleOpening = {"iframe",
"script",
"style",
"input"
@kkurni
kkurni / xss-attack-double-open-brackets.html
Created October 18, 2013 04:28
example of double open brackets xss attacks
//Double open angle brackets
//Using an open angle bracket at the end of the vector instead of a close angle bracket causes different behavior in Netscape //Gecko rendering. Without it, Firefox will work but Netscape won't:
<iframe src=http://ha.ckers.org/scriptlet.html <